是否证明了在二叉树中重复调用successor()的效率? [英] Prove the efficiency of repeated calls to successor() in binary trees?
本文介绍了是否证明了在二叉树中重复调用successor()的效率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要《 CLRS算法》一书中的这个练习的提示:
I need a hint for this exercise from the CLRS Algorithms book:
证明无论我们从高处开始于哪个节点-h二进制搜索树,对Tree-Successor的 k 连续调用需要 O(k + h)时间。
推荐答案
- 让
x
为起始节点,而z
是k
连续调用TREE-SUCCESSOR之后的结束节点。 - 让
p
是x
和z
之间的简单路径。 - 让
y
为x
和的共同祖先z
访问p
。 -
p $ c的长度$ c>最多为
2h
,即O(h)
。 - 让
output
成为它们的值在x.key
和z之间的元素。键
。 -
输出
的大小为O(k)
。 - 在执行
k
个连续调用TREE-SUCCESSOR的过程中,
个位于p $ c中的节点$ c>,
以及节点x
,y
和z
,
如果访问了p
中某个节点的子树,则其所有元素都在输出中
。 - 因此运行时间为
O(h + k)
。 - Let
x
be the starting node andz
be the ending node afterk
successive calls to TREE-SUCCESSOR. - Let
p
be the simple path betweenx
andz
inclusive. - Let
y
be the common ancestor ofx
andz
thatp
visits. - The length of
p
is at most2h
, which isO(h)
. - Let
output
be the elements that their values are betweenx.key
andz.key
inclusive. - The size of
output
isO(k)
. - In the execution of
k
successive calls to TREE-SUCCESSOR, the nodes that are inp
are visited, and besides the nodesx
,y
andz
, if a sub tree of a node inp
is visited then all its elements are inoutput
. - So the running time is
O(h+k)
.
这篇关于是否证明了在二叉树中重复调用successor()的效率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文