GATE / CS ARCHIVE

SIMILAR QUESTIONS / DATA STRUCTURES

Relate full k-ary leaves and branching

2 questions solved the same way, newest first. Back to Data Structures

How these are solved

Equate k times internal count with total vertices minus one; solve leaves=1+(k-1)*internal for the requested unknown. Symbolic leaf count versus numeric branching factor.

2 marks · MCQ
Report issue

Leaves and branching factor of a full n-ary tree

Tree Properties & Traversals

Question 43, GATE 2007: Here a complete n-ary tree means each node has exactly n children or none. It has I=10 internal nodes and L=41 leaves. Find n.
Options:
(A) 3
(B) 4
(C) 5
(D) 6
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Approach. Count child edges once from the parent side and once using the identity edges=vertices−1 for a tree. Equating the counts eliminates the shape of the tree.

2. Derivation and interpretation. Count the edges in two ways. Each of the I internal nodes contributes exactly n child edges, while a tree with I+L vertices has I+L−1 edges. Thus nI=I+L−1 and n=(10+41−1)/10=5 (C). The question calls this complete, but explicitly defines the full n-ary property, which is all the calculation needs.

Original paper, page 10

2 marks · MCQ
Report issue

Leaves in a full k-ary tree

Tree Properties & Traversals

Question 36, GATE 2005: A finite full k-ary tree has n internal nodes, each with exactly k children. Number of leaves? A nk; B(n−1)k+1; C n(k−1)+1; D n(k−1).
Question 36, GATE 2005: A finite full k-ary tree has n internal nodes, each with exactly k children. Number of leaves? A nk; B(n−1)k+1; C n(k−1)+1; D n(k−1).
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

If there are n internal nodes and L leaves, the number of parent-child edges is kn. Any finite tree also has n+L−1 edges. Equating gives L=n(k−1)+1, C. The premise is that every internal node has exactly k children, not merely at most k.

Count the same edges in two ways. Every internal node contributes k outgoing parent-child edges, for kn. Any tree on n+L total nodes has n+L−1 edges. Equating and solving yields L=kn−n+1=n(k−1)+1. This method does not require every leaf to have the same depth; the exact-k-child premise is what matters.

Original paper, page 4