(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...
-
Would it be advantageous to borrow money if you expected prices to rise? Why or why not?
-
The W-2 incomes of Betty and her husband Ronald were $47,222 and $44,910, respectively. If Betty and Ronald use a filing status of married filing jointly, determine their tax liability using the tax...
-
How a user conceptually organizes and understands data is referred to as the a. physical view c. data model view b. logical view d. data organization view
-
The scheduler at Haley's Airframes uses MPS time-phased records for planning end item production. The planner is currently working on a schedule for a strut assembly, one of Haley's top-selling spare...
-
1 ES Book Print 0 erences The general ledger of Pipers Plumbing at January 1, 2024, includes the following account balances: Accounts Cash Accounts Receivable Supplies Equipment Accumulated...
-
Christy Albright and Dan Ralls formed the Charter Company on 11/30/2012, and chose a tax year ending on 11/30. Charter was formed to operate a restaurant (at 7848 Pesca Dr., San Francisco, CA 94123)...
-
Why did the United States have no central bank between 1836 and 1913? OA. The IMF served as the central bank for the United States. OB. The country hadn't yet established a central bank. OC. The...
-
Solomon Sooners is a 40 year old man and unmarried. He is a sole supporter of his parents. The parents have no income. His father is 67 of age and in good health; his mother is 64 years old and...
-
James Ltd. has two service departments and two production departments. The summary of the costs in each department and the percentages of expenses charged out by the service departments are as...
-
How does the interplay between endocrine hormones and the nervous system mediate the body's stress response, and what are the long-term effects of chronic stress on hormone regulation ?
-
What are some of the reasons for the impairment of intangible assets such as Goodwill? What are some justifications for treating the write-down as a permanent decline in value of the asset(s)? What...
-
If g is the vector-valued function defined by g (t) = (sin(2t), cos(3t)), then g' (t) =
-
Potential of Multiple Charges: What is the correct value of the electric potential (in volts) due to point charges Q1=-8.79E0C and 92 =4.71E0C at the center of the sphere (of radius R) in the...
-
What is your opinion of advertising awards, such as the Cannes Lions, that are based solely on creativity? If you were a marketer looking for an agency, would you take these creative awards into...
-
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
-
Estimate the ending inventory by the gross profit method, given the following data: beginning inventory, \(\$ 40,000\); net purchases, \(\$ 100,000\); net sales, \(\$ 112,000\); average gross profit...
-
Use your operating systems built-in capability to encrypt a file. Store the enciy'pted file in a folder that can be shared with other users on that computer. Then create a new user account. Assign it...
-
Why do companies using LIFO in a perpetual inventory system often restate their ending inventory at the per-unit costs that result from applying periodic LIFO costing procedures?
Study smarter with the SolutionInn App