Answered step by step
Verified Expert Solution
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. 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 in to a binary search tree :
Algorithm : TreeInsert
NIL;
Troot;
while NIL
;
if NIL;key.key
left;
else right
parent ;
NIL
root ; tree was empty
elseif key;
else yright ;
a points To better understand the algorithm, draw the tree generated by inserting
the numbers in this given order into an initially
empty binary search tree using the above algorithm.
b points What is the asymptotic runtime of TREEINSERT when used to insert
items with identical keys into an initially empty binary search tree?
We propose to improve TREEINSERT by testing before line to determine whether
zkey key and by testing before line to determine whether zkeyykey. If
equality holds, we implement one of the following strategies. For each strategy, find
the asymptotic runtime of inserting items with identical keys into an initially empty
binary search tree. The strategies are described for line in which we compare the
keys of and and substitute for to arrive at the strategies for line
c points Keep a list of nodes with equal keys at and insert into the list.
d bonus Randomly set to either xleft or xright. Give the worstcase runtime
and informally derive the expected runtime.
Note: for bc and d we are expecting the runtime represented as a
function of
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started