English 中文(简体)
寻找 BST 平均身高时的 关系/时间复杂度
原标题:Recurrence Relation/Time Complexity for finding average height of a BST

假设我们有一个初始空的 BST, 在那里我执行 n 任意插入, 我如何找到这个 BST 的平均高度? 表达式/ 假代码将会是( 如果我没有错的话 ) :

H(T) = 1 + max(H(T.left), H(T.right))

我对重现此关联的猜测是 T(n) = 1 + 2* T(n/2) , 但我不确定这是否正确 。

现在我的两难处境是, 如果我的复发关系是正确的, 我如何计算我平均身高算法的平均复杂程度?

问题回答

在普通平均案例分析中, 普通平均案例分析更为复杂, 您无法真正使用您在普通最坏情况证明中使用的相同的大O 技术。 虽然您对高度的定义是正确的, 但将其转换为重现可能比较复杂。 首先, 您可能的意思是 T(n) = 1 + T(n/2) (这会使 O( log n) 高度高, 而您版本给出 O(n)), 然后, 无法保证数值在左右之间均分50- 50 。

如果您 < a href=> https://duckduckgo.com//?q= 平均+h8+of+a+binary+search+tree" rel=“nofollow'> 搜索一点点 , 你会看到在BSTs平均身高上有大量材料存在。 例如, < a href=> http://luc.devroye.org/devroye_1986_univ_a_ notte_on_the_hight_of_binary_search_trees.pdf" rel=“nofollow” 说, BST的预期身高通常为4.3* (log n), 成长时会经历许多复杂的数学才能到达那里。

T(n/2)+c where c is some constant and we divide our array in two parts but we use only single part to search.if out ans is the larger then the middle value of then we only search in (mid+1.....j) and if its smaller then the middle value then we only search in(i.....mid) so, at time we only work with the single sub-array





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...