(a) (4 marks) Write a function sumAtLevel that accept an integer m and the root node...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
(a) (4 marks) Write a function sumAtLevel that accept an integer m and the root node of a BST and calculates the sum of all the nodes (values) in a given level. Function Signature: int sumOfLevel(node *root, int m); For example: In the given BST, sumOfLevel(8, 2); will return 21. Because, the sum of the values of the nodes at level 2 is = 1 + 6 + 14 = 21. (b) (4 marks) Write a function minDepth that takes the root node of a BST as parameter. It finds the minimum depth of that tree. Function Signature: int minDepth(node *root); For example: In the given BST, minDepth(8) will return 2. 1 }; 4 6 8 The binary search tree node is defined as: struct node { int data; node* left_child; node* right_child; node* parent; (10) (7) (13) (14) (a) (4 marks) Write a function sumAtLevel that accept an integer m and the root node of a BST and calculates the sum of all the nodes (values) in a given level. Function Signature: int sumOfLevel(node *root, int m); For example: In the given BST, sumOfLevel(8, 2); will return 21. Because, the sum of the values of the nodes at level 2 is = 1 + 6 + 14 = 21. (b) (4 marks) Write a function minDepth that takes the root node of a BST as parameter. It finds the minimum depth of that tree. Function Signature: int minDepth(node *root); For example: In the given BST, minDepth(8) will return 2. 1 }; 4 6 8 The binary search tree node is defined as: struct node { int data; node* left_child; node* right_child; node* parent; (10) (7) (13) (14)
Expert Answer:
Answer rating: 100% (QA)
a int sumOfLevelnode root int m ifroot NULL return 0 ifm 0 ... 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 computer network questions
-
A mixture of acetone and water in a flash drum operating at 1 atm. The feed consists of 300 kmol/hr with a composition of 60% acetone. Also 70% of the feed is vaporized. Calculate the mole fractions...
-
C++ : Binary Trees 1. Write the definition of the function, nodeCount , that returns the number of nodes in thebinary tree. Add this function to the class binaryTreeType andcreate a program to test...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
Write a check (Figure 4 - 42) dated June 13, 20XX, to Byron Johnson in the amount of $296.83 for a washing machine, Complete the check stub. Figure 4 - 42 456 456 Amount To For KRA, INC 2596 Jason...
-
Find the number A so that Pr(- A < z < A) = 0.98 for the standard normal z-score.
-
Atlanta Office Equipment manufactures and sells metal shelving. It began operations on January 1, 2014. Costs incurred for 2014 are as follows (V stands for variable; F stands for fixed): Direct...
-
Contrast the different steps that are required in reviewing internal controls under the second standard of field work between a manual and an EDP system.
-
Presented on page 1032 are two independent situations. Situation 1 Hatcher Cosmetics acquired 10% of the 200,000 shares of common stock of Ramirez Fashion at a total cost of $14 per share on March...
-
Claudia is self-employed and earns $190,000 p.a. If she makes a tax deductible (concessional) contribution to superannuation of $15,000, will she save tax and if so, how much? Exclude Medicare Levy/...
-
The commercial loan operation of a financial institution has a standard for processing new loan applications in 24 hours. Table 7E.2 shows the number of applications processed each day for the last...
-
Calculate the partial derivatives Zx,Zy, ZZZy of the given function: zelny-(3x-2y)
-
What is the formula for calculating the present value of an amount A when the interest rate is R and the compounding frequency is continuous?
-
What series of equal annual payments is equivalent to a series of decreasing payments as follows: \($5\),000, \($4\),000, \($3\),000, \($2\),000, \($1\),000 if the interest rate is 10 percent per...
-
Design a program that asks the user to enter a stores sales for each day of the week. The amounts should be stored in an array. Use a loop to calculate the total sales for the week and display the...
-
A. Henriques has the following purchases and sales for May 2017: 2017 May 1 Sold to M. Marshall: brass goods 24, bronze items 36. Less 25 per cent trade discount. 1 Sold to R. Richards: tin goods 70,...
-
Design a program that has two parallel arrays: a String array named people that is initialized with the names of seven of your friends, and a String array named phoneNumbers that is initialized with...
-
Analyze the following circuit using LKV B) Change the NPN transistor to an PNP (so the 2 transistors are PNP) reanalize the circuit C) After the 2 analysis Explain what does this circuit do
-
Let (X. A. p) be a measure space. Show that for any A,B A, we have the equality: (AUB)+(An B) = (A) + (B).
-
Suppose that we allow strict inequalities in a linear program. Show that in this case, the fundamental theorem of linear programming does not hold.
-
Construct a computation dag for which one execution of a greedy scheduler can take nearly twice the time of another execution of a greedy scheduler on the same number of processors. Describe how the...
-
Show that in the recurrence T(n) max (T(q) +T(n q 1))+ O(n) , 0
-
Yvonne owns four cottages, all let furnished with a view to profit. None of the cottages is ever let to the same tenant for more than 31 consecutive days. In 2023-24 the number of days each cottage...
-
Anne's income for 2023-24 is as follows: Compute her income tax liability for the year.
-
In 2023-24, Alfred (not a Scottish taxpayer) had business profits of 16,940 and received net debenture interest of 1,520. He acquired the debentures on 1 July 2023 and accrued interest (gross) on 5...
Study smarter with the SolutionInn App