BEGINNER · 10 MIN · FREE LESSON
Binary search tree
Explore binary search tree through a visual, step-by-step model.
Loading interactive lesson…
BEGINNER · 10 MIN · FREE LESSON
Explore binary search tree through a visual, step-by-step model.
Loading interactive lesson…
Enter an integer array. Duplicates use set semantics. BST also searches for and deletes the middle input key.
Start with an empty ordered tree.
BST ordering narrows one subtree per comparison; sorted input can create a chain.
Key comparisons and rotations, seed 42. Plotted sample sizes respect each lesson’s explicit input limits.
Keyboard: Space play/pause · ←/→ step · R restart · 1–5 speed. Reduced motion disables transitions.
A sorted family of signposts sends smaller keys left and larger keys right.
Order keys, then follow one branch. Inspect the changing tree, variables and operation counters before stepping backward to compare states.
Predict the branch, repair, visited node or range block. Try the single-element case, then use a larger seeded input.
O(h) per operation; h can reach n. The tree preserves strict left<root<right ordering and stores duplicate keys once. Random insertion often gives logarithmic height, while sorted insertion creates a chain.
The four language references show the underlying operations. The teaching scene uses bounded, validated inputs; standalone callers must respect the stated structure and index assumptions.
Use for ordered dynamic sets; choose a balanced variant when worst-case guarantees matter.
Two-child deletion must remove the successor from its old location.
Explain the invariant and one boundary case before checking your answers.
MAKE IT STICK
Progress saves on this device and merges with your account after sign-in.
0 / 5000 · Saved on this device; synced when signed in.