算法导论 个人答案 12.2 (未完)

(今天主要解决了昨天遗留的问题。在上课的论坛上讨论还是很有效的。12.2未结)

 

12.2-1:

2011020800175788.png

 

 

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;

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.

转载于:https://www.cnblogs.com/flyfy1/archive/2011/02/08/1949770.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值