DevTools Logo

B-Tree & B+ Tree Index Visualizer

B-Tree & B+ Tree Index Visualizer

Insert, search and delete keys and watch splits, borrows, merges and root changes. Runs in your browser.

Runs in your browser
order 4
Try an example

Key

8 keys stored · height 2

Enter inserts. Stored keys: 5, 6, 7, 10, 12, 17, 20, 30

B-tree

invariants hold
Order m = 4 (max 3 keys). Non-root nodes keep 1 to 3 keys. An overflowing node splits at index 1 of its 4 keys. Keys are unique; duplicate inserts are ignored.
57 | 1017 | 20 | 306 | 12

Highlighted nodes show the latest search path.

Operation history

insert 17: Inserted 17
insert 7: Inserted 7
insert 30: Inserted 30. Split leaf 3 into 3 and 4; promoted 12
insert 12: Inserted 12
insert 6: Inserted 6. Split leaf 1 into 1 and 3; promoted 6
insert 5: Inserted 5
insert 20: Inserted 20
insert 10: Inserted 10

About

Insert, delete, and search numeric keys with a configurable maximum node size. Every split and search path is recorded locally; B+ tree values live in linked leaves.

Examples

Ordered inserts stay sorted

Input
insert 1..10 into createBTree(3), then inOrder(root)
Output
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Splits preserve order, so sequential inserts still traverse in sorted sequence.

B+ leaves form a chain

Input
insert 8 keys into createBTree(3, "bplus"), follow next from the leftmost leaf
Output
chained keys == inOrder(root), sorted

Leaf splits splice next pointers, so the linked leaves enumerate every value in order.

About this tool

B-Tree Index Visualizer models ordered indexes with createBTree(maxKeys = 3, variant = 'btree') plus insertBTree, searchBTree, deleteBTree, inOrder, and snapshotBTree. Variants are btree (keys promoted on split) and bplus (leaf splits copy the separator up and link leaves via next). Every operation appends a history entry with type, key, found, path, and message.

Splits are deterministic: a full root creates a new parent, full children split before descent, and B+ leaf splits report 'Split leaf' while internal splits report the promoted key. Search records lastSearchPath from root id down, inOrder always returns deduplicated sorted keys, and snapshotBTree deep-clones root, history, and paths.

Keys are finite numbers (non-finite coerces to 0), maxKeys floors at 2, duplicate inserts report 'Key already exists', and deletes report found true/false without rebalancing beyond collapsing an emptied root.

How to use this tool

  1. Create the tree

    Pick maxKeys and the btree or bplus variant — B+ is the one with linked leaves.

  2. Insert keys

    Add keys one by one; watch history for Split messages and confirm inOrder stays sorted.

  3. Search and read the path

    Search a key and check lastSearchPath — it starts at the root id and ends at the target node.

  4. Delete and snapshot

    Delete leaf keys, verify inOrder, and use snapshotBTree before mutations you want to compare.

Use cases

Teaching splits and promotion

Visualize when a full node splits, which key promotes, and how the root grows.

Contrasting B-tree vs B+ tree

Compare promoted-key internals against B+ duplicated separators with linked leaves.

Tracing index lookups

Follow search paths from the root to see how few nodes an ordered lookup visits.

Common mistakes

Mistake:Assuming deletes rebalance the tree.

Fix:Delete only removes the key (swapping a B-tree predecessor when needed) and collapses an emptied root — it never redistributes or merges siblings.

Mistake:Expecting duplicate inserts to add a second copy.

Fix:Existing keys are rejected with 'Key already exists' and inOrder deduplicates, so counts never double.

Frequently asked questions

What does this tool do?

It models ordered indexes with createBTree(maxKeys, variant), insertBTree, searchBTree, deleteBTree, inOrder, and snapshotBTree — btree promotes split keys while bplus copies separators up and links leaves via next, with every op logged to history.

How do I read the search path?

lastSearchPath lists node ids from the root down; the first entry is always the root id, and the history entry for the search carries the same path.

Is my key data uploaded or stored?

No. Node splits, searches, deletes, and snapshots run 100% client-side.

Do deletes rebalance, and do duplicates stack?

Neither: deletes only remove the key (plus a root collapse when emptied) without merging siblings, and duplicate inserts are rejected with Key already exists while inOrder deduplicates.

References & standards