Binary Search Tree (14 points) Recall that in a binary search tree, each node is defined...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Binary Search Tree (14 points) Recall that in a binary search tree, each node is defined as follows. struct node { int key; node *left; node *right; node *parent; \ Other data *\ } Recall that in a binary search tree, at every node, the key at a node is larger than or equal to the keys in its left subtree, and is smaller or equal to the keys its right subtree. In each case below, write a procedure in a C-like language that achieves the required task. (a) (3 pt) Compute the sum of all the keys in the binary tree. int Sum (node* root) { (b) (3 pt) Given a <b, compute the sum of all keys in the tree falling within the range [a..b]. If there is no key in the given range, return 0. int SumRange (node* root, int a, int b) { (c) (4 pt) Given a <b, return the pointer to a node having the maximum key in the range [a..b]. If there is more than one such node, return the node that appears the latest in the inorder traversal. If there is no such node, return the NULL pointer. node MaxRange (node* root, int a, int b) { (d) (4 pt) Given integers a and b, perform a linear transformation au bon all keys in the tree, i.e., if a node has key value v originally, the new key value should be au ib. The new tree must also be a binary search tree. The method should return the pointer to the root of the new tree. node Transform (node* root, int a, int b) { Binary Search Tree (14 points) Recall that in a binary search tree, each node is defined as follows. struct node { int key; node *left; node *right; node *parent; \ Other data *\ } Recall that in a binary search tree, at every node, the key at a node is larger than or equal to the keys in its left subtree, and is smaller or equal to the keys its right subtree. In each case below, write a procedure in a C-like language that achieves the required task. (a) (3 pt) Compute the sum of all the keys in the binary tree. int Sum (node* root) { (b) (3 pt) Given a <b, compute the sum of all keys in the tree falling within the range [a..b]. If there is no key in the given range, return 0. int SumRange (node* root, int a, int b) { (c) (4 pt) Given a <b, return the pointer to a node having the maximum key in the range [a..b]. If there is more than one such node, return the node that appears the latest in the inorder traversal. If there is no such node, return the NULL pointer. node MaxRange (node* root, int a, int b) { (d) (4 pt) Given integers a and b, perform a linear transformation au bon all keys in the tree, i.e., if a node has key value v originally, the new key value should be au ib. The new tree must also be a binary search tree. The method should return the pointer to the root of the new tree. node Transform (node* root, int a, int b) {
Expert Answer:
Answer rating: 100% (QA)
Let us see the procedures in a Clike language a Compute the sum of all keys in the binary tree int S... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
As an insurance agent, how can I handle increases from natural disasters? Will it have a regional impact or a general growth?
-
Complete the following with C++, (also if it compiles in Visual Studio that would be nice)my program so far before this part will be below the task. Add a to_string method to the class Binary Search...
-
What is the purpose of producing accounting information? Identify the main users of accounting information for a university. Do these users differ very much from the users of accounting information...
-
Hombran Doughnuts has current assets of $270 million; property, plant, and equipment of $400 million; and other assets totaling $160 million. Current liabilities are $160 million and long-term...
-
A chain of length l is placed on a smooth spherical surface of radius R with one of its ends fixed at the top of the sphere. What will be the acceleration w of each element of the chain when its...
-
How does the dynamic interplay between protgs and mentors within a mentorship framework contribute to the cultivation of cognitive dexterity and strategic foresight in navigating complex professional...
-
Do the assumptions for Bernoulli trials appear to hold? Explain. If the assumptions hold, identify success and the probability of interest. (a) A TV ratings company will use their electronic...
-
Imperial Carpet has the following unadjusted trial balance as of March 31, 2012. The debit and credit totals are not equal as a result of the following errors:a. The balance of cash was understated...
-
The 7 Domains Model is a simplified framework that company owners may use to determine whether their concept has commercial potential. The approach breaks down your concept into seven categories...
-
A slipper-pad bearing (Fig. P1023) is often encountered in lubrication problems. Oil flows between two blocks; the upper one is stationary, and the lower one is moving in this case. The drawing is...
-
Suppose an employer gives employees an insurance discount based on number of hours of physical fitness activities. Who benefits from the program? Who is harmed? Is this ethical? Suppose an employer...
-
In responding to a Request for Proposal (RFP), XYZ Contractor is preparing a lump sum price proposal for digging an underground hole with specifications below. 10m x 10m x 5m - Concept Design No...
-
1. The yield point data necessary to experimentally construct a yield surface for the particle reinforced aluminum 6092/17.5p-W is provided below. These data were acquired using axial- torsional...
-
For the given plan below apply 2 kN/m2 live load and 10 cm concrete slab ($235) By considering the slenderness effects, design (select the dimension from table) the MAIN beam given below. Draw the...
-
I choose IKEA COMPANY Production possibility curve (PPC) Scenario1: a. If your company can make two goods, use a numerical table and list different combinations of two goods your company can make b....
-
Use the bordered determinants to check y = xix (x, x > 0; 0 < a < 1 and 0 < b < 1). for quasiconcavity and quasiconvexity.
-
Domestic supply of sugar is Q=-60+2P, and domestic demand is Q=120-P. Where Q is in millions of pounds. The world price of sugar is 28 cents per pound. The government imposes a quota to limit sugar...
-
Linda Lopez opened a beauty studio, Lindas Salon, on January 2, 2011. The salon also sells beauty supplies. In January 2012, Lopez realized she had never filed any tax reports for her business and...
-
A compare-exchange operation on two array elements A[i] and A[j], where i < j, has the form COMPARE-EXCHANGE (A, i, j) 1 If A[i] > A[j] 2 exchange A[i] with A[j] After the compare-exchange operation,...
-
Show that the probability of no successes in n Bernoulli trials, each with probability p = 1/n, is approximately 1/e. Show that the probability of exactly one success is also approximately 1/e.
-
An integer linear-programming problem is a linear-programming problem with the additional constraint that the variables x must take on integral values. Exercise 34.5-3 shows that just determining...
-
Aerotron Radio Inc. has \(\$ 250,000\) available, and its engineering staff has proposed the following indivisible investments. With each, Aerotron can exit at the end of its planning horizon of 5...
-
Consider a capital budgeting formulation where the binary variables \(x_{1}\) and \(x_{2}\) are used to represent the acceptance \(\left(x_{i}=1 ight)\) or rejection \(\left(x_{i}=0 ight)\) of each...
-
True or False: If independent, indivisible investments 3 and 4 are mutually exclusive, then X 3 + X 4 < 1 is added as a constraint to the BLP formulation.
Study smarter with the SolutionInn App