The number of substrings (of all lengths inclusive) that can be formed from a character string of length is
View worked solution
Answer: D
To find the number of non-empty substrings that can be formed from a character string of length (assuming all characters are distinct):
We can count the substrings by their lengths:
- Number of substrings of length :
- Number of substrings of length :
- Number of substrings of length :
- Number of substrings of length :
The total number of substrings is the sum of these counts:
Alternative Approach:
A substring is uniquely identified by its starting index and ending index such that . Choosing such a pair is equivalent to choosing distinct boundary points from possible boundary positions. The number of ways to do this is:
Thus, the correct option is D.
Free practice · Your answers on this page are not saved.
