retagged by
43,621 views
59 59 votes
A binary tree T has $20$ leaves. The number of nodes in T having two children is ______.

15 Answers

Best answer
50 50 votes

In A binary tree if there are $N$ leaf nodes then the number of nodes having 2 children will be N-1

$\text{Proof}:$ 

Key idea is find number of edges using Degree and find number of edges using nodes and equate them

Let $l$ be the number of leaf nodes, $D_1$ be the number of nodes with one child and $D_2$ be the number of nodes with two children.

$\text{Sum of Degrees}, D = 1 \times l + 3\times D_2 + 2\times D_1 - 1 \text{(for root)}$

(Root is having one degree less because it is not having a parent) 

$D= l+ 3D_2+ 2D_1 - 1 \qquad \rightarrow (1)$

$\text{Number of edges}, e= \frac{D}{2} $

$\text{Number of nodes}, n = D_2+D_1+l $

A tree with $n$ nodes has $n-1$ edges so,

$\frac{D}{2} = D_2+D_1+l-1\qquad \to(2)$

From $(1)$ and $(2)$

$\frac{l+3D_2+2D_1-1}{2} = D_2+D_1+l-1$

$\implies D_2 = l-1$

So, the number of nodes in $T$ having two children  $= 20-1 = 19$

selected by
42 42 votes
$\mathbf{19}$

In Binary tree If there are $N$ leaf nodes then the number of Nodes having two children will be $N-1$. So in this case answer will be $20-1$, means $19$.
edited by
29 29 votes

in a binary tree there are 3 types of nodes are possible 1st with 0 child (aka leaf nodes) 2nd, node with 1 child and 3rd, node with 2 children 
suppose no of leaf nodes =k
no ofnodes with 1 child = x
no of nodes with 2 children = y 
so total no of edges = total degree/2
                                = (k+2x+3y-1)/2 = (k+x+y)-1
note - here we are subtracting 1 from  k+2x+3y bcoz of root node.
after solving y = k-1   
so  ans =20-1=19

14 14 votes

The total number of nodes in an m-ary tree is given by

n =  m*i +1 where i denotes the number of internal nodes

here in question m=2(binary tree)

so n=2i+1

Also, n = i+ l

where l= number of leaves in a binary tree

Combining above equations we get
2i+1 = i+ l

i + 1 = l

so i = l-1

Hence, number of internal nodes in a binary tree is number of leaves -1.

Answer : 20-1 = 19 Internal nodes or 19 nodes with 2 children are there in this binary tree.

Note : The Equations used above are provided in Kenneth Rosen Graph Theory chapter.

5 5 votes
The general formula for a Binary tree having two children with n leaves is

=> n-1.

Here n = 20 So answer is 19.
Answer:
Position:
Show:

Related questions

52 52 votes
4 answers 4 answers
17.8k
17.8k views
go_editor asked Feb 12, 2015
17,835 views
Consider the C program below#include <stdio.h int *A, stkTop; int stkFunc (int opcode, int val) { static int size=0, stkTop=0; switch (opcode) { case -1: size = val; brea...
65 65 votes
9 answers 9 answers
15.4k
15.4k views
go_editor asked Feb 12, 2015
15,422 views
Perform the following operations on the matrix $\begin{bmatrix} 3 & 4 & 45 \\ 7 & 9 & 105 \\ 13 & 2 & 195 \end{bmatrix}$Add the third row to the second rowSubtract the th...
73 73 votes
9 answers 9 answers
34.1k
34.1k views
go_editor asked Feb 12, 2015
34,126 views
A computer system implements a $40\;\text{-bit}$ virtual address, page size of $8\;\text{kilobytes}$, and a $128\text{-entry}$ translation look-aside buffer $\text{(TLB)}...
54 54 votes
7 answers 7 answers
22.8k
22.8k views
go_editor asked Feb 12, 2015
22,807 views
Assume that for a certain processor, a read request takes $50\:\text{nanoseconds}$ on a cache miss and $5\:\text{nanoseconds}$ on a cache hit. Suppose while running a pro...