3.4.1 · D4Trees

Exercises — Tree terminology — root, leaf, height, depth, degree, subtree

2,293 words10 min readBack to topic

The two reference trees for this page:

Figure — Tree terminology — root, leaf, height, depth, degree, subtree
Figure — Tree terminology — root, leaf, height, depth, degree, subtree

Level 1 — Recognition

Read the definition straight off the picture. No computation.

Recall Solution L1.1

WHAT we look for: root = the only node with no parent (the topmost). Leaf = a node with no children.

  • Root . It is the only node nobody points down to.
  • Leaves . Each has zero downward edges. Note is a leaf even though it sits at depth leaf means "no children", not "deepest".
Recall Solution L1.2

Children of = the nodes one edge below = . Siblings = nodes sharing the same parent. E.g. and (both children of ); or (all children of ).

Recall Solution L1.3

True. Internal node = "has at least one child". has child , so is internal (not a leaf).


Level 2 — Application

Now you must count edges or apply a formula.

Recall Solution L2.1

Depth = number of edges on the path from the root down to the node. Count edges, not nodes.

  • Path to : = 3 edges → depth .
  • Path to : = 1 edge → depth .
Recall Solution L2.2

Height = edges on the longest path from the node down to a leaf.

  • From : = 2 edges → height . Degree = number of children.
  • has children → degree .
Recall Solution L2.3

WHY the rule: every node except the root is joined to its parent by exactly one edge. That is one edge per non-root node.


Level 3 — Analysis

Combine several definitions or run the recursive height algorithm.

Recall Solution L3.1

WHAT we do: start from leaves (base case) and build upward, because a node's height depends on its children's heights.

  • Leaves: .
  • .
  • .
  • .
  • .

Height of the whole tree = height of the root . ✅

Recall Solution L3.2

Subtree rooted at = plus all its descendants = , with as its own local root. Degree of a (sub)tree = the max degree of any node in it. Here has children, and have . Max → degree .

Recall Solution L3.3

Ancestor = any node on the path from up to the root (excluding itself).

  • Ancestors of : . Descendant = any node below the given node.
  • Descendants of = everyone except = (all other nodes, since is the root).

Level 4 — Synthesis

Build or reason about a whole structure, using tree U.

Recall Solution L4.1

Bottom-up, leaf :

  • Leaves: .
  • .
  • .
  • .
  • .

Tree height . Subtree sizes: subtree() (all nodes), subtree() , subtree(). Excluding the root, the largest subtree is rooted at with nodes.

Recall Solution L4.2

With , : Tree U has ✅. WHY the slack: the bound assumes every level is completely full (). Tree U is not full — level 2 has only 3 of a possible 4 nodes and level 3 has only 1 of a possible 8 — so it holds far fewer than the max. The bound is a ceiling, not an exact count.

Recall Solution L4.3

Strategy: to minimise height with a child-cap of , pack each level as full as possible (each node grabs its children before we open a new level).

  • Level 0: node (root) → running total .
  • Level 1: nodes → total .
  • Level 2: up to nodes, but we only need more → total . We stop at level 2, so height . One valid shape:
        a          depth 0
       / \
      b   c        depth 1
     / \  /
    d  e f         depth 2

Any arrangement filling level 1 fully then partially filling level 2 works — height is optimal because nodes () is the most that fit in heights , and forces at least one more level.


Level 5 — Mastery

Prove small general facts. Answers are formulas/arguments, not single trees.

Recall Solution L5.1

Definitions used: leaf = degree ; internal = degree . Every node has a degree (a child-count) that is either or — never both, never neither. So each node lands in exactly one of the two buckets. A partition of the nodes into two disjoint groups sums to : No overlap, because "" and "" cannot hold simultaneously.

Recall Solution L5.2

Count edges two ways.

  1. From the parent side: each internal node contributes exactly downward edges, so total edges .
  2. From the child side: every node except the root has exactly one edge to its parent, so total edges .

Set them equal: Sanity check on tree U (which is not full, so this need not hold — good to see): it fails, confirming the "full" hypothesis is essential. A full example: root with two leaf children → ✅.

Recall Solution L5.3

Level-by-level bound. Put the root on level . A node on level has at most children, each on level . So:

  • level : at most node,
  • level : at most ,
  • level : at most (each level multiplies the previous max by ).

Height means the deepest level is . Summing all levels to gives a geometric series — chosen precisely because each term is the one before: Equality holds exactly when every level is completely full — i.e. a perfect -ary tree where every internal node has all children and every leaf sits on level .


Recall One-line self-test (hide, then recall)

Depth ::: edges up to the root; root . Height ::: edges down to the deepest leaf; leaf . Edges in an -node tree ::: . Recursive height ::: of children's heights. Full binary tree leaves vs internals ::: . Max nodes, height , degree ::: .

Connections

  • Binary Trees — L4/L5 use the degree- special case directly.
  • Recursion — the height algorithm and L5 proofs are recursive/inductive.
  • Balanced Trees (AVL, Red-Black) — the height bound in L5.3 is why balancing gives .
  • Tree Traversals — visiting by depth/level.
  • Graphs — the "count edges two ways" trick in L5.2 is a classic graph argument.

Solution map

tool

tool

L1 Recognition names

L2 Application count edges

L3 Analysis recursive height

L4 Synthesis build a tree

L5 Mastery prove a fact

count edges two ways

sum levels geometric