(今天主要解决了昨天遗留的问题。在上课的论坛上讨论还是很有效的。12.2未结)
12.2-1:
12.2-2:
RECURSIVE-TREE-MINIMUM(X):
while(x.left != null):
x = x.left;
return x;
RECURSIVE-TREE-MAXIMUM(X):
while(x.right != null):
x = x.right;
return x;
12.2
-
3
:
TREE - PREDECESSOR(x):
if (x.left != null ):
return x.left;
t = x.parent;
while (x == t.left && t != null )
x = t; t = t.parent;
return t;
TREE - PREDECESSOR(x):
if (x.left != null ):
return x.left;
t = x.parent;
while (x == t.left && t != null )
x = t; t = t.parent;
return t;
12.2-5:
If one BST node has two children, then its predecessor is the maximum of its left
sub-tree, and its successor is the minimum of its right sub-tree. The smallest
element has no left child, and the largest one has no right child.
12.2-6:
Think from node x.
If x don't have a right sub-tree, then its successor is the ancestor where the left
sub-tree is the first to contain x. Therefore, this successor is the lowest ancestor
of x, whose left child is also an ancestor of x.