3.4.6 · D5Trees
Question bank — BST — worst case O(n) — motivation for balancing

True or false — justify
Every item is stated as a claim. The answer says true or false AND why — never a bare verdict.
A BST guarantees search.
False. A plain BST only guarantees , and can reach on sorted input; only self-balancing BSTs force .
The cost of a BST search depends on how many keys you stored.
False. It depends on the tree's height , not the count directly — the same keys can give or depending on shape.
Inserting keys in decreasing order also produces a degenerate stick.
True. Each key is smaller than everything so far, so it always goes left — a left-leaning stick with , just as sorted-increasing gives a right-leaning one.
A tree with height contains no nodes.
False. Height counts edges; a single lone node has height (zero edges on its longest path). The empty tree is the one with height .
If two BSTs store the same keys, they have the same height.
False. Shape depends on insertion order; identical key sets can yield or , differing by a factor of .
The height of a BST can exceed .
False. With nodes and one per level you already use levels to ; more height would need nodes, which we don't have.
A perfectly balanced BST on nodes has height exactly .
True. Packing each level full lets level hold nodes, so nodes fit in the fewest levels, giving exactly — the shortest possible tree.
A degenerate BST is strictly worse than a linked list.
False. It is asymptotically the same ( search); it's arguably worse only by a constant (extra unused child pointers), not in Big-O.
Balancing changes the keys stored in the tree.
False. Balancing (rotations in AVL Trees — rotations and balance factor) only rearranges structure while preserving the BST ordering property; the set of keys is untouched.
Spot the error
Each item quotes flawed reasoning. The answer names the exact broken step.
"Search halves the remaining tree each step, so it's always ."
The "halving" only happens when both subtrees are roughly equal — i.e. when the tree is balanced. In a stick, one subtree is empty, so you discard one node, not half.
"There are nodes on level , so a BST on nodes has height ."
Level holds at most nodes; it is not forced to be full. The result is only the best case, not a guarantee.
"Height = number of nodes on the longest root-to-leaf path."
Height counts edges, which is one less than the node count on that path. This off-by-one doesn't change Big-O but breaks base cases (single node has height , not ).
"Random inserts give expected height, so BSTs are safe in practice."
You cannot guarantee your input is random. Sorted or adversarial input (logs, auto-increment IDs) is common and forces — expectation is not a worst-case guarantee.
"To find the max nodes at height , sum over the levels: it's ."
"A BST with still throws away half the keys per comparison."
In a stick every node has one child, so each comparison eliminates only the current node — one key, not half. That's exactly why it collapses to .
"Since inserts and searches both cost , and deletes rebuild the tree, deletes must cost ."
Deletes also just walk one root-to-node path (plus a local fixup), so they are too — no full rebuild.
Why questions
Each answer gives the mechanism, not just a label.
Why does sorted insertion produce the worst case?
Every new key is larger (or smaller) than all previous ones, so it always turns the same direction and never branches — the tree stretches into a one-node-per-level stick with .
Why is BST cost tied to height rather than to ?
Every operation follows a single path from root down to one node, and the longest such path has length ; the total node count only matters through how it shapes .
Why can level hold at most nodes?
Each node has at most children, so the node count can at most double each level down: .
Why does a plain BST fail to guarantee ?
Its shape is decided by the (uncontrollable) insertion order, and one bad order collapses it to a stick; without automatic restructuring nothing prevents that.
Why do self-balancing trees restore the guarantee?
On each insert/delete they detect leaning and perform rotations that pull height back toward , so holds regardless of input order (see Red-Black Trees).
Why is the geometric series central to the best case?
It counts the maximum nodes that fit in full levels; inverting it gives the smallest height that can hold nodes, namely .
Why is a degenerate BST as slow as a linked list for search?
With one child per node there is no branching to exploit, so searching means walking every node in order — the exact behaviour of a linked list, .
Why does binary search on a sorted array stay while a BST on sorted input does not?
Binary search on an array always jumps to the true middle index; a BST's "middle" is whatever the root happens to be, and a stick's root is an endpoint, so no halving occurs.
Edge cases
Boundary and degenerate inputs the topic invites.
What is the height of an empty BST?
By our fixed convention, (no nodes, no path); the point is search costs work — there's nothing to walk.
What is the height of a BST with exactly one node?
, since the longest root-to-leaf path has zero edges; both best-case and worst-case agree here.
For , are the best and worst cases the same?
Yes. Two nodes can only form a root with one child, so always; and coincide — shape can't vary yet.
At what does the best-vs-worst height gap first appear?
At : best case (root with two children) versus worst case (a stick) — the first size where insertion order truly matters.
If you insert the same key twice into a BST, what happens to height analysis?
Duplicates are typically rejected or sent consistently one direction; either way the bounds still hold for the distinct keys actually stored.
For a stick of nodes, how many comparisons does a worst-case search make?
Up to comparisons (visiting every node), matching the nodes on the path — this is the trap in action.
Does a perfectly balanced tree require to be exactly ?
No. For other the last level is only partly filled, giving ; full "perfect" trees occur exactly when .
Recall One-line summary of every trap
Cost , and ; sorted input hits the top, balancing forces the bottom, height counts edges not nodes, and the empty tree has .
Connections
- 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