AVL tree--Data Structure
来源:互联网 发布:淘宝客费用 编辑:程序博客网 时间:2024/05/22 12:48
Height
Definition
The heightof a node is the maximum depth of its subtree.
AVL Property
AVL trees maintain the following property:
For all nodesN, |N.Left.Height−N.Right.Height| ≤ 1
We claim that this ensures balance.
Conclusion
AVL Property
If you can maintain the AVL property, you can perform operations inO(log(n))time.
AVLInsert(k,R)
Insert(k,R)
N ←Find(k,R)
Rebalance(N)
Rebalance(N)
P ←N.Parent
if N.Left.Height>N.Right.Height+1:
RebalanceRight(N)
if N.Right.Height>N.Left.Height+1:
RebalanceLeft(N)
AdjustHeight(N)
if P !=null:
Rebalance(P)
AdjustHeight(N)
N.Height←1+ max( N.Left.Height, N.Right.Height)
AVLDelete(N)
Delete(N)
M ←Parent of node replacingN
Rebalance(M)
Summary
AVL trees can implement all of the basic operations inO(log(n))time per operation.
MergeWithRoot(R1,R2,T)
T.Left←R1
T .Right←R2
R1.Parent←T
R2.Parent←T
return T
Time O(1).
Merge(R1,R2)
T ←Find(∞,R1)
Delete(T)
MergeWithRoot(R1,R2,T)
return T
Time O(h).
AVLTreeMergeWithRoot(R1,R2,T)
if |R1.Height−R2.Height| ≤1:
MergeWithRoot(R1,R2,T)
T .Ht←max(R1.Height,R2.Height) +1
return T
Split(R,x)
if R =null:
return (null,null)
if x ≤R.Key:
(R1,R2)←Split(R.Left,x)
R3←MergeWithRoot(R2,R.Right,R)
return (R1,R3)
if x >R.Key:
...
Summary
Merge combines trees.
Split turns one tree into two.
Both can be implemented inO(log(n))time for AVL trees.
- AVL tree--Data Structure
- Data Structure: Tree
- data structure -- tree
- Data Structure:Binary Tree
- Basic Tree--Data Structure
- Data Structure -Tree
- Data structure of tree
- Data Structure: Binary Index Tree
- Binary Search Tree--Data Structure
- Perl implement Tree data structure (1)
- Perl implement Tree data structure (2)
- JavaScript Build Tree Data Structure Using Array
- C#数据结构-树 data Structure Tree
- [数据结构]tree-form data structure summary
- Data Structure: Segment Tree 线段树
- [Data Structure][Tree][Binary Tree]POJ 2255----Tree Recovery
- Data Structure
- Data structure
- object detection方法汇总
- Strom Spouts
- jQ 子元素选择器和后代选择器
- shell 中bad substitution错误
- 9月29日云栖精选夜读:武装到“牙齿”!阿里云发布史上最强企业云安全架构 11层防护
- AVL tree--Data Structure
- Python Django+Echarts将数据作可视化输出
- JavaScript最全的10种跨域共享的方法
- 10斤酒两个桶
- main线程打印100此次“main”,新线程打印50次“new”。
- ExecutorService中submit和execute的区别
- hadoop 格式化时报错 No class configured for node2
- WIN32GUI消息机制简单探索
- XmlDocument节点遍历(C#)