#1, theorem
On a two-fork search tree with a height of H, the operation Search, MINIMUM, MAXIMUM, successor, and predecessor on the dynamic collection can be completed in O (h) time.
#2, pseudo-code
Search, iterative form of search, take the minimum value, take the maximum value, find the successor, find the precursor.
1 //x is a element of the tree, K is the key of element we want to search.2tree-SEARCH (x,k)3 ifX==null or k==X.key4 returnx;5 6 ifk<X.key7 returntree-SEARCH (x.left,k);8 Else9 returnTree_search (X.RIGHT,K);
Tree-search
1 Iterative_tree_search (x,k) 2 while X!=null and k!=x.key3 if k<x.key4 x= X.left; 5 Else 6 x=x.right; 7 return x;
Iterative_tree_search
1 tree-MINIMUM (x)2 while x.left!=NULL3 x=x.left; 4 return x;
Tree-minimum
1 tree-MAXIMUM (x)2 while x.right!=NULL3 x= X.right; 4 return x;
Tree-maximum
1 tree-successor (x)2if x.right!=NULL3 return Tree_minimum (x.right); 4 y=x.p; 5 while Y!=null and x==y.right6 x=y; 7 y=y.p; 8 return y;
Tree-successor
1 terr-predecessor (x)2if x.left!=NULL3 return MAXIMUM (x.left); 4 y=x.p; 5 while Y!=null and x==y.right6 x=y; 7 y=y.p; 8 return y;
Terr-predecessor
&12-2 Find binary search tree