Chapter 14 Exercises

Exercises
14.2-2 Can the black-heights of nodes in a red-black tree be maintained as fields in the nodes of the tree without affecting the asymptotic performance of any of the red-black tree operations? Show how, or argue why not.
The answer is yes. Red-black trees has two primitive operation. One is change a node's color and the other is rotations. Changing color only effects the node and its ancestors, which is O(logn) nodes. When rotating is performed, the nodes involved in rotating may have their b-h value changed, and so do their ancestors, which is also O(logn) nodes in all. Thus, maintaining this field results in an extra cost of O(logn) per operation, which does not affect the asymptotic performance of any rb-tree operation.

14.2-3 Can the depths of nodes in a red-black tree be efficiently maintained as fields in the nodes of the tree? Show how, or argue why not.
The answer is yes if an additional field, maintain, is maintained.

14.2-5 We wish to augment red-black trees with an operation RB-ENUMERATE(x,a,b) that outputs all the keys k such that a<=k<=b in a red-black tree rooted at x. Describe how RB-ENUMERATE can be implemented in Θ(m+logn) time, where m is the number of keys that are output and n is the number of internal nodes in the tree.(Hint: There is no need to add new fields to the red-black tree).
First, locate the smallest node which is not smaller than a. This takes Θ(logn). Then we're to prove that m-1 successive calls of SUCCESSOR operation takes Θ(m) time.
Consider the spanning tree T that connects these m nodes. Recall that these m nodes are successive. Thus if we draw the route the SUCCESSOR operations passes, each edge in T must be visited at least once and at most twice. Thus, the time for SUCCESSOR operations is Θ(m).

14.3-6 Show how to maintain a dynamic set Q of numbers that supports the operation MIN-GAP, which gives the magnitude of the difference of the two closest numbers in Q. Make the operations INSERT, DELETE, and MIN-GAP as efficient as possible, and analyze their running times.
Use any balanced binary search tree to store Q, and maintain another tree T. When a number x is inserted, consider x's predecessor y and successor z. Insert x-y and z-x into T(if exists). When a number x is deleted, also delete such x-y and z-x from T(if exists). The MIN-GAP call can be simply implemented by calling T's MINIMUM operation. Thus, all operations can be performed in Θ(logn).

转载于:https://www.cnblogs.com/FancyMouse/articles/1176551.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值