The Gateway to Computer Science Excellence

+1 vote

In a string of length $n$, how many of the following are there?

- Prefixes.
- Suffixes.
- Proper prefixes.
- Substrings.
- Subsequences.

0 votes

- $n + 1 (n$ prefixes for $n$ characters, plus the empty string$)$
- $n + 1 ($similar to $(a))$
- $n - 1 (n$ prefixes for $n$ characters, minus the string itself$)$
- $n [1$ character substring$] + (n - 1) [2$ character substring$] + \dots + 1 = \dfrac{n (n + 1)}{2}.$ Add $1$ to include the empty substring.
- $\displaystyle{}\sum_{i=0}^{n} {^{n}C_{i}} = 2^{n}$, if you include the empty subsequence.

52,315 questions

60,433 answers

201,778 comments

95,257 users