Documentation
Binary Tree
Nodes with up to two children. Common traversals: Preorder (Root, Left, Right), Inorder (Left, Root, Right), Postorder (Left, Right, Root), Level-order (BFS).
Try it live: /visualize?model=binary
Binary Search Tree (BST)
For every node, keys in the left subtree < node.key < keys in the right subtree. Inorder traversal yields sorted order.
- Insert: walk comparisons, place at leaf.
- Search: follow comparisons to target.
- Delete: leaf, one child, two children (swap with inorder successor, then delete successor).
Try it live: /visualize?model=bst&op=insert&vals=7,3,5
Complexities
Operation | Average | Worst |
---|---|---|
BST Search/Insert/Delete | O(log n) | O(n) (degenerate) |
Traversals | O(n) |
Glossary
- Height: max edges from node to a leaf.
- Depth: edges from root to node.
- Level-order: breadth-first order.