lecture 11.6

可自行balance的tree一共讲三种,除了上节课讲过的splay tree(分为四种case,insert as root),还有AVL tree,2-3-4 tree(引出red-black tree)

1. AVL tree

开始条件为:abs(height.left-height.right)>1

故而也需要counter记录左右的个数

左右比较后,更深的那侧自行进行内部rotate

2. 2-3-4 tree

searching: O(log n)

worst situation:log2n

best situation: log4n

3. 新element加入时逐层检查是否会因为新element的加入分成两部分,不能最下面有位置就直接加进来

4. red-black tree类似,每个点都要被标为红色或者黑色,相邻的两个点不能同时为红色(path),node的sibling标为红色,两种表示方法如下

 

原文地址:https://www.cnblogs.com/eleni/p/11807134.html