Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Binary search tree with equal keys. ( 4 0 points ) In the class, we assumed that all the keys in a BST are different

Binary search tree with equal keys. (40 points) In the class, we assumed that all the
keys in a BST are different from each other. However, the BST can still store keys of the
same value, in this case, we put a key that is less than a node to its left, and put a key
that is greater than or equal to a node to its right. Here is the algorithm for inserting
a new key z in to a binary search tree T :
Algorithm 1: Tree-Insert (T,z)
y= NIL;
x= T.root;
while x NIL
y=x;
if x=xx=x=yy==NIL=z;,??T=zz.key.key
x=x.left;
else x=x.right
z.parent =y;
ify==NIL
T.root =z;,?? tree T was empty
elseif z.key=z;
else y.right =z;
(a)(10 points) To better understand the algorithm, draw the tree generated by inserting
the numbers 5,3,10,8,12,12,8,8,6,6,7,5,8 in this given order into an initially
empty binary search tree using the above algorithm.
(b)(10 points) What is the asymptotic runtime of TREE-INSERT when used to insert n
items with identical keys into an initially empty binary search tree?
We propose to improve TREE-INSERT by testing before line 5 to determine whether
z.key ==x.key and by testing before line 11 to determine whether z.key==y.key. If
equality holds, we implement one of the following strategies. For each strategy, find
the asymptotic runtime of inserting n items with identical keys into an initially empty
binary search tree. (The strategies are described for line 5, in which we compare the
keys of z and x, and substitute y for x to arrive at the strategies for line 11.)
(c)(10 points) Keep a list of nodes with equal keys at x, and insert z into the list.
(d)(10 bonus) Randomly set x to either x.left or x.right. (Give the worst-case runtime
and informally derive the expected runtime.)
[Note: for (b)(c) and (d), we are expecting the runtime represented as a
function of n.
image text in transcribed

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

Recommended Textbook for

Master The Art Of Data Storytelling With Visualizations

Authors: Alexander N Donovan

1st Edition

B0CNMD9QRD, 979-8867864248

More Books

Students also viewed these Databases questions

Question

What questions should Jessica ask of Anna?

Answered: 1 week ago

Question

Does it avoid using personal pronouns (such as I and me)?

Answered: 1 week ago

Question

Does it clearly identify what you have done and accomplished?

Answered: 1 week ago