Question: (a) (4 marks) Write a function sumAtLevel that accept an integer m and the root node of a BST and calculates the sum of

(a) (4 marks) Write a function sumAtLevel that accept an integer m and the root node of a BST and calculates 1 }; 4 6 8 The binary search tree node is defined as: struct node { int data; node* left_child; node*

(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)

Step by Step Solution

3.44 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a int sumOfLevelnode root int m ifroot NULL return 0 ifm 0 ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Network Questions!