🌳 Binary Search Tree

A BST keeps one rule at every node: everything on the left is smaller, everything on the right is larger. That's what makes search, insert and delete O(height). Insert values and watch each one walk down by comparison β€” then run the four traversals and see the order they visit.

β˜… Star on GitHub
Empty tree. Insert a value to begin.
nodes
0
height
0
min
β€”
max
β€”
Try this: hit random tree, then run in-order β€” it always comes out sorted ascending, because "left, node, right" visits smaller values first (that's a one-line way to sort a BST). Now search for a value and watch it compare at each node and turn left or right, never scanning the whole tree. Then delete a node with two children β€” it's replaced by its in-order successor (the smallest value in its right subtree), the one swap that keeps the ordering intact. Insert values in sorted order (1, 2, 3, …) and the tree degenerates into a linked list β€” height = n β€” which is why balanced trees (AVL, red-black) exist.