!!!Chapter 12 Advanced Data Structure and Implementation

12.2 Red Black Tree

Operations on red black trees take O(logN) time in the worst case, and a careful nonrecursive implementation can be done relatively effortlessly.

A red black tree is a binary search tree with the following coloring properties:

1. Every node is colored either red or black.

2. The root is black.

3. If a node is red, its children must be black.

4. Every path from a node to a NULL pointer must contain the same number of black nodes.

(5). All leaves (NULL node) are black.

The height of a red black tree is at most 2log(N+1). Height of AVL tree & red black tree:http://en.wikipedia.org/wiki/AVL_tree

12.2.1 Bottom-Up Insertion

When insert a new node, it must be red. Otherwise, it will break rule 4. When we add a red node, there are two scenarios:

1. The parent node is black: In this case, we are done

2. The parent node is red: In this case, we need to change color and rotate tree






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值