B+ Tree Visualizer

Insert a key to split a leaf, watch a separator enter the parent, then follow the leaf links through a range scan.

Tree structure

Order 4 · Up to 4 children per index node and 3 keys per leaf

Root · leaf102030+ 25
Starting tree

This leaf is full. Insert 25 to see where a fourth key can go.

How to use the B+ tree visualizer

Select First leaf split in the Example menu. The box containing [10, 20, 30] is both the root and the only leaf. In this visualizer, order means the maximum number of children of an internal node. An order-4 node can have four child pointers separated by three keys. Each leaf in this example has space for three distinct integer keys.

Click an operation to play it automatically, or use the right arrow (Next step) to advance one frame at a time. The left arrow takes you back one frame. Replay repeats the last operation. The reset arrow beside the example menu restores that example’s starting tree. Select any illustration below to open the full-size animation.

Insert 25 and watch a separator appear

  1. In Insert mode, click Insert 25. At step 2 the leaf briefly holds [10, 20, 25, 30]. The keys are in order, but the page only has room for three.
  2. At step 3 the leaf splits into [10, 20] on the left and [25, 30] on the right. An arrow links the two leaves so a scan can continue from one page to the next.
  3. At step 4 watch 25, the smallest key in the right leaf. A copy moves up to a new root. The 25 in the root directs searches. The 25 in the leaf identifies a data entry. In a database index, a leaf entry can hold a record or a reference to one.

A full leaf splits when 25 is inserted. A copy of 25 travels from the right leaf into the new root.

Find 25, then try a missing key

Keep the tree you just split. Switch to Find, enter 25 in Integer key, and click Find 25. The search continues past the 25 in the root. Keys smaller than a separator belong on its left, and keys equal to or greater than it belong on its right. Equality takes you to the right leaf, [25, 30], where the entry is found.

Now try 24. The root sends you left to [10, 20]. This is the only leaf where 24 could belong, so the search can end as soon as it checks that page. To see how the visualizer handles duplicates, switch back to Insert and try 25 again. The existing entry stays in place.

Choose Scan across leaves. The example loads the two-leaf tree and fills in both bounds. Click Scan range. Follow the downward pointer first, then the horizontal arrow.

  1. Locate the lower bound. Since 18 is smaller than the root separator 25, start in the left leaf. Skip 10 and collect 20. The lower bound itself need not be present.
  2. Continue along the leaf chain. Follow the link to the right leaf and collect 25. The scan only descends from the root once.
  3. Stop when the next key is too large. The next key is 30, which exceeds 28. All later keys are larger. Matching keys now reads 20, 25.

The range scan collects 20 on the left, follows a leaf link to collect 25, and stops at 30.

Change From and Through on the same tree to check two boundary cases.

Range Matching keys What to watch
25 through 25 25 Equality sends the scan directly to the right leaf. Both endpoints are inclusive.
21 through 24 ∅ Every key in the left leaf is too small. The first key in the right leaf, 25, is already too large.

Insert 100 and follow a split up to the root

Select Split up to the root. The root already holds [30, 50, 70] and points to four children. Its rightmost leaf, [70, 80, 90], is also full. Click Insert 100 and watch the two levels in turn.

  • At the leaf, the keys split into [70, 80] and [90, 100]. The right leaf’s smallest key, 90, is copied into its parent. The old root now holds [30, 50, 70, 90] and has five child pointers.
  • At the old root, pause at step 6 to see the overflow. At step 7 the middle separator 70 moves up to a new root. The two internal nodes below it retain [30, 50] and [90]. The data entry for 70 is still in its leaf.

Inserting 100 splits the rightmost leaf. The separator 90 is copied up, then 70 moves out of the old root to form a new root.

A lookup for 100 now follows root 70 → internal node 90 → leaf [90, 100]. The tree has grown from two levels to three, and every leaf is still at the same depth. Use Previous step to compare the copy of 90 at step 5 with the promotion of 70 at step 7.

Build a tree and check your prediction

Choose Start with an empty tree. Insert 8, 4, 12, 6, letting each operation finish before starting the next. Before inserting 6, predict the first root separator. The finished tree should have 8 in the root, [4, 6] in the left leaf and [8, 12] in the right leaf. Switch to Range scan and scan from 6 through 12. You should get 6, 8, 12.

To see which leaf splits next, switch back to Insert and click Insert random key. The visualizer picks an integer that is missing from the tree, shows it in the input, and starts the insertion. Click again after the animation finishes to grow the tree. Try it in the visualizer

Explore the AVL tree rotation visualizer and the skip list visualizer for other ways to organize an ordered index. For more on how leaf pages relate to records, see the UC Berkeley CS 186 notes on B+ trees.