Lecture15

# Lecture15 - Lecture 15 Red-Black Trees Red-Black Tree A...

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

Lecture 15 Red-Black Trees

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

View Full Document
Red-Black Tree A Red-Black tree is a binary search tree that obeys 4 properties: 1) Every node is colored red or black 2) All children of a red node are black 3) [black height property] For every node in the tree, all paths from that node down to a NULL have the same number of black nodes along the path 4) The root is black
Height and Size of RB Trees If every path from root down to NULL has B black nodes, then tree has at least 2 B -1black nodes (can show by induction) N >= 2 B -1 (since number nodes >= number black nodes) log( N + 1 ) >= B log( N + 1 ) >= ½ height of tree (since B >= ½ height) Height of tree <= 2 log (N+1) = O( log N) RED BLACK TREES HAVE O( log N ) height

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

View Full Document
Bottom-Up Insertion into RB tree First insert as you would in standard binary search tree Color new node red If parent is black, done If parent is red, have red-red violation. Fix by recoloring and (maybe) rotation.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

Lecture15 - Lecture 15 Red-Black Trees Red-Black Tree A...

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

View Full Document
Ask a homework question - tutors are online