Worked examples — Tree terminology — root, leaf, height, depth, degree, subtree
Two symbols we will lean on — defined before use
Before the examples, we pin down the two tools that keep reappearing, so no symbol is ever used on faith.
The scenario matrix
Every tree question is really one of these shapes or edge cases. The examples below are tagged with the cell(s) they cover.
| Cell | The scenario | Why it is tricky |
|---|---|---|
| C1 | Normal bushy tree (multiple children per node) | The baseline — measure depth/height/degree cleanly |
| C2 | Leaf sitting above the bottom level | Breaks the "leaf = deepest" instinct |
| C3 | Single-node tree (root is a leaf) | Degenerate: is the root a leaf? height? depth? |
| C4 | Empty tree () | The ultimate degenerate — height convention flips |
| C5 | A "stick" / path tree (every node has 1 child) | Height is maximal for its node count |
| C6 | Perfectly balanced tree | Height is minimal — the geometric-series bound is tight |
| C7 | Recursive height computation on an asymmetric tree | Must pick the tallest child, not the first |
| C8 | Subtree extraction + re-measuring inside it | Depth resets to 0 inside the subtree |
| C9 | Real-world word problem (file system) | Translate English → tree vocabulary |
| C10 | Exam twist: given constraints, deduce a hidden number | Use edges / geometric bound backwards |
We now cover all ten across the worked examples. Each example names its cell(s).
Example 1 — Baseline bushy tree (C1, C2)

- Root =
A. Why this step? Root is the only node with no parent (parent arrow pointing into it). Look at the figure — every node has an incoming edge from above exceptA. - Leaves =
{E, F, C, H}. Why? A leaf is defined only by "no children" — no edges leave it going downward. In the figureChas nothing below it, so it is a leaf even though it sits at depth 1 (this is cell C2). Do not tie "leaf" to "bottom row". - Degree of the tree =
3. Why? Degree of a node = its number of children.Ahas 3 children (B, C, D), and no node has more. The tree's degree is the maximum node degree . - Depth of
F=2. Why? Depth = edges on the path root → node. PathA→B→Fhas 2 edges. Count the edges (arrows), not the nodes. - Height of
B=1. Why? Height = edges on the longest downward path from the node to a leaf. FromBwe can goB→EorB→F, both 1 edge. So height . - Height of the tree =
3. Why? Height of the tree = height of the root = longest root-to-leaf path.A→D→G→His 3 edges — the longest such path.
Verify: Node count (A,B,C,D,E,F,G,H) ⇒ a tree must have edges. Count the arrows in the figure: A-B, A-C, A-D, B-E, B-F, D-G, G-H . ✅ Consistent, so we drew a valid tree.
Example 2 — Single-node tree (C3, degenerate)

- Root =
R. Why? It has no parent — it satisfies the root definition trivially. Ris also a leaf. Why? A leaf is "no children," andRhas zero children. Yes — the same node is simultaneously root and leaf. There is no rule forbidding it; the two definitions look in opposite directions and both happen to be satisfied.- Degree of the tree =
0. Why?Rhas 0 children, and it is the only node, so the max degree is 0. - Depth of
R=0. Why? Zero edges from the root to itself. - Height of
R=0. Why? Zero edges fromRdown to a leaf — andRis the leaf, so the longest downward path is length 0. - Height of the tree =
0. Why? It equals the height of the root, which is 0.
Verify: ⇒ edges . The picture has zero edges. ✅ And depth height of tree, matching "height of tree = max depth."
Example 3 — Empty tree (C4, the ultimate edge case)
- There is no root, no leaf, nothing to measure a path from. Why care? Recursive code hits this case:
height(null)must return something so1 + max(children)still works for a node with one missing child. - Convention: height of the empty tree . Why ? Take the recursive rule (the operator we defined at the top). For a single-node tree we want .
Rhas no children, so we treat "the tallest child" as an empty tree of height , giving . So empty is exactly the value that makes the leaf formula fall out automatically.
Verify: Plug into the recursion: ✅ We recover leaf height 0, so is the self-consistent choice.
Example 4 — The "stick" tree: maximum height (C5)

- Height of the tree =
3. Why? Longest root-to-leaf pathP→Q→S→Thas 3 edges. - Depth of
T=3. Why? Same path measured downward from root; here height and this deepest depth coincide only because it is the deepest node. - Degree of the tree =
1. Why? Every node has at most one child. - Tallest possible for ? Why? Height is the number of edges on a root-to-leaf path. With nodes you have edges total; a stick puts all of them on one single path, so height , the absolute maximum. You cannot make a 4-node tree taller than 3.
Verify: edges ; the stick uses all 3 on one path, so . ✅ Maximum confirmed.
Example 5 — Perfectly balanced tree: minimum height + geometric bound (C6)

