• edited by
21,884 views
29 29 votes

How many sub strings of different lengths (non-zero) can be formed from a character string of length $n$?

  1. $n$
  2. $n^2$
  3. $2^n$
  4. $\frac{n(n+1)}{2}$

3 Answers

Best answer
59 59 votes
Assuming in the string of length $n$ provided, all alphabets are distinct.

No. of strings of length $1 = n$
No. of strings of length $2=\left(n-1\right)$
No. of strings of length $3=\left(n-2\right)$
$\vdots$
No. of strings of length $n = 1$

$\begin{align} \text{Hence, total no. of strings} &= n + (n -1) + (n - 2) + (n - 3) +\cdots+ 1\\&= \frac{n(n+1)}{2}\end{align}$

Correct Answer: $D$
• edited by
3 3 votes

If you have a string of length n 
Then you’ll have,

 

n strings of length 1

n-1 strings of length 2

n-2 strings of length 3

n-4 strings of length 5

.

.

.

.

3 strings of length of n-2

2 strings of length n-1

1 string of length n

 

 Therefore total substrings will be n+(n-1)+(n-2)+(n-3)+........+3+2+1 = n(n+1)/2
_______________________________________________________________________________________________

Example : VARUN HAS LENGTH 5

5 strings of length  1 = {V,A,R,U,N}

4 strings of length  2 = {VA,AR,RU,UN}

3 strings of length  3 = {VAR,ARU,RUN}

2 strings of length  4 = {VARU,ARUN}

1 strings of length  5 = {VARUN}

Therefore total substrings will be 5+(5-1)+(5-2)+(5-3)+(5-4)+(5-5) = 5(5+1)/2 = 15


Correct Answer: D

Answer:
Position:
Show:

Related questions

43 43 votes
6 answers 6 answers
16.9k
16.9k views
Kathleen asked Sep 23, 2014
16,946 views
The number of binary strings of $n$ zeros and $k$ ones in which no two ones are adjacent is$^{n-1}C_k$$^nC_k$$^nC_{k+1}$None of the above
51 51 votes
6 answers 6 answers
13.5k
13.5k views
Misbah Ghaya asked Nov 29, 2016
13,529 views
How many substrings (of all lengths inclusive) can be formed from a character string of length $n$? Assume all characters to be distinct, prove your answer.
51 51 votes
8 answers 8 answers
17.4k
17.4k views
Kathleen asked Sep 14, 2014
17,379 views
A multiset is an unordered collection of elements where elements may repeat any number of times. The size of a multiset is the number of elements in it, counting repetiti...
27 27 votes
1 answers 1 answer
15.1k
15.1k views
Kathleen asked Sep 26, 2014
15,073 views
Let the attribute ‘$val$’ give the value of a binary number generated by $S$ in the following grammar:$S \rightarrow L.L \mid L$$L \rightarrow LB \mid B$$B \rightarrow 0 ...