What the binary tree visualizer shows
Insert, delete, search, and traverse a binary search tree (BST) and watch each operation animate node by node. Values you add slot into place by the BST rule — smaller to the left, larger to the right — so the structure stays ordered, and the highlighting shows the exact path each operation walks from the root.
How a binary search tree works
Every node has at most two children, and the whole left subtree is smaller than the node while the whole right subtree is larger. That invariant lets search, insert, and delete skip half the remaining nodes at each step — O(log n) when the tree is balanced. The three depth-first traversals (in-order, pre-order, post-order) visit nodes in different useful orders; in-order, notably, returns the values sorted.
Why it matters
BSTs are the idea behind ordered maps and sets, database indexes, and countless interview questions. Seeing the pointers move makes the difference between "memorized the traversal" and actually understanding it. Ready to write one? Try the coding challenges or explore related structures in the graph visualizer.
Frequently asked questions
What's the difference between a binary tree and a binary search tree?
A binary tree just limits each node to two children. A BST adds the ordering rule (left < node < right) that makes fast search possible.
Why can a BST degrade to O(n)?
If you insert already-sorted values, the tree becomes a straight line (a linked list). Self-balancing variants like AVL or red-black trees prevent this.
Which traversal returns sorted order?
In-order traversal (left, node, right) visits a BST's values from smallest to largest.