Many exam questions ask how many nodes, leaves or edges a tree must have. A few simple counting facts answer all of them. This page derives those facts and solves the Check Your Progress questions.
Edges and nodes
Why: each edge joins a node to its parent, every node except the root has exactly one parent, so there is exactly one edge per non-root node: n−1 edges.
Nodes per level
An m-ary tree is a tree in which every node has at most m children (m=2: binary tree). At level 1 there is at most 1 node, at level 2 at most m, at level 3 at most m2, so
level ℓ has at most mℓ−1 nodes,
and a tree of height h (levels 1 to h) has at most
1+m+m2+⋯+mh−1=m−1mh−1 nodes.
For m=2 this is 2h−1.
Full m-ary trees
Let n = number of nodes, i = number of internal nodes and l = number of leaves. Each internal node has m children, and every node except the root is a child, so
n=mi+1,n=i+l.
From these two equations any one of n, i, l gives the other two:
Known
Formulas
i
n=mi+1, l=(m−1)i+1
l
i=m−1l−1, n=m−1ml−1
n
i=mn−1, l=m(m−1)n+1
Key takeaways
A tree with n nodes has n−1 edges.
An m-ary tree has at most mℓ−1 nodes on level ℓ and at most (mh−1)/(m−1) nodes in h levels.
Full m-ary tree: n=mi+1, n=i+l, so l=(m−1)i+1.
State which definition of “full” you use.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
A full 4-ary tree has 100 leaves. Find the number of internal vertices and the total number of vertices, and check your answer.
Show worked answer
Use n=mi+1 and n=i+l with m=4, l=100. Then mi+1=i+l, so (m−1)i=l−1 and i=399=33. Total n=4⋅33+1=133. Check: i+l=33+100=133. ✓
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-208/trees/counting-in-m-ary-trees/ to read this page.