- Count nodes: . Why? Level 0 has 1, level 1 has 2, level 2 has 4; .
- Apply the bound (the one we derived in "Two symbols we will lean on") with . Why this tool and not just counting? Counting works when you can see the tree; the formula answers "what is the most a tree of this shape could hold?" — needed when you only know and . Here is the child-cap .
- The full tree hits the maximum (). Why? "Perfectly balanced / full" means every level is completely packed, so it is the densest possible tree — equality holds.
- Minimal height for ? Why? Height is minimized by making each level as wide as possible. With degree 2 the widest a 7-node tree can be still needs 3 levels (heights ), because . So height 2 is the smallest achievable — you cannot fit 7 nodes into height 1 (that holds at most ).
Verify: height-1 bound , so height 1 is impossible; height-2 bound , so height 2 is achievable and minimal. ✅ This is the shape Balanced Trees (AVL, Red-Black) chases to keep height .
Example 6 — Recursive height on an asymmetric tree (C7)

- Leaves first: . Why? No children ⇒ base case, height 0.
- . Why?
Y's only childWhas height 0. - . Why? Same base-plus-one step.
- . Why?
Z's childMhas height 1. - . Why? The operator (defined at the top) keeps the biggest child height, so the longest path leaves through the tallest child
Z. If you naively took the first childXyou would get 1 — wrong. Themaxis the whole point.
Verify: Longest root-to-leaf path is
R→Z→M→Nedges. ✅ Matches .
Example 7 — Subtree: depth resets inside it (C8)

- Subtree . Why? A subtree is a node plus all its descendants.
Z's descendants areM(child) andN(grandchild). - Depth of
Ninside the subtree =2. Why? Inside the subtree,Zbecomes the local root with depth 0. PathZ→M→Nhas 2 edges, soNis at depth 2 relative to Z. - Depth of
Nin the original tree =3. Why? From the global rootR: pathR→Z→M→Nhas 3 edges. - They differ by exactly 1. Why? The subtree view drops the single edge
R→Z. In general, depth-in-subtree depth-in-original depth-of-subtree-root. Here . ✅
Verify: depth of subtree root
Zin original (pathR→Z). Then global depth ofNthat local depth. ✅ Depth is relative to whichever root you declare.
Example 8 — Word problem: a file system (C9)

- Root =
/home. Why? It is the topmost container with no parent folder in this problem. - Leaves =
{cv.pdf, a.jpg, b.jpg}. Why? Files contain nothing below them ⇒ no children ⇒ leaves. - Degree of the tree =
2. Why?/homehas 2 children (docs, pics) andpicshas 2 children (a.jpg, b.jpg). Max node degree . - Depth of
b.jpg=2. Why? Path/home → pics → b.jpghas 2 edges. - Height of the tree =
2. Why? Longest root-to-leaf path, e.g./home → pics → b.jpg, is 2 edges. - Subtree rooted at
pics={pics, a.jpg, b.jpg}. Why?picsplus its descendants — a little folder-tree by itself.
Verify: nodes (/home, docs, pics, cv.pdf, a.jpg, b.jpg) ⇒ edges . Count: home-docs, home-pics, docs-cv, pics-a, pics-b . ✅
Example 9 — Exam twist: deduce a hidden number (C10)
- (a) Use . Why this tool? Every tree obeys "edges " exactly (the parent note derived it: each non-root node contributes one parent-edge). Since it is an identity, knowing one side pins the other. Invert: nodes.
- (b) Use the geometric max-nodes bound — the very formula we derived in "Two symbols we will lean on." Why this tool? We want the most nodes a bounded-degree, bounded-height tree can hold, and that is precisely the packed-every-level count that bound computes. Here the child-cap is and the height is : What each piece means: is "if every one of the levels were as wide as the child-cap allows"; subtracting and dividing by is just the geometric-series shortcut for .
- (b) Cross-check by adding the levels directly: level 0 holds , level 1 holds , level 2 holds ; total . ✅ Same answer, so the closed form and the hand-sum agree.
Verify: (a) edges ✅. (b) and ✅.
Example 10 — Limiting behaviour: stick vs balanced as grows (C5 vs C6 combined)
- Stick height . Why? All 6 edges lie on one path (Example 4's logic scaled to 7 nodes).
- Balanced height . Why? From Example 5, a full degree-2 tree with 7 nodes packs 3 levels ⇒ height 2. Formally, height .
- The gap is edges, and it widens as grows: stick height grows linearly () while balanced grows logarithmically (). Why care? Search cost in Binary Search Trees is proportional to height — this gap is the entire reason Balanced Trees (AVL, Red-Black) exist.
Verify: : stick ; balanced ; gap . ✅
Recall Self-test: name the cell, then answer
A node with no children sitting at depth 1 — is it a leaf? ::: Yes (cell C2). Leaf = no children, at any depth. Height of a tree containing one node? ::: 0 (cell C3). Zero edges below the root. Height of the empty tree, and why? ::: (cell C4), so that gives leaf height 0. For fixed , which shape maximizes height? ::: The stick (cell C5); height . Max nodes in a degree-2 tree of height 3? ::: (cell C6/C10). Depth of a node inside a subtree vs whole tree? ::: Subtree depth global depth depth of subtree root (cell C8).
Connections
- Back to the parent terminology note
- Binary Trees — the degree- special case behind Examples 5, 10.
- Binary Search Trees — search cost height (Example 10's punchline).
- Balanced Trees (AVL, Red-Black) — engineer height down to .
- Tree Traversals — visiting the nodes we just measured.
- Recursion — the height formula in Examples 6–7 is pure recursion.
- Graphs — trees are acyclic connected graphs; degree conventions differ.