Exercises — Decision tree structure and terminology
Level 1 — Recognition
Recall Solution L1.1
The root node. It is the only node that holds the entire dataset, and the first split happens there. Why not "internal node"? Every root is an internal node in behaviour (it asks a question), but "root" is the special name for the one with no parent.
Recall Solution L1.2
- "branch" = the edge (the True/False outcome of a test).
- "leaf" = the node (the terminal endpoint that outputs a prediction). A branch is a line in the drawing; a leaf is a box.
Recall Solution L1.3
A class label (e.g. "cat"). Classification leaves output categories; only regression leaves output numbers.
Level 2 — Application
Recall Solution L2.1
Count each class: Dog , Cat , Bird (total ). The majority class is Dog, so . Choosing Dog is "wrong" for every sample that is not a Dog: that is misclassified. Why majority? Any label we pick is wrong for every sample of a different class; the biggest group leaves the fewest wrong. In symbols — where names one leaf, runs over the samples in that leaf, is sample 's true label, and ranges over the possible classes — this is i.e. "pick the class whose group of samples is largest." No tie here: Dog (3) is a clear single winner, so the tie-break rule never fires.
Recall Solution L2.2
The regression leaf predicts the mean: Why the mean? We minimize squared error . Setting the derivative to zero, , gives — the average.
Recall Solution L2.3
Follow each edge and AND the conditions. The False branch of Income ≤ 30k? means Income > 30k.
Why AND? A single path forces all its tests to hold at once, so the conditions chain with AND.
Recall Solution L2.4
Count: , — a tie. Either choice misclassifies the other 2 samples, so both give the same minimum training error of . Because we need a deterministic answer, we apply the tie-break rule (first class in order): predict ====. Why it doesn't matter for the loss: on a tie, no class is "more correct"; the tie-break only makes the model reproducible, it does not lower the error.
Level 3 — Analysis
Recall Solution L3.1
Depth = the number of edges on the longest root-to-leaf path. Why the max? Depth measures the worst-case number of questions the tree can ask before answering.

Recall Solution L3.2
The first test is a vertical line splitting the plane into left/right. The second test is a horizontal line applied only to the right piece, splitting it into bottom/top. Result: rectangular boxes. What "rectangular box" means here: in a 2-feature space each leaf is an ordinary rectangle whose sides are parallel to the axes. If there were features instead of 2, the same idea gives a -dimensional box (a "box" in directions) — the general name for that is a hyper-rectangle (just "rectangle" stretched to more than 2 dimensions; the "hyper-" prefix only means "in higher dimensions"). On this 2-D page you can safely picture plain rectangles. Why rectangles? Each test is perpendicular to one axis, so stacking them can only ever cut out axis-aligned boxes — never a diagonal. Predictions are constant inside each box, giving the staircase surface described in the parent's splitting section.

Recall Solution L3.3
Every split is of the form — a line perpendicular to one axis (horizontal or vertical), never slanted. To follow the diagonal, the tree must chain many small horizontal + vertical cuts, producing a staircase of tiny boxes that hugs the diagonal. The more splits (the deeper the tree), the finer the steps — but it is always piecewise-constant, never a true slanted line. See the red staircase tracking the green diagonal in the figure.
Level 4 — Synthesis
Recall Solution L4.1
Split on :
- True (): both labels are → leaf predicts ==== (majority is unanimous).
- False (): both labels are → leaf predicts ====. All four points correct; training error . Depth (one edge from root to each leaf). Why ? The threshold must land between the last () and the first (). Any with works; is the standard "" choice.
Recall Solution L4.2
With split , the True leaf now owns with labels — impure, because the noisy at sits between the two 's. To reach training error the tree must isolate that lone with extra cuts inside the True region, carving (labels ), (labels ), and (labels ). Together with the untouched False leaf (, all ), the tree ends with leaves and training error . Why dangerous? A future point near is probably really an ; the tree confidently says . That is overfitting — the deep tree fits a fluke, so test error rises. This is the low bias, high variance regime.
Recall Solution L4.3
The merged leaf owns , . Majority vote → predict ====. Predicting is wrong only for the single noisy at , so training error on this leaf sample. Why accept a training error? We trade one memorized fluke for a much simpler tree that generalizes better — the whole point of pruning. Predicting the majority treats the lone as the noise it almost certainly is.
Level 5 — Mastery
Recall Solution L5.1
(a) Classification. Counts: . Majority → predict ==== (clear single winner, no tie). Misclassified = all non- = . (b) Regression. Mean: SSE . Why these choices? Majority minimizes misclassifications; the mean minimizes SSE (derivative ). Both come straight from the parent's leaf-prediction derivation.
Recall Solution L5.2
Split first on (i.e. "?"):
- True (): rows 1–2 are both → pure leaf: No.
- False (): rows 3–4 are → not pure, split again on :
- True (): row 3 → leaf: No.
- False (): row 4 → leaf: Yes.
All 4 rows correct. Longest path Root → ( node) → leaf crosses 2 edges, so depth . Why split first? alone fully decides "No" (2 pure samples in one cut), so it's the cheapest question that purifies the most data — exactly the greedy logic CART follows using impurity.
Recall Solution L5.3
A single tree's staircase has high variance — small data changes reshuffle the boxes. Random Forests grow many de-correlated trees on bootstrapped samples and average their predictions; averaging more independent trees cancels out their random wiggles, smoothing the staircase and cutting variance (the variance side of the tradeoff) without much added bias. Gradient Boosted Trees instead grow shallow trees in sequence, each new tree predicting the residual errors of the ensemble so far — chipping away at bias step by step. Both keep the axis-aligned box structure of a single tree, but combine many of them to escape the overfit/underfit trap that a lone tree falls into.
Recall Self-test checklist
Root holds the whole dataset? ::: Yes — the only node with no parent. Classification leaf predicts…? ::: The majority class (minimizes misclassifications). On a tie between classes, what happens? ::: Both give the same error; a fixed tie-break (first class in order) is used for determinism. Regression leaf predicts…? ::: The mean (minimizes squared error). Depth counts nodes or edges? ::: Edges, on the longest root-to-leaf path. 0 training error is good or a warning? ::: A warning — likely overfitting. Random Forest fixes which error, how? ::: Variance, by averaging many de-correlated trees.
Connections
- Gini impurity and entropy — the score that picks each split you built above.
- CART algorithm — the greedy procedure automating L4/L5 tree construction.
- Overfitting and pruning — the fix for the L4.2 overfit tree.
- Random Forests · Gradient Boosted Trees — combining many trees (L5.3).
- Bias-variance tradeoff — the lens for depth, overfitting, and ensembles.