Bartleby Related Questions Icon

Related questions

Question

I need help with this

12.2-9
Let T be a binary search tree whose keys are distinct, let x be a leaf node, and let y
be its parent. Show that y.key is either the smallest key in T larger than x.key or
the largest key in T smaller than x.key.
expand button
Transcribed Image Text:12.2-9 Let T be a binary search tree whose keys are distinct, let x be a leaf node, and let y be its parent. Show that y.key is either the smallest key in T larger than x.key or the largest key in T smaller than x.key.
TREE-INSERT (T, z)
1 y = NIL
2 x = T.root
3 while x + NIL
4
y = x
if z.key < x.key
x = x.left
else x = x.right
5
6
7
8
z.p= y
9
if y == NIL
10
T.root = z
11 elseif z.key < y.key
12
y.left = z
13 else y.right: = z
// tree T was empty
expand button
Transcribed Image Text:TREE-INSERT (T, z) 1 y = NIL 2 x = T.root 3 while x + NIL 4 y = x if z.key < x.key x = x.left else x = x.right 5 6 7 8 z.p= y 9 if y == NIL 10 T.root = z 11 elseif z.key < y.key 12 y.left = z 13 else y.right: = z // tree T was empty
SAVE
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
bartleby
Unlock instant AI solutions
Tap the button
to generate a solution
Click the button to generate
a solution