Tree - DPP 01
Tree - DPP 01
[NAT]
1. A binary tree has 1024 leaves. The number of nodes [NAT]
in the tree having two children is _______________. 5. A linked list is used to store a binary tree with 1024
nodes. The number of null pointers present is
[MCQ] __________.
2. The height of a tree is the length of the longest root-
to-leaf path in it. The maximum and minimum [NAT]
number of nodes in a binary tree of height 9 are- 6. Let T be a full binary tree with 4 leaves. (A full binary
(a) 1024, 9 (b) 1023, 10 tree has every level full). Suppose two leaves x and y
(c) 511, 9 (d) 512, 10 of T are chosen uniformly and independently at
random. The expected value of the distance between
[NAT] x and y in T (i.e., the number of edges in the unique
3. In a binary tree, the number of internal nodes of degree path between x and y) is (rounded off to 2 decimal
1 is 6, and the number of internal nodes of degree 2 is places) _____.
12. The number of leaf nodes in the binary tree is
________. [MCQ]
7. The number of leaf nodes in a rooted tree of n nodes,
[MCQ] with each node having 0 or 2 children is-
4. A strict k-ary tree T is a tree that contains exactly 0 or n +1 n –1
(a) (b)
k children. The number of leaf nodes in tree T if there 2 2
are exactly ‘p’ internal nodes is- n
(a) (k – 1)p + 1 (b) pk + 1 (c) (d) n – 1
2
(c) pk + 1 + p (d) None
2
Answer Key
1. (1023) 5. (1025)
2. (b) 6. (2.5)
3. (13) 7. (a)
4. (a)
3
1. (1023) 6. (2.5)
If there are ‘n’ leaf nodes, the number of internal nodes Any two leaf nodes can be selected in 4 * 4 = 16 ways
with 2 children is ‘n – 1’.
Path length between x and y (i) 0 2 4
Number of ways 4 4 8
2. (b) P(i) 4 4 8
Minimum number of nodes in a binary tree of height
16 16 16
9 = 10
Maximum number of nodes in a binary tree of height The expected value of the distance between x and y in
9 = 210 – 1 = 1023 T-
4 4 8
E(i) = i * P(i) = 0 + 2 + 4 = 2.50
3. (13) 16 16 16
If there are ‘n’ internal nodes of degree 2, the number
of leaf nodes is ‘n + 1’. 7. (a)
Number of nodes Number of leaf nodes
4. (a) 1 1
Number of Number of 3 2
internal nodes leaf nodes 5 3
0 1 7 4
1 k . .
2 k + k – 1 i.e 2k – 1 . .
3 2(2k – 1) – k i.e 3k – 2 . .
. n n +1
. 2
.
p pk – (p – 1) i.e (k – 1)p + 1
5. (1025)
The number of null pointers = 1024 + 1 = 1025