GateAI
Regular Expressions and Finite Automata

GATE CSE 2017 Set 1 · Q22

NAT1 markEasy

Time

Consider the language L L given by the regular expression (a+b)∗b(a+b) (a+b)^*b(a+b) over the alphabet {a,b} \{a,b\} . The smallest number of states needed in a deterministic finite-state automaton (DFA) accepting L L is _________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 4 (±0)

Regular Expressions and Finite Automata

The given regular expression is $L = (a+b)^*b(a+b)$, which describes the set of all strings over $\{a, b\}$ whosesecond symbol from the right is bb.

In general, for an alphabet of size 2, a DFA that checks whether the kk-th symbol from the right is a specific symbol requires 2k2^k states, because it must remember the last kk symbols seen.

Here k=2k = 2, so the minimum number of states is:

22=42^2 = 4

The 4 states corresponding to the suffix of the last 2 symbols processed are:

  • q0q_0: Initial state (suffix ϵ\epsilon or ends with aaaa)

  • q1q_1: Suffix ends with aa (specifically preceded by something not enabling acceptance, i.e., seen baba or aa)

  • q2q_2: Suffix ends with bb (second symbol from right is not yet bb)

  • q3q_3: Suffix is baba or bbbb (accepting states where the second symbol from right is bb)

Explicitly, the state set {qaa,qab,qba,qbb}\{q_{aa}, q_{ab}, q_{ba}, q_{bb}\} or the standard Myhill-Nerode equivalence classes give exactly 4 states.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Regular Expressions and Finite Automata previous year question is Q22 of the GATE CSE 2017 Set 1 paper. Find more GATE CSE PYQs on Regular Expressions and Finite Automata in Theory of Computation, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Regular Expressions and Finite Automata PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Regular Expressions and Finite Automata in GATE CSE

Regular Expressions and Finite Automata has 41 GATE CSE PYQs across 24 papers from 2011 to 2026. 5 of them are 1-mark NAT questions like this one, and it is the only one in GATE CSE 2017 Set 1.

How GATE tests Regular Expressions and Finite Automata

More from GATE CSE 2017 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2017 Set 1 · Q22 · NAT

Consider the language L given by the regular expression (a+b)*b(a+b) over the alphabet {a,b} . The smallest number of states needed in a deterministic finite-state automaton (DFA) accepting L is …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.