lecture08-RBTree

lecture08-RBTree - CS 6713 Advanced Analysis of Algorithms...

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

View Full Document Right Arrow Icon
Sources: Dr. David Luebke’s slides Internet CS 6713 Advanced Analysis of Algorithms Lecture 08 Red-Black Trees (cont’d) 1
Background image of page 1

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

View Full Document Right Arrow Icon
2
Background image of page 2
Red-Black Trees: Insertion Insertion: the basic idea Insert x into tree, color x red Only r-b property 3 might be violated (if p[ x ] red) If so, move violation up tree until a place is found where it can be fixed Total time will be O(lg n ) 1. Every node is either red or black 2. Every leaf (NULL pointer) is black 3. If a node is red, both children are black 4. Every path from node to descendent leaf contains the same number of black nodes 5. The root is always black 3
Background image of page 3

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

View Full Document Right Arrow Icon
RB Insert: Case 1 if (y->color == RED) x->p->color = BLACK; y->color = BLACK; x->p->p->color = RED; x = x->p->p; Case 1: “uncle” is red In figures below, all ’s are equal-black-height subtrees C A D B C A D B x y new x Change colors of some nodes, preserving #4: all downward paths have equal b.h. The while loop now continues with x’s grandparent as the new x case 1 4
Background image of page 4
B x RB Insert: Case 1 if (y->color == RED) x->p->color = BLACK; y->color = BLACK; x->p->p->color = RED; x = x->p->p; Case 1: “uncle” is red In figures below, all ’s are equal-black-height subtrees C A D C A D y new x Same action whether x is a left or a right child B x case 1 5
Background image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 28

lecture08-RBTree - CS 6713 Advanced Analysis of Algorithms...

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