notes12 - CSE 2320 Notes 12: Red-Black Trees (Last updated...

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

View Full Document Right Arrow Icon
CSE 2320 Notes 12: Red-Black Trees (Last updated 10/30/11 3:50 PM) Sedgewick 13.3-13.4 12.A. S TRUCTURAL P ROPERTIES A red-black tree is a binary search tree whose height is Ο log n ( ) in the number of keys ( n ) stored. 1. Every node is colored red or black. (Colors are only examined during insertion and deletion) 2. null is colored black and is optionally drawn as a sentinel node in diagrams. 3. Both children of a red node are black. 4. Every simple path from a child of node X to null has the same number of black nodes. This number is known as the black-height of X (bh(X)). These are not stored, but appear below nodes in some diagrams. Example ( notes12.page1.dat ): [170 1 1] (160 3 1) [150 1 1] [140 5 2] (130 1 1) (120 7 2) (110 1 1) [100 13 3] (90 1 1) [80 3 2] (70 1 1) (60 5 2) (50 1 1) (40 17 3) (30 1 1) (20 3 2) (10 1 1)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Observations: 1. A red-black tree with n internal nodes (“keys”) has height at most 2 lg( n +1). 2. If a node X is not null and its sibling is null , then X must be red. 3. There may be many ways to color a binary search tree to make it a red-black tree. 4. If the root is colored red, then it may be switched to black without violating structural properties. (Implementations usually color root as black.) 1 2 3 4 5 6 7 8 1 2 4 5 6 7 3 1 2 12.B. T OP -D OWN (R ECURSIVE ) I NSERTION 1. Start with unbalanced insert. a. If a (black) node (y) with both children colored red is encountered during downward search, flip colors on all three nodes before proceeding to the appropriate child (x or z):
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/25/2012 for the course CSE 2320 taught by Professor Bobweems during the Spring '12 term at UT Arlington.

Page1 / 11

notes12 - CSE 2320 Notes 12: Red-Black Trees (Last updated...

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

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