IAE Academy

GATE 2025 CS1 Q.50: solution and answer

GATE 2025 · CS1Q.50 · 2 marks · MSQ

Consider the following deterministic finite automaton (DFA) defined over the alphabet, . Identify which of the following language(s) is/are accepted by the given DFA.

GATE 2025 CS1 question 50: A DFA with four states in a row, left to right: q_0 (start, arrow entering from the left), q_1, q_2, q_3 (q_3 is…Tap to open full size
Figure from the GATE 2025 CS1 paper. It is part of the question.
Figure description

A DFA with four states in a row, left to right: q_0 (start, arrow entering from the left), q_1, q_2, q_3 (q_3 is accepting, double circle). Transitions: q_0 has a self-loop on a; q_0 → q_1 on b; q_1 has a self-loop on b; q_1 → q_2 on a; q_2 → q_3 on b; q_3 → q_2 on a (top curved arc); q_2 → q_0 on a (bottom long arc ending at q_0); q_3 → q_1 on b (bottom arc ending at q_1).

  1. (A)

    The set of all strings containing an even number of 's.

  2. (B)

    The set of all strings containing the pattern .

  3. (C)

    The set of all strings ending with the pattern .

  4. (D)

    The set of all strings not containing the pattern .

Answer and solution

ANSWER

Only (C) is correct: the DFA accepts exactly the strings ending with .

Official answer: CSource: Official answer key, GATE 2025 CS1 (IIT Roorkee)

  1. Read the DFA from the figure. States (start), , , ; is the only accepting state. Transitions: , , , , , , , .

  2. Give each state a meaning: the longest suffix of the input read so far that is a prefix of . So means no useful suffix (), means , means , and means .

  3. Check every transition against this meaning. From : reading gives suffix , so ; reading gives , so . From (): reading gives , so ; reading gives , longest useful suffix , so . From (): reading gives , no useful suffix, so ; reading gives , so . From (): reading gives , longest useful suffix , so ; reading gives , longest useful suffix , so . All eight transitions match, so the DFA is in exactly when the input ends with . The language is , and (C) is correct.

  4. (A) is false. The string ends with , so it is accepted (), but it has three 's, an odd number. Also has an even number of 's but ends in and is rejected.

  5. (B) is false. The string contains , but ends in the non-accepting state , so it is rejected.

  6. (D) is false. The string does not contain , but it ends in and is rejected. Also contains yet is accepted ().

KEY IDEA

Label each state with the longest suffix of the input that is a prefix of the pattern , and check every transition. The DFA is then the standard pattern-matching automaton for strings ending in .

WATCH OUT FOR

Choosing (B) because the automaton is a -detector. Here the accepting state has outgoing transitions to and , so it is not absorbing and the DFA remembers only the last few symbols. Accepting means the input ENDS with , not that it contains .

From the GATE 2025 CS1 paper. Every question of this paper · Download the full paper · All 18 Finite automata questions, with notes

More Finite automata questions