Lecture15

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

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

View Full Document Right Arrow Icon
Lecture 15 Red-Black Trees
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online