2,201 views
4 votes
4 votes

The maximum no of proper non empty sub-strings for the given 'n' length string is:

A)    n*(n+1)/2    -   1

B)    n*(n+1)/2

C)    n*(n+1)/2   +  1

D)    none of the above

I basically want a good explanation here for whatever option you choose???thanks in advance smiley.

<answer given as per coaching book is B>

2 Answers

Best answer
6 votes
6 votes

take "abc" string. Sub strings are

  1. a
  2. b
  3. c
  4. ab
  5. bc
  6. abc

For a string of length n, we can have 1 sub-string of length n, 2 sub-strings of length n-1, 3 sub-strings of length n-2, ... n substrings of length 1. So, total no. of sub-strings = 1 + 2 + ... + n = n (n+1)/2

But the question asks for "proper" sub-strings. Proper sub-string means the given string (of length n) must not be counted. So, the answer must be n(n+1)/2 - 1.

Ref: http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/StringMatch/stringMatchIntro.htm

edited by

Related questions

0 votes
0 votes
1 answer
1
2 votes
2 votes
0 answers
2
radha gogia asked Nov 18, 2015
226 views
In this one how come from q1 we are directly converting it into qf , since non-terminals have not been emptied , this method is for converting grammar in GNF to PDA .