How many sub strings of different lengths (non-zero) can be formed from a character string of length ?
View worked solution
Answer: D
To find the number of non-empty (non-zero length) substrings that can be formed from a character string of length (assuming all characters in the string are distinct):
We can classify the substrings by their length , where :
- Substrings of length : There are such substrings.
- Substrings of length : There are such substrings.
- Substrings of length : There are such substrings.
- Substrings of length : There is such substring.
Summing these up, the total number of non-empty substrings is:
Alternative Approach:
A substring is uniquely defined by choosing its starting position and ending position such that .
- The number of ways to choose two distinct indices is .
- The number of ways to choose (substrings of length 1) is .
Total substrings = .
Thus, the correct option is D.
Free practice · Your answers on this page are not saved.
