In this problem we consider binary trees, represented by pointer data structures. A binary tree is...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this problem we consider binary trees, represented by pointer data structures. A binary tree is either an empty tree or a node (called the root) made of a single integer value and two further binary trees, called the left subtree and the right subtree. For example, the figure below shows a binary tree that has six nodes. Its root contains the value 5, and the roots of its left and right subtrees have the values 3 and 10. The right subtree of the node with the value 10, as well as the left and right subtrees of the nodes with the values 1, 20 and 21, are empty trees. 20 A binary tree can be given using a pointer data structure. Assume that the following declaration are given: class Tree { 10 public int x; public Tree 1; public Tree r; }; An empty tree is represented by an empty pointer (denoted by null). A non-empty tree is represented by a pointer to an object representing its root. The attribute x holds the integer contained in the root, while attributes 1 and r hold the left and right subtrees of the binary tree. A path in a binary tree is a non-empty sequence of nodes that one can go through by following the pointers. The length of a path is the number of pointers it follows. More formally, a path of length K is a sequence of nodes P[0], P[1], ..., P[K], such that node P[I + 1] is the root of the left or right subtree of P[I], for 0 ≤ I < K. For example, the sequence of nodes with values 5, 3, 21 a path of length 2 in the tree from the above figure. The sequence of nodes with values 10, 1 is a path of length 1. The sequence of nodes with values 20, 3, 21 is not a valid path. The height of a binary tree is defined as the length of the longest possible path in the tree. In particular, a tree of only one node has height 0 and an empty tree has height -1. For example, the tree shown in the above figure is of height 2. A binary tree T is given. A node of tree T containing value V is described as visible if the path from the root of the tree to that node does not have a node with any value exceeding V. In particular, the root is always visible and nodes with values lower than that of the root are never visible. In this problem we consider binary trees, represented by pointer data structures. A binary tree is either an empty tree or a node (called the root) made of a single integer value and two further binary trees, called the left subtree and the right subtree. For example, the figure below shows a binary tree that has six nodes. Its root contains the value 5, and the roots of its left and right subtrees have the values 3 and 10. The right subtree of the node with the value 10, as well as the left and right subtrees of the nodes with the values 1, 20 and 21, are empty trees. 20 A binary tree can be given using a pointer data structure. Assume that the following declaration are given: class Tree { 10 public int x; public Tree 1; public Tree r; }; An empty tree is represented by an empty pointer (denoted by null). A non-empty tree is represented by a pointer to an object representing its root. The attribute x holds the integer contained in the root, while attributes 1 and r hold the left and right subtrees of the binary tree. A path in a binary tree is a non-empty sequence of nodes that one can go through by following the pointers. The length of a path is the number of pointers it follows. More formally, a path of length K is a sequence of nodes P[0], P[1], ..., P[K], such that node P[I + 1] is the root of the left or right subtree of P[I], for 0 ≤ I < K. For example, the sequence of nodes with values 5, 3, 21 a path of length 2 in the tree from the above figure. The sequence of nodes with values 10, 1 is a path of length 1. The sequence of nodes with values 20, 3, 21 is not a valid path. The height of a binary tree is defined as the length of the longest possible path in the tree. In particular, a tree of only one node has height 0 and an empty tree has height -1. For example, the tree shown in the above figure is of height 2. A binary tree T is given. A node of tree T containing value V is described as visible if the path from the root of the tree to that node does not have a node with any value exceeding V. In particular, the root is always visible and nodes with values lower than that of the root are never visible.
Expert Answer:
Answer rating: 100% (QA)
To solve the problem we can use a recursive approach to traverse the binary tree and determine which ... View the full answer
Related Book For
Posted Date:
Students also viewed these mathematics questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
Hehtoc-yrityksen tuloslaskelma on esitetty alla. Yrityksen valmistuskapasiteetti on 120.000 kpl vuodessa. Myyntituotot 80.000 kpl 20 Myytyjen tuotteiden kustannukset Vlittmt aineet Vlitn ty...
-
The primary operating goal of a publicly-owned firm interested in serving its stockholders should be to a. Maximize its expected total corporate income. b. Maximize the stock price per share over the...
-
Divide. Check your answer. 12x - 14x + 7x -7 3x - 2
-
Fresh Food Direct, LLC, entered into a lease agreement with Jet Star Realty, LLC. Fresh Food terminated the lease before its terms end, and the parties disputed the amount of rent that Fresh Food...
-
On May 1, 2016, Benzs Sandwich Shop loaned $10,000 to Mark Henry for one year at 6 percent interest. Required Answer the following questions: a. What is Benzs interest income for 2016? b. What is...
-
Consider the Bertrand duopoly discussed in class. Assume each firm has constant marginal cost c = 10 and zero fixed cost. Each firm chooses a price Pi 0. The market demand is given by Q = 130 P,...
-
Prepare an offer and post it in the discussion. Then I want you to review at least two other students offers in the class and determine if their posting is actually an offer or a negotiation to make...
-
Calculate the 3 year monthly lease payment on an office computer system costing $ 2 8 , 5 0 0 , assuming a residual value of $ 3 , 5 0 0 , an interest rate of 6 . 4 % , and a $ 5 , 0 0 0 down payment.
-
Bonnie devised the residue of her estate in trust for the benefit of her husband, Otis. The relevant provisions of the trust read as follows: "During my husband's lifetime, the Trustee shall...
-
What does it mean to be a fair - minded thinker, according to your understanding? Explain the characteristics of fair - mindedness, particularly in relation to refraining from judging sources with...
-
John Doe Company uses process costing. The goods are processed first in department A and then passed onto department B , the final department. What is the journal entry for recording the cost of...
-
Suppose that f(x) dx = = 5, compute 3 f(2x) dx
-
continuous alphabet discrete time random variable is called discrete random process .a O discrete random sequence .b O continuous random sequence .c O continuous random process .d O
-
If M = 7, s = 2, and X = 9.5, what is z?
-
Using the information in the previous problem, compute the prices of In previous problem Suppose that S = $100, K = $100, r = 0.08, = 0.30, = 0, and T = 1. Construct a standard two-period binomial...
-
In this problem we consider whether parity is violated by any of the option prices in Table 9.1. Suppose that you buy at the ask and sell at the bid, and that your continuously compounded lending...
-
Problem 12.11 showed how to compute approximate Greek measures for an option. Use this technique to compute delta for the gap option in Figure 14.3, for stock prices ranging from $90 to $110 and for...
-
Taylor Pty Ltd is based in Brisbane and sells glamping yurt tents imported from China at a cost of $150 each plus import duties and other costs of $60. These purchase and import costs are paid cash...
-
ArbreCorp Ltee is a sawmill operation in Quebec that is owned by a major forest products company but operates independently of the parent company. It was built 30 years ago, and completely updated...
-
Over the past 15 years, Volkswagen Group (VW) acquired several fiefdoms- Audi, Lamborghini, Bentley, Bugatti, Skoda, SEAT - that jealously guarded their brand and continuously rebelled against...
Study smarter with the SolutionInn App