Lecture 10 Balanced Search Trees

Search tree data structure maintaining dynamic set of n elements using tree of height O(logn).

Examples:

    >AVL trees

    >2-3 trees

    >2-3-4 trees

    >B-trees

    >Red-black trees

    >Skip lists

    >Treaps


Red-black trees

BST data structure with extra color field for each node, satisfying:

>Red-black properties:

1. Every node is either red or black;

2. The root and leaves(nil's) are black;

3. Every red node has black parent;

4. All simple paths from a node x to a descendant leaf of x have same #black nodes=black-height(x)


Example:



Height of red black tree:





Corollary:

Queries (Search  Min  Max  Successor  Predecessor) run in O(log(n)) in a red-black tree.

Updates (Insert  Delete) must modify the tree.

    ---BST operation

    ---color changes

    ---restructruing of links via rotations  O(1) time operations


Rotation:



RB-insert(x):

Idea

--Tree-Insert(x)

--color node red

---problem: parent might be red. So violate 3

---move violation up the tree via recoloring until we can fix violation via rotation & recoloring.







RB-Insert adds x to set & preserves red-blackness in O(logn) time.

#Case1 <= logn  #Case2 & 3 <= 2   O(1) rotations

Case 2 and 3 means termination. What we mainly to do is case 1.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值