lecture09-RBTree-handout

# lecture09-RBTree-handout - RB Insert: Case 1 if (y->color =...

This preview shows pages 1–4. Sign up to view the full content.

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 1

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

View Full Document
B x RB Insert: Case 2 if (x == x->p->right) x = x->p; leftRotate(x); // continue with case 3 code Case 2: “Uncle” is black Node x is a right child Transform to case 3 via a left-rotation C A C B y A x case 2 y Transform case 2 into case 3 (x is left child) with a left rotation This preserves property 4: all downward paths contain same number of black nodes 2
RB Insert: Case 3 x->p->color = BLACK; x->p->p->color = RED; rightRotate(x->p->p); Case 3: “Uncle” is black Node x is a left child Change colors; rotate right

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/30/2011 for the course CS 6713 taught by Professor Su during the Spring '11 term at Arkansas State.

### Page1 / 12

lecture09-RBTree-handout - RB Insert: Case 1 if (y->color =...

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

View Full Document
Ask a homework question - tutors are online