← capítulo

B-trees and B+ trees

The balanced tree reimagined for disk. Wide nodes → few levels → few disk reads.

On disk, cost = blocks read

Watch nodes fill and split

Keys accumulate; overflow → split, median rises. Root split → tree grows. All leaves stay at the same depth.

Fan-out crushes the height

500000 keys: 3 levels vs 19 → ~6× fewer disk reads. At ms/seek, that's the whole ballgame.

B+ trees (what databases use)

Takeaway

Match the structure to the memory hierarchy it runs on. In memory? Use a red-black tree. On disk? B-tree. Next: Union-Find.