{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# lec10 - Introduction to Algorithms 6.046J/18.401J LECTURE...

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

Introduction to Algorithms 6.046J/18.401J L ECTURE 10 Balanced Search Trees Red-black trees Height of a red-black tree Rotations Insertion Prof. Erik Demaine October 19, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L7.1

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

View Full Document
Balanced search trees Balanced search tree: A search-tree data structure for which a height of O (lg n ) is guaranteed when implementing a dynamic set of n items. AVL trees 2-3 trees Examples: 2-3-4 trees B-trees Red-black trees October 19, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L7.2
Red-black trees This data structure requires an extra one- bit color field in each node. Red-black properties: 1. Every node is either red or black. 2. The root and leaves ( NIL ’s) are black. 3. If a node is red, then its parent is black. 4. All simple paths from any node x to a descendant leaf have the same number of black nodes = black-height( x ) . October 19, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L7.3

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

View Full Document
Example of a red-black tree h = 4 8 8 11 11 10 10 18 18 26 26 22 22 3 3 7 7 NIL NIL NIL NIL NIL NIL NIL NIL NIL October 19, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L7.4
Example of a red-black tree 8 8 11 11 10 10 18 18 26 26 22 22 3 3 7 7 NIL NIL NIL NIL NIL NIL NIL NIL NIL 1. Every node is either red or black. October 19, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L7.5

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

View Full Document
Example of a red-black tree 8 8 11 11 10 10 18 18 26 26 22 22 3 3 7 7 NIL NIL NIL NIL NIL NIL NIL NIL NIL 2. The root and leaves ( NIL ’s) are black. October 19, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L7.6
Example of a red-black tree 8 8 11 11 10 10 18 18 26 26 22 22 3 3 7 7 NIL NIL NIL NIL NIL NIL NIL NIL NIL 3. If a node is red, then its parent is black. October 19, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L7.7

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

View Full Document
Example of a red-black tree 8 8 11 11 10 10 18 18 26 26 22 22 3 3 7 7 NIL NIL NIL bh = 2 bh = 1 bh = 1 bh = 2 bh = 0 NIL NIL NIL NIL NIL NIL 4. All simple paths from any node x to a descendant leaf have the same number of black nodes = black-height ( x ) .
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}