s = ABC

length 0 = 1

lenght 1 = {A , B , C} = 3

length 2 = {AB , BC } = 2

length 3 = {ABC} = 1

total string = length 0 + length 1 + length 2 + length 3 = 1 + 3 + 2 + 1 = 7

option D is the correct answer

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

0 votes

The number of substrings(of all lengths inclusive) that can be formed from character string of length n is

a)n

b)n^2

c)n(n-1)/2

d)(n(n+1)/2)+1

a)n

b)n^2

c)n(n-1)/2

d)(n(n+1)/2)+1

0

let's take an example:

s = ABC

length 0 = 1

lenght 1 = {A , B , C} = 3

length 2 = {AB , BC } = 2

length 3 = {ABC} = 1

total string = length 0 + length 1 + length 2 + length 3 = 1 + 3 + 2 + 1 = 7

option D is the correct answer

s = ABC

length 0 = 1

lenght 1 = {A , B , C} = 3

length 2 = {AB , BC } = 2

length 3 = {ABC} = 1

total string = length 0 + length 1 + length 2 + length 3 = 1 + 3 + 2 + 1 = 7

option D is the correct answer

0

@anji

AC is not Substring of ABC because it is separated by B , Substring is that in which we add another substring , in either left are Right side of Substring to get actual Substring.

AC is not Substring of ABC because it is separated by B , Substring is that in which we add another substring , in either left are Right side of Substring to get actual Substring.

0

Substring is defined as "Zero or more **Consecutive symbols taken**"

What you must be confusing it with is "Subsequence" which is defined as "Zero or more Symbols left out (Consecutive or Not)"

Subword is defined as "One or more **Consecutive symbols taken**" (Subword is same as substring except for Zero length string)

+1 vote

The length of substrings are **n** or **n-1** or **n-2** or....or **2** or **1** or **0**

let the string is **abcd...xyz**

no.of substrings of length **'n'** = 1 ------ abcd....xyz

no.of substrings of length **'n-1'** = 2 ------ abcd....xy , bcd....xyz

no.of substrings of length **'n-2'** = 3 ------ abcd....x , bcd....xy , cdef.....xyz

.......

no.of substrings of length **'2'** = n-1 ----- ab,bc,cd,....vx,xy,yz

no.of substrings of length **'1'** = n ------ a,b,c,d,....x,y,z

no.of substrings of length **'0'** = 1 ----> only empty string is possible

total substrings = 1+2+3+...+(n-1) + n + 1

= [ 1+2+3+...+(n-1) + n ] + 1

= $\frac{n(n+1)}{2}$ + 1

- All categories
- General Aptitude 1.3k
- Engineering Mathematics 5.5k
- Digital Logic 2.1k
- Programming & DS 4k
- Algorithms 3.4k
- Theory of Computation 4.2k
- Compiler Design 1.6k
- Databases 3.1k
- CO & Architecture 2.7k
- Computer Networks 3.1k
- Non GATE 1.1k
- Others 1.4k
- Admissions 501
- Exam Queries 449
- Tier 1 Placement Questions 19
- Job Queries 62
- Projects 12

38,094 questions

45,587 answers

132,148 comments

49,123 users