Skip to content

GATE CS 1994 Q1.15 — Combinatorics: Counting, Recurrence Relations, Generating Functions

Explain with AI

The number of substrings (of all lengths inclusive) that can be formed from a character string of length nn is

Choose one option
View worked solution

Answer: D

To find the number of non-empty substrings that can be formed from a character string of length nn (assuming all characters are distinct):

We can count the substrings by their lengths:

  • Number of substrings of length 11: nn
  • Number of substrings of length 22: n−1n - 1
  • Number of substrings of length 33: n−2n - 2
  • …\dots
  • Number of substrings of length nn: 11

The total number of substrings is the sum of these counts:

Total Substrings=n+(n−1)+(n−2)+⋯+1=∑i=1ni=n(n+1)2\text{Total Substrings} = n + (n-1) + (n-2) + \dots + 1 = \sum_{i=1}^{n} i = \frac{n(n+1)}{2}

Alternative Approach:
A substring is uniquely identified by its starting index ii and ending index jj such that 1≤i≤j≤n1 \le i \le j \le n. Choosing such a pair (i,j)(i, j) is equivalent to choosing 22 distinct boundary points from n+1n+1 possible boundary positions. The number of ways to do this is:

(n+12)=(n+1)n2=n(n+1)2\binom{n+1}{2} = \frac{(n+1)n}{2} = \frac{n(n+1)}{2}

Thus, the correct option is D.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Combinatorics: Counting, Recurrence Relations, Generating Functions questions