证明二叉树中重复调用 successor() 的效率?
我需要 CLRS 算法书中关于此练习的提示:
证明无论我们从高度为 h 的二叉搜索树中的哪个节点开始,k 次连续调用 Tree-Successor 都会花费 O(k+h) 时间.
I need a hint for this exercise from the CLRS Algorithms book:
Prove that no matter what node we start at in a height-h binary search tree, k successive calls to Tree-Successor take O(k+h) time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
x
为起始节点,z
为结束节点。p
为x
和z
之间的简单路径(包含)。y
为p
访问的x
和z
的共同祖先。p
的长度最多为2h
,即O(h)
。output
为其值在x.key
和z.key
之间的元素。输出
的大小为O(k)
。k
次连续调用TREE-SUCCESSOR时,访问
p
中的节点,除了节点 x、y 和 z 之外,
如果访问
p
中节点的子树,那么它的所有元素都在output
中。O(h+k)
。x
be the starting node andz
be the ending node afterk
successive calls to TREE-SUCCESSOR.p
be the simple path betweenx
andz
inclusive.y
be the common ancestor ofx
andz
thatp
visits.p
is at most2h
, which isO(h)
.output
be the elements that their values are betweenx.key
andz.key
inclusive.output
isO(k)
.k
successive calls to TREE-SUCCESSOR,the nodes that are in
p
are visited,and besides the nodes
x
,y
andz
,if a sub tree of a node in
p
is visited then all its elements are inoutput
.O(h+k)
.提示:举一个小例子,观察结果,尝试推断原因。
首先,需要考虑以下一些事项。
从某个节点开始,连续 k 次调用 Tree-Succcesor 构成部分树遍历。这次步行访问了多少个(至少和最多)节点? (提示:考虑 key(x))。请记住,一条边最多被访问两次(为什么?)。
最后提示:结果是
O(2h+k)
。Hint: work out a small example, observe the result, try to extrapolate the reason.
To get started, here are some things to consider.
Start at a certain node, k succesive calls to Tree-Succcesor consititutes a partial tree walk. How many (at least and at most) nodes does this walk visit? (Hint: Think about key(x)). Keep in mind that an edge is visited at most twice (why?).
Final hint: The result is
O(2h+k)
.