![]() |
Jupyter at Bryn Mawr College |
|
|
Public notebooks: /services/public/dblank / CS206 Data Structures / 2017-Spring / Notebooks |
We looked at Search Trees previously, and we knew that they were better if balanced. Now we explore how to automatically keep them balanced.
Most of the algorithms that we will discuss use the ideas of balance and rotation.
We have explored AVL trees very thoroughly.
Rules (Invariants):
Adding a new node:
Fig 9.22:
Fig 9.23:
Fig 9.25:
Red-Black Simulation:
https://www.cs.usfca.edu/~galles/visualization/RedBlack.html
Other notes:
Children are either 2-node or 3-node
If n = 200, then each node has between 100 and 200 children. Tree of height 4 could hold:
$$ 100 ^ 4 $$
or 100 million values.
A B-Tree with n set to 4.