The number of substrings that can be formed from string given by “a d e f b g h n m p” is
(A) 10
(B) 45
(C) 56
(D) 55
Answer: (C)
Explanation: Total number of non-empty substrings of all lengths from 1 to n
= n + (n-1) + (n-2) + (n-3) + … 2 + 1
= n * (n + 1)/2
These are non-empty substrings, but if you count null substrings there are [n(n+1)/2] + 1.
Where, n = 10,
So, total number of all substrings are = 10*11/2 + 1 = 55+1 = 56.
Option (C) is correct.
Quiz of this Question