rb_example1 - 1/26 Red-black tree properties • Every node...

Info iconThis preview shows pages 1–6. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 /26 Red-black tree properties • Every node in a red-black 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 Red-Black 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 Red-Black Tree. – insert the new node at that location. • Color the new node red . • Use the cases described in the following slides to restore any Red-Black Tree properties that are violated by the new node. 3 /26 Red-black 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 Red-black 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 r-b violation upward that must also be fixed… ( x could also be a right child) compare w/ Figure 13.5 x x 5 /26 Red-black 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.

Page1 / 28

rb_example1 - 1/26 Red-black tree properties • Every node...

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

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