Topic: Data Structures
From a character string of length m, the number of sub-strings of all lengths that can be formed are:
- A. $m^{2}$
- B. m
- C. $m(m+1)/2$
- D. $m(\log m)$
Answer: C. $m(m+1)/2$
Explanation: For a string of length m, assuming all characters are distinct and excluding the empty substring, the number of substrings of length 1 is m, length 2 is m-1, and so on up to length m which is 1. The sum of the first m natural numbers is $m(m+1)/2$.