43 votes

Let $w$ be any string of length $n$ in $\{0,1\}^*$. Let $L$ be the set of all substrings of $w$. What is the minimum number of states in non-deterministic finite automation that accepts $L$?

- $n-1$
- $n$
- $n+1$
- $2^{n-1}$

59 votes

Best answer

3

Why answer is not n+2? for string of length n we need n+1 states and one extra state to reject the string of length greater than n.

1

Sir its an NFA, so here i dont think we need a reject state, we only need n+1 states for counting the length. Please clarify.

0

Sir a minimized NFA that accepts only "1" will have two states, 1 final and 1 non-final(start state) and a transition from non-final to final state on "1" and no other transitions... am I right ?

6

i don't think we need a dead state, the transition function is Δ : *Q* × Σ → *P(Q)*. P(Q) also includes empty set.

11

In NFA we do not need dead state.

http://www.eecs.wsu.edu/~ananth/CptS317/Lectures/FiniteAutomata.pdf

Page no 18.

**For each state, not all symbols necessarily have to be defined in the transition function**

** **answer should be

0

@arjun sir how can u say that for dfa it would take n+2 states . try this containing substring '11' it would take 3 states. for containing substring of length dfa always takes n+1 states. bcz here no trap states comes to be in picture . but if they ask starting wid then it will take 'n+2' states bcz here dead state is involved. am i correct plz verify @praveen saini sir @habib khan also

1

**sir question is asking substring and not prefix of string so how n+1 states and also it is asked for NFA and not epsilon NFA .**

0

1

We cannot generalize that we need n+2 states for DFA.

eg: w=010 ; n=3

L={ Ξ΅ , 0 , 1 , 01 , 10 , 101 }

Try drawing a DFA, it will have 7 states , which is not equal to n+2=5

eg: w=010 ; n=3

L={ Ξ΅ , 0 , 1 , 01 , 10 , 101 }

Try drawing a DFA, it will have 7 states , which is not equal to n+2=5

0

for nfa answer is n+1 states

But all dfa does not have dead state. for some of languages we have dead state for dfa.

so for dfa it can be n+1 or n+2 states

can anybody give perfect example.

But all dfa does not have dead state. for some of languages we have dead state for dfa.

so for dfa it can be n+1 or n+2 states

can anybody give perfect example.

0

@abhishekmehta4u in your diagram edge from start state to finish state is not needed , if possible for you please change image

0

you can create infinite states in NFA using epsilon transitions.

Even if you are not using epsilon moves then also you can create infinite states for the given problem.

Even if you are not using epsilon moves then also you can create infinite states for the given problem.

0

@Arjun For DFA, isn't it more accurate to say that we require at least n+2 states rather than saying that the minimum no of states required is n+2 ?

18 votes

Step1. Draw a NFA that accept 001 so it requires (n+1=4) states

step2. Now our requirement is to draw a NFA for "L be the set of all substrings of w". so From NFA given in step1 attach an branch containing Ξ΅ from initial state to all other states. This Ξ΅-NFA accepts L.

--- but there may be a confusion that it is a Ξ΅-NFA as i know that for an Ξ΅-NFA an equivalent NFA(w/o Ξ΅) contains same no of states as in Ξ΅-NFA

**Hence this NFA also contains "n+1" states**

Step3. now someone ask that how many minimum states DFA it requires to accept the L so i want to tell u that there is no any standard result for it and also** it is wrong to say that DFA for L contains "n+2" states** it is variying {u can check it also by taking some examples}.

7 votes

For n length string, the nfa needs n+1 states where all the states are final states and there are epsilon transitions from the initial state to all final states. So, answer is n+1.

3 votes

For example - string is 101 (n=3) then possible sub-strings are : (epsilon, 1,0,10,101,01,1) , so max length sub-string will be string itself.

And for accepting 'n' length string atleast 'n+1' states will be required ,either in DFA or NDFA (may require more states for acceptance of other sub-strings too)

So Answer is C) n+1

And for accepting 'n' length string atleast 'n+1' states will be required ,either in DFA or NDFA (may require more states for acceptance of other sub-strings too)

So Answer is C) n+1

0

Also can you help me with the substring of 'pratik' (assume input alphabet = a to z)

I guess you are just taking set of prefixes Union set of suffixes

According to me there are 2^6 substrings for the string 'pratik'

I guess you are just taking set of prefixes Union set of suffixes

According to me there are 2^6 substrings for the string 'pratik'

0

1

substrings are simply possible factors of the string. In this question we needed to find the states, so we need is only maximum possible substring of string, and maximum possible substring of any string is string itself

0

@Pratikkumar Bulani 2^{6} doesn't seems to be correct option to find all possible strings of length 6. I think for any given string w of length |W|=n, the number of possible strings (including null)= (n(n+1))/2 +1 where +1 is for epsilon.

Please check:https://gateoverflow.in/1660/gate1998-1-23

0

0 can be a substring and if u want to accept 0 only then also 2 states will be needed because if u will loop of a in any state then not only one o but all zeros will be accepted...so if u want to accept only one one 0 then u have to make two states....A β **B two states with 0 move.so length of 0 is 1 and we need length+1 states.**

0 votes

I thought about this question as follows

Question is asking for set of all substrings to be accepted by nfa where a is of size n

So substrings possible are {β¬, 0,1,00,01,10,11} now draw nfa for this

q0---0,1-->q1--0,1-->q2 where all states are accepting state hence it's 3 for n=2 so n+1

Question is asking for set of all substrings to be accepted by nfa where a is of size n

So substrings possible are {β¬, 0,1,00,01,10,11} now draw nfa for this

q0---0,1-->q1--0,1-->q2 where all states are accepting state hence it's 3 for n=2 so n+1

0 votes

Since L is set of all substrings of βwβ (Substring of a string is obtained by deleting any prefix or any suffix from string), so if we consider βwβ as β101β , then the substrings of w are { Ο΅, 0, 1, 10, 01, 101}.

Since the string β101β is also its substring, so we require 4 states (i.e. for n length string, n+1 states are required) and the NFA would be: