




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Jared Saia University of New Mexico
Tree-Search(x,k){ if (x=nil) or (k = key(x)){ return x; } if (k<key(x)){ return Tree-Search(left(x),k); }else{ return Tree-Search(right(x),k); } }
A useful tool for proving correctness is loop invariants. Three things must be shown about a loop invariant
12
Tree-Successor(x){ if (right(x) != null){ return Tree-Minimum(right(x)); } y = parent(x); while (y!=null and x=right(y)){ x = y; y = parent(y); } return y; }
Insert(T,x)
P (n) =
n
n∑− 1
i=
(P (i) + P (n − i − 1) + n − 1) (1)
n
n∑− 1
i=
(P (i) + P (n − i − 1)) +
n
n∑− 1
i=
n − 1)) (2)
n
n∑− 1
i=
(P (i) + P (n − i − 1)) + Θ(n) (3)
n
n∑− 1
k=
P (k)) + Θ(n) (4)
(5)