Skip to content
Official PYQ · 2010

GATE CS 2010 Q41 — Regular Expressions and Finite Automata

Explain with AI

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

Choose one option
View worked solution

Answer: C

To find the minimum number of states in an NFA that accepts the set of all substrings of a string ww of length nn, we can analyze both the upper bound (by construction) and the lower bound (by a worst-case example).

1. Upper Bound (Construction):
Let the string be w=a1a2…anw = a_1 a_2 \dots a_n. We can construct an NFA with n+1n+1 states, Q={q0,q1,…,qn}Q = \{q_0, q_1, \dots, q_n\}:

  • q0q_0 is the start state.
  • All states q0,q1,…,qnq_0, q_1, \dots, q_n are final (accepting) states.
  • For each 1≤i≤n1 \le i \le n, there is a transition qi−1→aiqiq_{i-1} \xrightarrow{a_i} q_i.
  • To allow starting at any position in the string, we add ϵ\epsilon-transitions from the start state q0q_0 to every other state qiq_i (for 1≤i≤n1 \le i \le n).
Any substring ai+1…aja_{i+1} \dots a_j is accepted by the path q0→ϵqi→ai+1qi+1⋯→ajqjq_0 \xrightarrow{\epsilon} q_i \xrightarrow{a_{i+1}} q_{i+1} \dots \xrightarrow{a_j} q_j. This NFA uses exactly n+1n+1 states.

2. Lower Bound (Necessity):
Consider the string w=1nw = 1^n. The set of all substrings is L={1k∣0≤k≤n}L = \{1^k \mid 0 \le k \le n\}. Any NFA accepting LL must accept 1n1^n but reject 1n+11^{n+1}. To distinguish between 1n1^n and 1n+11^{n+1}, the automaton must have at least n+1n+1 states to track the length of the string of 11s.

Thus, the minimum number of states in the NFA is n+1n+1.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Regular Expressions and Finite Automata questions