← All tools

Binary Search Tree Visualizer

Build and explore a binary search tree interactively. Insert numbers (one at a time or a batch), watch the tree take shape, then search for a key to highlight the path from the root, delete keys (with all three cases handled), and rebalance the tree into a minimal-height shape. Shows all four traversals — inorder, preorder, postorder, and level-order — plus size, height, min, max, and whether the tree is balanced. Everything runs locally in your browser.

Value
Batch insert

Tree

Stats

Traversals

A binary search tree (BST) keeps keys ordered: for every node, all keys in its left subtree are smaller and all keys in its right subtree are larger, so a search follows a single root-to-leaf path (O(log n) when balanced, O(n) when degenerate). Inorder traversal visits keys in sorted order; preorder (root, left, right) records the structure top-down; postorder (left, right, root) is used to delete subtrees; level-order (breadth-first) visits row by row. Deletion handles three cases — a leaf, a node with one child, and a node with two children (replaced by its inorder successor). Rebalance rebuilds the tree from the sorted inorder sequence with the median as root, yielding a minimal-height tree (a one-shot alternative to AVL/red-black rotations). Duplicates are ignored. Pairs with the Sorting Visualizer and Topological Sort tools. Everything runs locally — nothing leaves your browser.