October 2025
Intermediate to advanced
485 pages
13h 2m
English
Like red-black trees and randomized treaps, B-trees are self-balancing. However, B-trees perform a different kind of self-balancing, as you’ll now see.
In the following example, we’re going to work with a B-tree whose nodes hold a maximum of 4 values. We’ll assume that our B-tree is currently empty, so we’ll start by inserting integers into the tree.
Step 1: Let’s insert a 20:

Step 2: Next, we’ll insert a 5. Because B-trees always hold their values in order, we’ll need to move the 20 one slot to the right to make room for the 5. Here’s what this looks like when we complete this:
Steps 3 and 4: We’ll add the values 68 and 103 ...
Read now
Unlock full access