(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...
-
How can you best handle a material?
-
Each of the following compounds possesses carbon atoms that are chirality centers. Locate each of these chirality centers, and identify the configuration of each one: a. b. c. d. e. f. Ephedrine A...
-
The August 2025 transactions of Jackson Productions Ltd, which uses a job order costing system, are shown below. (Ignore GST.) 1. Raw materials purchased, $171 000. 2. Raw materials issued to...
-
The total processing cost for producing the X-Pacer running shoe in Problem 2-5 is $18. The Omega Shoe Company starts production of 650 pairs of the shoes weekly, and the average weekly yield is 90%,...
-
what ways has the incorporation of metal-organic frameworks (MOFs) in catalytic applications expanded the scope of catalysis, particularly in gas-phase reactions and environmental catalysis ?
-
What Happens When You Dont Deliver on Your Promises Web: www.clearly.ca Facebook: Clearly Canadian If a new product or service seems like the perfect option to solve a problem or capitalize on an...
-
A sequential search member function of SortedType has the following prototype: void SortedType::Search(int value, bool& found); 1. Write the function definition as a recursive search, assuming a...
-
Let \(T \sim \Gamma(4,0.5)\). a. Find \(\mu_{T}\). b. Find \(\sigma_{T}\). c. Find \(P(T \leq 1)\). d. Find \(P(T \geq 4)\).
-
A new centrifugal pump is being considered for an application involving the pumping of ammonia. The specification is that the flow rate be more than \(5 \mathrm{gal}-\) lons per minute (gpm). In an...
-
Explain what is meant by the following: 1. base case 2. general (or recursive) case 3. run-time stack 4. binding time 5. tail recursion
-
The article "Developing a Tool to Measure the Factors Influencing Nurses' Enjoyment of Nursing" (L. Wilkes, M. Doull, et al., Journal of Clinical Nursing, 2016:1854-1860) reports that in a sample of...
-
10. Thylakoids, DNA, and ribosomes are all components found in a. vacuoles b. chloroplasts c. mitochondria d. lysosomes e. nuclei 11. Where are the proteins produced other than on ribosomes free in...
-
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
-
Consider an experiment that selects a cell phone camera and records the recycle time of a flash (the time taken to ready the camera for another flash). The possible values for this time depend on the...
-
Suppose that the recycle times of two cameras are recorded. The extension of the positive real line \(R\) is to take the sample space to be the positive quadrant of the plane \[ S=R^{+} \times R^{+}...
-
Consider the sample space \(S=\{y y, y n, n y, n n\}\) in Example 2.2. Suppose that the subset of outcomes for which at least one camera conforms is denoted as \(E_{1}\). Then, \[ E_{1}=\{y y, y n, n...
Study smarter with the SolutionInn App