Before you can understand why a BST can secretly become slow, you need a small toolbox of ideas. The parent note tosses around words like "node", "height", "O(n)", "log2n", and "geometric series" as if you already own them. Here we forge each one, in an order where every new idea only uses ideas already built.
Forget code for a second. A tree is just dots connected by lines, drawn top-down, where each dot has exactly one line coming from above it — except the very top dot, which has none.
Why the topic needs this: every cost in a BST is counted by walking along edges from the root downward. If you can't see nodes and edges clearly, you can't count that walk. Look at the picture: the root is the yellow dot at top, leaves are the green dots at the bottom, and every blue line is one edge.
We have a binary tree (each node has ≤2 children). A Binary Search Tree is that same shape plus one ordering rule that turns it into a fast lookup machine.
Why the topic needs this: everything in the parent note — the cost O(h), the sorted-insert disaster, the motivation for balancing — is a property of this structure. If the BST is not defined, none of it has meaning.
The BST rule uses two tiny symbols. Let's not assume them.
Why the topic needs this: the BST property ("left < node < right") is what makes searching directional — at each node you can decide "go left" or "go right" and throw away the other side. That throwing-away is where speed comes from. Equal keys would break the decision, which is why we fix a rule for them.
First, one word the doubling arguments secretly depend on.
Now the two most important quantities.
Why the topic needs this: the parent note's headline claim is "cost = O(h)". Every search/insert/delete walks one path from the root down, and h is the length of the longest such path — the worst walk you could be forced to take. So his the cost. Everything else on the page is about how big or small h can be.
The symbol h is just a nickname ("h for height") so we don't have to write "the height of the tree" every single time.
Why the topic needs this: we want to know how bad things get as the tree grows. Asking "how big can h get for a tree of n nodes?" only makes sense once n names the size. The two bounds in the parent note, ⌊log2n⌋≤h≤n−1, both compare h against this count n.
Before quoting the parent note's bound, let's build it.
Every non-empty level must contain at least one node (if a level were empty, nothing could hang below it, so the tree would already have ended). To reach height h, the tree needs levels 0,1,2,…,h — that is h+1 distinct levels, each holding at least one node. So:
n≥h+1 levels1+1+⋯+1=h+1.
Rearranging, h≤n−1. And this is achieved exactly when every level holds precisely one node — the "stick" tree, where each node has a single child.
Why the topic needs this: this n−1 is the O(n) villain of the whole topic. We just showed why no tree can be taller and which shape hits the limit.
Now the opposite question — how short can we make it? — needs one tool: the fact that levels can grow fast.
Why the topic needs this: the fact "level i holds at most 2i nodes" is the seed of the best-case height. Doubling grows so fast that even a short tree holds an enormous crowd.
To find the total capacity of a tree that is full up to height h, we add up every level's maximum.
Why the topic needs this: this formula tells us the maximum number of nodes a tree of height h can hold. Turning that around ("if I have n nodes, how few levels can I get away with?") produces the best-case height next.
The exponent asks: "2 to the power of what gives me n?" The answer to that question is the logarithm.
Now the best-case height. To hold all n nodes in the fewest levels, pack every level full. From the capacity formula, a tree of height h holds at most 2h+1−1 nodes, so we need:
n≤2h+1−1⇒n+1≤2h+1⇒h+1≥log2(n+1)⇒h≥log2(n+1)−1.
Since h must be a whole number, we round the requirement up: the smallest legal height is h=⌈log2(n+1)⌉−1, which equals the parent note's ⌊log2n⌋ for every n≥1 (both give: n=1→0, n=3→1, n=7→2, n=8→3). Either form names the same integer — the shortest a BST on n keys can be.
Why the topic needs this:log is the opposite tool to the exponent 2i. Since capacity grows like 2h, the height needed for n nodes shrinks like log2n. That log2n floor is the fast, "bushy" end of the height range — the target every balancing scheme aims for.
Finally, O(n), O(logn), O(h). These are not exact counts — they describe how the cost grows as the tree gets bigger, ignoring constants.
Why the topic needs this: Big-O is the ruler we measure heights with. Saying "cost is O(h), and h is between O(logn) and O(n)" is the parent note's whole thesis compressed into one sentence.
How to read this diagram: arrows mean "is needed to build". Start at the top boxes (raw ideas) and follow the arrows downward; each box only uses ideas from the boxes pointing into it. The bottom box, "Motivation for balancing", is the parent topic — everything flows into it.
Answer each before reading the parent note. If any stumps you, re-read its section above.
In a tree, what is the difference between a node and an edge?
A node is a dot holding a key; an edge is a line connecting a parent to a child.
What is the empty tree and what is its height?
A tree with zero nodes; by convention its height is −1 (so a single node comes out to height 0).
State the BST property in one sentence.
For every node, all keys in its left subtree are less than it and all keys in its right subtree are greater than it.
What is one valid rule for handling a duplicate (equal) key in a BST?
Forbid duplicates (insert of an existing key does nothing), or always send equals to one fixed side using ≥ — pick one and keep it.
What is a "level" in a tree?
The set of all nodes at the same depth (i edges below the root).
Does height count nodes or edges on the longest path?
Edges — a single node has height 0.
What does n stand for in this topic?
The number of nodes (keys) in the tree.
Why can't a tree of n nodes have height greater than n−1?
Each of the h+1 levels needs at least one node, so n≥h+1, giving h≤n−1.
What is the maximum number of nodes on level i, and why?
2i, because each node has at most 2 children, so capacity doubles each level.
What does 20+21+⋯+2h equal, and how do you derive it?
2h+1−1, via double-and-subtract: 2S−S=2h+1−1.
In plain words, what does log2n measure?
The exponent to raise 2 to, to get n — i.e. how many times you can halve n down to 1.
What do ⌊x⌋ and ⌈x⌉ do?
Round down / round up to the nearest whole number.
What does O(h) mean for a BST operation?
Its cost grows in proportion to the tree's height h (up to a constant).
Why does O(logn) beat O(n) dramatically for large n?
logn grows far slower — a million nodes is ~20 vs ~1,000,000 steps.
Recall The one-line summary of this whole page
Cost follows a path; a path's length is the height h; height depends on shape; shape depends on insertion order. Every symbol on this page (n, 2i, the geometric sum, log2n, floor/ceiling, Big-O) exists to pin down how small or large h can be — which is exactly the question the parent note answers.