MCS-208 · Unit 6

Trees

Section 2 of 8

Block 2 · Unit 6Trees11 min · Section 2 of 8

6.2Counting in m-ary Trees

Covers IGNOU MCS-208 §6.2

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−1n - 1 edges.

Nodes per level

An m-ary tree is a tree in which every node has at most mm children (m=2m = 2: binary tree). At level 1 there is at most 1 node, at level 2 at most mm, at level 3 at most m2m^2, so

level ℓ has at most mℓ−1 nodes,\text{level } \ell \text{ has at most } m^{\ell - 1} \text{ nodes},

and a tree of height hh (levels 11 to hh) has at most

1+m+m2+⋯+mh−1=mh−1m−1 nodes.1 + m + m^2 + \dots + m^{h-1} = \frac{m^h - 1}{m - 1} \text{ nodes.}

For m=2m = 2 this is 2h−12^h - 1.

Full m-ary trees

Let nn = number of nodes, ii = number of internal nodes and ll = number of leaves. Each internal node has mm children, and every node except the root is a child, so

n=m i+1,n=i+l.n = m\,i + 1, \qquad n = i + l.

From these two equations any one of nn, ii, ll gives the other two:

KnownFormulas
iin=mi+1n = mi + 1,   l=(m−1) i+1\; l = (m - 1)\,i + 1
lli=l−1m−1i = \dfrac{l - 1}{m - 1},   n=ml−1m−1\; n = \dfrac{ml - 1}{m - 1}
nni=n−1mi = \dfrac{n - 1}{m},   l=(m−1) n+1m\; l = \dfrac{(m - 1)\,n + 1}{m}

Key takeaways

  • A tree with nn nodes has n−1n - 1 edges.
  • An m-ary tree has at most mℓ−1m^{\ell - 1} nodes on level ℓ\ell and at most (mh−1)/(m−1)(m^h - 1)/(m - 1) nodes in hh levels.
  • Full m-ary tree: n=mi+1n = mi + 1, n=i+ln = i + l, so l=(m−1)i+1l = (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 1 · multiple choice

A tree has 60 vertices. How many edges does it have?

Show answer

Answer: B. 59

Every vertex except the root has exactly one edge to its parent: 60−1=5960 - 1 = 59.

Question 2 · multiple choice

What is the maximum number of nodes in a 3-ary tree of height 3 (three levels)?

Show answer

Answer: C. 13

1+3+9=13=(33−1)/(3−1)1 + 3 + 9 = 13 = (3^3 - 1)/(3 - 1). The study material’s formula dh−1d^h - 1 would give 26, which is impossible.

Question 3 · multiple choice

A full binary tree (every internal node has 2 children) has 50 internal nodes. How many leaves does it have?

Show answer

Answer: D. 51

l=(m−1)i+1=1⋅50+1=51l = (m - 1)i + 1 = 1 \cdot 50 + 1 = 51. In a full binary tree there is always one more leaf than internal nodes.

Question 4 · multiple choice

A full 5-ary tree has 41 vertices. How many internal vertices does it have?

Show answer

Answer: A. 8

i=(n−1)/m=40/5=8i = (n - 1)/m = 40/5 = 8, and then l=41−8=33l = 41 - 8 = 33 leaves. 33 is the number of leaves, not internal vertices.

Question 5 · multiple choice

Which property is required for l=(m−1)i+1l = (m - 1)i + 1 to hold?

Show answer

Answer: C. Every internal node has exactly mm children.

The proof uses only “each internal node has mm children”. Leaves on the same level is a stronger condition (a perfect tree), not a requirement.

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+1n = mi + 1 and n=i+ln = i + l with m=4m = 4, l=100l = 100. Then mi+1=i+lmi + 1 = i + l, so (m−1)i=l−1(m - 1)i = l - 1 and i=993=33i = \dfrac{99}{3} = 33. Total n=4⋅33+1=133n = 4 \cdot 33 + 1 = 133. Check: i+l=33+100=133i + l = 33 + 100 = 133. ✓

↑ ↓ move↵ openTab switch type