Lecture Notes for CS 512, Algorithm Design
Red-Black Trees - 7 February 2000
- what's the matter with binary search trees?
- average case vs. worst case
- average case behavior is O(log n)
- worst case behavior is O(n)
- binary search trees can become unbalanced
- tree height
- unbalanced trees have a significant difference between subtree heights
- constraining subtree height differences provides balance
- AVL trees limit the height difference to -1, 0, or 1
- strict constraints require more work
- and don't forget the O(log n) limit on operations
- red-black trees
- a binary search tree
- nodes are either red or black
- leaves are special; leaves are black
- red parents don't have black children
- every root-leaf path has the same number of black nodes
- a rb tree's black height
- search(), min(), max(), succ(), pred() run in O(log
n)
- insertion
- insert new values as in bst
- new nodes are red
- deletion
- splice out the deleted node
- the replacement node inherits the extra 1 if the deleted node was
black
This page last modified on 14 February 2000.