Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions