edited by
20,832 views
41 41 votes

A complete $n$-ary tree is one in which every node has $0$ or $n$ sons. If $x$ is the number of internal nodes of a complete $n$-ary tree, the number of leaves in it is given by

  1. $x(n-1) +1$
  2. $xn-1$
  3. $xn +1$
  4. $x(n+1)$

12 Answers

Best answer
53 53 votes

Correct Option: A

$x(n-1) +1$

Originally when we have root , there is only $1$ node, which is leaf. (There is no internal node.) From this base case "+1" part of formula comes.

When we add $n$ children to root, we make root internal. So then Total Leaves $=  1(n-1) + 1 = n$.

In complete $n$ ary tree every time you add $n$ children to node, you add $n$ new nodes & make that node to which you are inserting childen internal.( $+n$ for leaves, $-1$ for node which you are attaching ). So if you had originally few leaves, you add $n-1$ "New" leaves to them. This is how $x(n-1) +1$ makes sense.

edited by
22 22 votes

As they said in question A complete n-ary tree is one in which every node has 0 or n sons.

lets take few case's and analyze them 

if we consider n = 2 (A Binary tree in place of n-ary tree See figure 1)

if we consider n = 3 (A 3-ary tree in place of n-ary tree See figure 2)

if we consider n = 4 (A 4-ary tree in place of n-ary tree See figure 3)

       

Type of Tree Internal Node (x) Leaf Nodes
Binary 3 4
3-ary 3 7
4-ary 3 10
5-ary 3 13

In Given Options put the values of internal nodes and type of tree and get the relation

    x(n-1)+1     xn-1     xn+1    x(n+1)
3(2-1)+1 = 4  3*2 - 1 = 5 3*2+1 = 7 3(2+1) = 9
6+1 = 7 8 10 12
10 11 13 15

Answer : Option A

edited by
9 9 votes

let

i = # internal nodes

l = # leaves

n = total # nodes 

then for m-ary tree

total # nodes(n)  = m* i + 1.......................(1)   

also u know  total # nodes(n) = i + l............(2)

now u use these two formula

n x + 1 = x + l

so l = x * (n-1) + 1

8 8 votes
if 1-ary tree and x is internal node then no of leave is 1

if 2-ary tree and x is internal node then no of leaves are (x+1)

if 3-ary tree and x is internal node then no of leaves are (2x+1)

if 4-ary tree and x is internal node then no of leaves are (3x+1)

if n-ary tree and x is internal node then no of leaves are (n-1)x+1

so ans is A.)
5 5 votes
Each of the $x$ internal nodes has exactly $n$ edges connected to it. So there are $xn$ edges in the tree. Some of these edges have other internal nodes at the other end and some have leaves at the other end. Except for the root, all other internal nodes are at the other end of an edge starting at an internal node. Thus to get the number of leaves we compute the number of edges with leaves at the other end. We do this by subtracting $x-1$ from $xn$. Hence the formula is $xn - (x-1)$.
1 1 vote

Recursive solution for this problem:

$T(x) = T(x-1) + n -1$

$T(0) = 1$


$T(x) = T(x-i) + i \cdot (n-1) $

when i=x, we have x-i = 0

$T(x) = T(0) + x\cdot(n-1)$

$ = 1 + x\cdot (n-1)$

Hence option A

Answer:
Position:
Show:

Related questions

45 45 votes
5 answers 5 answers
26.0k
26.0k views
Kathleen asked Sep 25, 2014
25,959 views
Which of the following statements is false? A tree with a $n$ nodes has $(n – 1)$ edges A labeled rooted binary tree can be uniquely constructed given its postorder and p...
38 38 votes
5 answers 5 answers
11.6k
11.6k views
Kathleen asked Sep 26, 2014
11,646 views
Let $p$ be a pointer as shown in the figure in a single linked list. What do the following assignment state...
38 38 votes
3 answers 3 answers
18.5k
18.5k views
Kathleen asked Sep 26, 2014
18,541 views
Suppose $A = \{a, b, c, d\}$ and $\Pi_1$ is the following partition of A$\Pi_1 = \left\{\left\{a, b, c\right\}\left\{d\right\}\right\}$List the ordered pairs of the equiv...
62 62 votes
12 answers 12 answers
40.6k
40.6k views
Kathleen asked Sep 25, 2014
40,565 views
Let $A$ be a two dimensional array declared as follows:A: array [1 …. 10] [1 ….. 15] of integer;Assuming that each integer takes one memory location, the array is stored ...