4 5 6 7 TREE-INSERT (T, z) 1 y = NIL 2 x = T.root 3 while x NIL y = x if z.key < x.key x = x.left else x = x.right 8 z.p = y 9 if y == NIL 10 T.root = z // tree T was empty 12 elseif z.key

icon
Related questions
Question

I need help with this please

4
5
6
7
TREE-INSERT (T, z)
1 y = NIL
2 x = T.root
3 while x NIL
y = x
if z.key < x.key
x = x.left
else x = x.right
8
z.p = y
9
if y == NIL
10
T.root = z
// tree T was empty
12
elseif z.key<y.key
13 else y.right = z
y.left = z
Transcribed Image Text:4 5 6 7 TREE-INSERT (T, z) 1 y = NIL 2 x = T.root 3 while x NIL y = x if z.key < x.key x = x.left else x = x.right 8 z.p = y 9 if y == NIL 10 T.root = z // tree T was empty 12 elseif z.key<y.key 13 else y.right = z y.left = z
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.
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.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer