• edited by
34,555 views
43 43 votes

A complete $n-ary$ tree is a tree in which each node has $n$ children or no children. Let $I$ be the number of internal nodes and $L$ be the number of leaves in a complete $n-ary$ tree. If $L = 41$ and $I = 10$, what is the value of $n$?

  1. $3$
  2. $4$
  3. $5$
  4. $6$

10 Answers

Best answer
47 47 votes

If you do little bit experiments on no of leaves, Internal nodes, you will realize that they have equation like following :-

No of leaves $(L) = (n-1) *$ Internal Nodes $(I) + 1$

Here we need to find $n$.

Putting values

$41 = (n-1) * 10 + 1$
$\implies(n-1) * 10 = 40$
$\implies n-1 = 4$
$\implies n = 5$

So, answer is C.

• edited by
56 56 votes
Sum of degrees in tree $= L +  I \times (n+1) - 1 = 10n + 50 ($Each leaf node has degree 1 and all internal nodes have degree $k+1,$ except root which has degree $k)$

So, number of edges $= 5n + 25 ($Number of edges in a graph (hence applicable for tree also) is half the sum of degrees as each edge contribute $2$ to the sum of degrees)

In a tree with $n$ nodes we have $n-1$ edges, so with $41+10 = 51$ nodes, there must be $50$ edges.

So, $5n + 25 = 50$

$\implies 5n = 25$

$\implies n = 5$
21 21 votes

Full m-ary tree means : Every internal node have exactly m children. Other way, each node has zero or m children only. 

Some of the full m-ary trees.

T1 (m=2) ,  T2 (m=3) , T3 (m=5)  are full but T4 is not.

In this question, how they define complete means the full m-ary tree. We have n-ary tree and Internal nodes ( I ) = 10 , Leaf nodes ( L ) = 41

$n = L+ I \\ =>n = 51 \\ =>n*10+1 = 51 \\ =>n = 5$

• edited by
11 11 votes

Total number of internal nodes = $I=10$
Total number of leaf nodes = $L=41$

for a $n-ary$ tree, levels starts with $0$ and at each level there are $n^k$ nodes; where $k$ it the level number.

\[\begin{align*} \text{total number of nodes} - L &= I \\ \left( 1 + n^1 + n^2 + \dots + n^k \right) - L &= I \\ \left( 1 + n^1 + n^2 + \dots + n^k \right) - 41 &= 10 \\ \left(n^1 + n^2 + \dots + n^k \right) &= 50 \\ \frac{n(n^k-1)}{n-1} &= 50 \qquad \text{;on putting }n=5 \\ n^k &= 41\\ \end{align*}\]

where, $n^k$ represents number of nodes in last level i.e. leaf nodes, so on taking option C verifies it.

Hence, answer = option C

8 8 votes
for this type of question, don't remember formulas simply learn derivations

total number of nodes (N) = internal nodes (n)+ leaf nodes(L)

total  number of edge(E)= N-1

so here internal node=10 , leaf nodes=41

so edge(E)= 10+41-1=50

again Edge E= maximum child size of internal nodes* total internal nodes

so, 50= I*10

I=5
1 1 vote

most of the solutions have used some equation, so I tried with the basic handshaking lemma. Do point out it you find anything incorrect

Answer:
Position:
Show:

Related questions

125 125 votes
5 answers 5 answers
34.8k
34.8k views
Kathleen asked Sep 21, 2014
34,772 views
Consider the process of inserting an element into a $\text{Max Heap}$, where the $\text{Max Heap}$ is represented by an array. Suppose we perform a binary search on the ...
36 36 votes
4 answers 4 answers
14.3k
14.3k views
Kathleen asked Sep 21, 2014
14,279 views
Consider the following C program segment where $\text{CellNode}$ represents a node in a binary tree:struct CellNode { struct CellNode *leftChild; int element; struct Cell...
24 24 votes
3 answers 3 answers
11.3k
11.3k views
Kathleen asked Sep 21, 2014
11,295 views
The inorder and preorder traversal of a binary tree are$\text{d b e a f c g}$ and $\text{a b d e c f g}$, respectivelyThe postorder traversal of the binary tree is:$\text...
52 52 votes
4 answers 4 answers
24.8k
24.8k views
Kathleen asked Sep 21, 2014
24,789 views
The following postfix expression with single digit operands is evaluated using a stack:$$8 \ 2 \ 3 \ \;\hat{}\; ∕ \ 2 \ 3 * + 5 \ 1 * -$$Note that $\;\hat{}\;$ is the ...