Data Structures / Visual Lab

Same keys. Different depth.

A binary search tree stores keys in a strict left/right order, but an ordinary BST does not rotate or rebalance itself. Insertion order changes the shape it creates.

Controlled comparison

Building the trees…

A

Tree A

First insertion becomes the root

Root — 0 unique

Drag to orbit · scroll to zoom
Avg. depth —
Max depth —
Height —
Local BF range —
Depth is measured in edges from the root. —
B

Tree B

Only the insertion order changes

Root — 0 unique

Drag to orbit · scroll to zoom
Avg. depth —
Max depth —
Height —
Local BF range —
BF = left subtree height − right subtree height. —

1 · Insert by comparison

The first key is the root. Each later key walks left when it is smaller, right when it is larger, and occupies the first empty position on that path. Duplicates are ignored in this ordinary BST.

2 · The first choice cascades

A poor early root can split the remaining keys into one long side. A later key then travels through every earlier ancestor before finding its position, increasing the tree's path lengths.

3 · No automatic balancing

These are plain BSTs: there are no AVL or Red-Black rotations. The shallow tree is shallow because of its insertion order, not because the data structure repaired itself.