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 Document
Unformatted text preview: 1 /26 Redblack tree properties • Every node in a redblack tree is either black or red • Every null leaf is black • No path from a leaf to a root can have two consecutive red nodes  i.e. the children of a red node must be black • Every path from a node, x, to a descendant leaf contains the same number of black nodes  the “black height” of node x . In these slides we don’t force the root to be black 2 /26 Insertion: The First Step • Given a new node with a key value, the first step is to determine where to insert the new node. • Since a RedBlack Tree is a Binary Search Tree (BST), use the BST Insert procedure to: – determine the location where the new node’s key value belongs in the RedBlack Tree. – insert the new node at that location. • Color the new node red . • Use the cases described in the following slides to restore any RedBlack Tree properties that are violated by the new node. 3 /26 Redblack tree insertion: Case 0: New node’s parent is black. No property is violated, so there’s nothing to do. n e w l y i n s e r t e d n o d e 4 /26 Redblack tree insertion: Case 1: New node’s parent and uncle are both red. color flip: x’ s parent, uncle, and grandparent all change color newly inserted node This node is now red; possibly propagating a rb violation upward that must also be fixed… ( x could also be a right child) compare w/ Figure 13.5 x x 5 /26 Redblack tree insertion: Case 3: New red node’s parent is red and uncle is black ;...
View
Full
Document
This note was uploaded on 02/13/2012 for the course CS 91.404 taught by Professor Dr.karendaniels during the Fall '09 term at UMass Lowell.
 Fall '09
 DR.KARENDANIELS

Click to edit the document details