Open In App

Aptitude | GATE CS 1998 | Question 23

Like Article
Like
Save
Share
Report

How many substrings of different length (non-zero) can be formed from a character string of length n ?

(A)

n

(B)

n2

(C)

2n

(D)

n(n+1)/2


Answer: (D)

Explanation:

Number of substrings of length 1: n
Number of substrings of length 2: n-1
Number of substrings of length 3: n-2                                    
Similarly, the number of substrings of length n: 1

Sum of substrings of all lengths = 1+2+…….+(n-1)+n = n(n+1)/2     (Sum of n natural numbers)
 


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 11 Oct, 2017
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads