Visual walkthrough — BST — worst case O(n) — motivation for balancing
Every symbol below is drawn before it is used. If a word looks scary, wait one line — the picture is coming.
Step 1 — What is a tree, and what is a "path"?
WHAT. A tree is a set of circles called nodes, each holding a number (a key), joined by lines called edges. One special node at the very top is the root. From the root, edges go down to children. A node with no children is a leaf.
WHY. Before we can talk about how tall a tree is, we must agree on what "top", "down", and "a path down" mean. A BST operation (search / insert / delete) never wanders sideways — it starts at the root and walks straight down, one edge at a time, until it stops. So the only thing that can make it slow is a long downward path.
PICTURE. The red arrows trace one root-to-leaf path. Count the edges it crosses — that count is what we will call the path's length.

Here, in , the letter just means "how many downward steps in the worst possible walk."
Step 2 — Why does cost equal height?
WHAT. To search for a key, you stand at the root, compare, and move to exactly one child (left if you want something smaller, right if bigger — that is the BST property). You repeat until you find it or fall off the bottom.
WHY. Because you take one step per level, the number of comparisons is at most the number of levels you can descend — which is the height plus one. Using Big-O notation (which throws away the "+1" and constant factors), the cost is:
The symbol answers the question "how does the work grow as the tree grows?" — it ignores small stuff and keeps only the shape of the growth. We use it (not exact counts) because we care about scaling, not whether it's or .
PICTURE. Follow the blue walk: at every circled node you make one decision and drop one level. The number of blue steps can never beat .

Recall Why not count sideways moves?
A BST search never moves sideways — it goes strictly down. So the only thing that limits its speed is how deep the tree can go. ::: Because each comparison sends you to exactly one child (down one level), the total work is bounded by the number of levels, i.e. the height.
So the entire question "is a BST fast?" collapses to "how big can get?" Steps 3–7 answer that from both ends.
Step 3 — The same keys, two shapes (the whole mystery in one figure)
WHAT. Take the five keys . Insert them in sorted order, then insert them in a mixed order. Watch two completely different trees appear.
WHY. Insertion order decides where each new key lands. When a key is larger than the current node, it turns right; when smaller, left. Sorted keys are always larger than everything before them, so they always turn right — the tree never branches. Mixed keys turn both ways, so the tree spreads out.
PICTURE. Left = the "stick" (sorted inserts). Right = the "bush" (mixed inserts). Same numbers, wildly different heights. Count the edges on the longest path in each.

Step 4 — The worst case: derive
WHAT. We now find the tallest tree possible for nodes. Call it — "the biggest height any legal tree on nodes can have."
WHY. To make a tree as tall as possible, give every node exactly one child. Then each new node adds a whole new level instead of filling an existing one. This is exactly what sorted insertion produces (see a linked list — same shape!).
PICTURE. Watch the stick grow: node at level , level , ..., level . Each of the nodes sits alone on its own level.

Now count the levels. With one node per level and nodes, the levels are numbered . The longest path runs from level to level , crossing:
Here is the node count and counts the gaps between the stacked nodes.
Step 5 — The best case: why each level holds at most nodes
WHAT. To make a tree as short as possible, we must cram the most nodes into the fewest levels. First we ask: how many nodes can level hold?
WHY. Each node has at most 2 children (that's what "binary" means). So going down one level, the node count can at most double. Level holds node (the root); level holds at most ; level at most ; and in general:
The exponent is the level number, and is "each parent makes up to two children."
PICTURE. Level : . Level : . Level : . Level : . Watch the width double each row.

Step 6 — Add up the full levels (a geometric series)
WHAT. Suppose the tree has height and every level is packed full. Total nodes is the sum of all levels' capacities:
WHY. This is a geometric series — a sum where each term is the previous one times a fixed ratio (here the ratio is ). We use the closed form of this series so we don't have to add term by term:
Read it as: "one more than the last term, doubled, minus one." The is double the biggest level, and the trims the overshoot.
PICTURE. The staircase blocks (widths ) stack up to just one short of the next power of two — the pale-yellow bar of height .

Now solve for — we invert the relationship because we want height in terms of the node count :
We apply (the "how many times must I double to reach this?" function) precisely because it undoes the doubling that built the levels. The smallest legal height is therefore about .
Step 7 — Edge & degenerate cases (never leave a gap)
WHAT / WHY / PICTURE — the corners the formulas must still survive:

The figure shows the tiny cases side by side: notice how for the "fast" and "slow" bounds are the same tree. The gap between and only yawns open once is large — which is exactly when it matters.
The one-picture summary
WHAT. One graph. Horizontal axis = number of nodes . Vertical axis = height . Two curves: the ceiling (the stick) and the floor (the bush). Every legal BST lives in the shaded band between them.
WHY. This single frame is the parent note: cost , and is trapped between and . A plain BST can sit anywhere in the band — including on the deadly straight line up top. AVL and Red-Black trees are the machinery that pins you to the bottom curve forever.

Recall Feynman: tell the whole walkthrough to a 12-year-old
A tree is dots joined by lines, with a boss dot on top. When you look for a number, you start at the boss and take one step down each time — smaller goes left, bigger goes right — so the number of steps is just how deep the tree goes. Now here's the trick: if you feed the tree numbers already in order (1, 2, 3, 4, 5), each new one is always bigger, so it always goes right, and the tree grows into a long ladder — you'd have to climb every rung. That's the slow case, and its depth is (one less than the number of dots). But if you feed the numbers mixed up, the tree fills out sideways: row 1 has 1 dot, row 2 has 2, row 3 has 4 — doubling each time. Doubling means the depth to hold dots is only about (how many times you double 1 to reach ). So every tree's depth is squished between "about " (fast, bushy) and "" (slow, stick). Balancing trees are just robots that keep shoving your tree down to the fast, bushy bottom no matter what order you hand them.
Connections
- BST — worst case O(n) — motivation for balancing (index 3.4.6)
- Binary Search Tree — definition and property
- Tree height and depth
- Binary Search — divide and conquer
- AVL Trees — rotations and balance factor
- Red-Black Trees
- Linked List — O(n) search
- Big-O notation
- Geometric series