RedBlack - CSE 4101/5101 Red-Black Tree Prof. Andy Mirzaian...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 4101/5101 Red-Black Tree Prof. Andy Mirzaian Lists Move-to-Front Search Trees Binary Search Trees Multi-Way Search Trees B-trees Splay Trees 2-3-4 Trees Red-Black Trees SELF ADJUSTING WORST-CASE EFFICIENT competitive competitive? Linear Lists Multi-Lists Hash Tables DICTIONARIES 2 References: [CLRS] chapter 13 AAW animation 3 Binary Search trees from 2-3-4 trees 2-3-4 trees are perfectly balanced ( height: log(n+1) h log(n+1) ) search trees that use 2-nodes, 3-nodes, and 4-nodes. We can transform a 2-3-4 tree to an O(log n) height BST by replacing each 3-node and 4-node by a small-clustered BST with 2 or 3 binary nodes. Dilemma: How do we distinguish node clusters? Disallowed 4-node clusters: 2-node right slant left slant OR 3-node 4-node 4 Red-Black trees from 2-3-4 trees Although the resulting BST has height O(log n) , it loses the node cluster information and renders the 2-3-4 tree algorithms obsolete. We use a node cluster colour-coding scheme to resolve this. Convention: each cluster top level is black (including external nodes), lower levels within each cluster are red. So, any red node is clustered within its parent cluster. Disallowed 4-node clusters: 2-node right slant left slant OR 3-node 4-node 5 Example: 2-3-4 tree 36 12 18 26 42 48 6 8 10 14 16 20 22 24 28 30 32 38 44 50 52 54 bh = 3 black height, including external nodes 6 . ) 1 n ( log bh ) 1 n ( log 2 1 + + Transformed Red-Black tree bh = 3 black height, including external nodes 36 10 6 14 20 24 32 28 54 50 8 16 22 30 38 44 52 12 26 48 18 42 7 . 1 ) 1 n ( log 2 1 bh 2 h height - + - Definition: Red-Black tree DEFINITION: T is a Red-Black tree if it satisfies the following: 1. T is a Binary Search Tree with a red / black colour bit per node. 2. Every red node has a black parent. ( root is black.) 3. By convention we assume all external nodes are black . 4. All external nodes have the same number (namely, bh) of black proper ancestors. 8 Implementing Operations Access operations : SEARCH MINIMUM MAXIMUM PREDECESSOR SUCCESSOR Update Operations : INSERT DELETE Use the BST algorithms without change. (Simply ignore the node colours.) Worst-case time: O(h) = O(log n). Simulate the 2-3-4 tree algorithms as shown next. Worst-case time: O(h) = O(log n). 9 Example operations SEARCH 40 INSERT 40 36 10 6 14 20 24 32 28 54 50 8 16 22 30 38 44 52 12 26 48 18 42 40 10 Local Restructuring INSERT and DELETE need the following local operations that take O(1) time each: Node Colour Switch: red black Link Rotation a b b a Right Rotate Left Rotate FACT: Rotation preserves INORDER sequence of the tree nodes and changes slant of link ....
View Full Document

Page1 / 30

RedBlack - CSE 4101/5101 Red-Black Tree Prof. Andy Mirzaian...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online