Skip to content

Commit

Permalink
树的时间复杂度
Browse files Browse the repository at this point in the history
  • Loading branch information
Xikl committed Nov 12, 2018
1 parent afc9ee9 commit e1f41d8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ S 就是D的后继
然后 需要删除S的最小值 S.right = removeMin(D.right)
然后S.left = D.left
删除D, S是新的子树的根

- 5 树的时间复杂度为 O(h) h为树的高度
其中 假设 一个树为满二叉树
他的节点个数为 2^0 + 2^1 + 2^2 + 2^3 + ... + 2^h-1 = 1 * (1-2^h)/(1-2) = 2^h-1 = n
所以h = logn 故 O(h) = O(logn)
这是一种非常快的速度 当然只是平均的时间 最坏的情况 当树变成一个链表的时候 将会变O(n)



0 comments on commit e1f41d8

Please sign in to comment.