This preview shows pages 1–12. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CSE 4101/5101 RedBlack Tree Prof. Andy Mirzaian Lists MovetoFront Search Trees Binary Search Trees MultiWay Search Trees Btrees Splay Trees 234 Trees RedBlack Trees SELF ADJUSTING WORSTCASE EFFICIENT competitive competitive? Linear Lists MultiLists Hash Tables DICTIONARIES 2 References: [CLRS] chapter 13 AAW animation 3 Binary Search trees from 234 trees 234 trees are perfectly balanced ( height: log(n+1) h log(n+1) ) search trees that use 2nodes, 3nodes, and 4nodes. We can transform a 234 tree to an O(log n) height BST by replacing each 3node and 4node by a smallclustered BST with 2 or 3 binary nodes. Dilemma: How do we distinguish node clusters? Disallowed 4node clusters: 2node right slant left slant OR 3node 4node 4 RedBlack trees from 234 trees Although the resulting BST has height O(log n) , it loses the node cluster information and renders the 234 tree algorithms obsolete. We use a node cluster colourcoding 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 4node clusters: 2node right slant left slant OR 3node 4node 5 Example: 234 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 RedBlack 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: RedBlack tree DEFINITION: T is a RedBlack 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.) Worstcase time: O(h) = O(log n). Simulate the 234 tree algorithms as shown next. Worstcase 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
 Winter '12
 Mirzaian
 Binary Search, Data Structures

Click to edit the document details