Question: 2. Show that if a node in a binary search tree has two children, then its successor has no left child and its predecessor has

 2. Show that if a node in a binary search treehas two children, then its successor has no left child and its

2. Show that if a node in a binary search tree has two children, then its successor has no left child and its predecessor has no right child. 3. In a binary search tree, we might also keep track of the total number of nodes in that subtree (including the node itself). a. Assuming we store this value (e.g. x.size) write pseudocode for a function BSTKeyLessThan(T, k) that takes a tree T and a number k and returns the number of values in the tree T that are less than k. For example, if the tree had the number 1 through 9 in it, then BSTKeyLessThan(T, 5) should return 4. What is the best-case and worst-case running time of your algorithm? b. Describe an algorithm Median (T) that finds the median element in a binary search tree. Write pseudocode or state your algorithm precisely. State your run-time with respect to the height of the tree. 3. In a binary search tree, we might also keep track of the total number of nodes in that subtree (including the node itself). a. Assuming we store this value (e.g. x.size) write pseudocode for a function BSTKeyLessThan(t, k) that takes a tree T and a number k and returns the number of values in the tree T that are less than k. For example, if the tree had the number 1 through 9 in it, then BSTKeyLessThan(T, 5) should return 4. What is the best-case and worst-case running time of your algorithm? b. Describe an algorithm Median (T) that finds the median element in a binary search tree. Write pseudocode or state your algorithm precisely. State your run-time with respect to the height of the tree

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!