What is a Binary Tree / BST?
Binary trees and BSTs, told as a story about a shelf map where every fork picks left or right to find a part.
With jumbled numbers, you open boxes one by one down the line.Worst case, you open every single box.
Even sorted in a neat row, following it from the front is still one box at a time.Follow the row from the front, and it's still one box at a time.
Binary tree search = a map that halves the candidates at every fork.Looking for 19: smaller than 31, go left → bigger than 12, go right → 19.
If the number you want is smaller than the fork's, go left; if bigger, go right.Every fork follows this rule: smaller left, bigger right.
A tree leaning one way makes the search as slow as a plain line again.That's why algorithms exist just to rebalance the tree.
Binary tree = a map that branches only left or right at every fork. A binary search tree (BST) adds one rule: smaller values go left, bigger values go right.
A binary tree is a tree structure where each node has at most two children (left and right). A binary search tree (BST) adds the rule that every value in the left subtree is less than the node, and every value in the right subtree is greater — giving average O(log n) search, insert, and delete. But if insertions skew one way, the tree degenerates into a line, with worst-case O(n); self-balancing trees like AVL or red-black trees exist to prevent that.
When grown-ups say it
- Node
- One fork, a square with a part number. Has at most two branches, left and right.
- BST Rule
- Smaller to the left, bigger to the right. Holds true at every single fork.
- Balance
- Keeping the tree from leaning to one side. Lean too far, and search slows back to a line.
- Stack/Queue (linear structures)
- Rules for a single line — stacking or queuing. The branch-free, single-line structures live here. → boxes get stacked, cars get queued
- Time Complexity
- The ruler for how time grows as data grows. A balanced tree is O(log n); a plain line is O(n). → how much slower as cars pile up
- Cache Memory
- A small toolbox holding only the frequent tools. A different way to be fast: keep frequent items close. → the toolbox kept right beside you
- Virtual Memory/Page Table
- The table matching virtual slots to real ones. Page tables themselves are often implemented as tree structures. → the fake map that makes the whole warehouse yours
- CPU Scheduling
- The rule that sets the car order on the board. Some schedulers use tree structures internally too. → who gets the lift first