Consider the set of strings on {0,1} in which, \(every \ substring \ of \ 3 \…

2012

Consider the set of strings on {0,1} in which, \(every \ substring \ of \ 3 \ symbols\) has at most two zeros. For example, 001110 and 011001 are in the language, but 100010 is not. All strings of length less than 3 are also in the language. A partially completed DFA that accepts this language is shown below

The missing arcs in the DFA are

Attempted by 150 students.

Show answer & explanation

Key idea: keep track of the last two symbols seen; reject as soon as three consecutive zeros would appear.

Construction and transition rule:

  • States: an initial empty state (ε), single-symbol states (0 and 1), two-symbol states (00, 01, 10, 11), and a rejecting sink state q.

  • General transition rule for two-symbol states: from a state named XY on input b go to the state named Yb, except when XYb = 000; in that case go to the rejecting sink q (because the substring 000 appears).

  • The sink q loops on both 0 and 1.

Complete transition list (the missing arcs):

  • From ε: on 0 → state 0; on 1 → state 1.

  • From state 0: on 0 → state 00; on 1 → state 01.

  • From state 1: on 0 → state 10; on 1 → state 11.

  • From state 00: on 0 → sink q (because reading another 0 would create 000); on 1 → state 01.

  • From state 01: on 0 → state 10; on 1 → state 11.

  • From state 10: on 0 → state 00; on 1 → state 01.

  • From state 11: on 0 → state 10; on 1 → state 11.

  • From sink q: on 0 → q; on 1 → q.

Accepting states: every state except the sink q. This accepts all strings that never contain three consecutive zeros; strings of length less than 3 are accepted because they never form 3-symbol substrings.

Example runs to verify correctness:

  • For 001110: ε --0→ 0 --0→ 00 --1→ 01 --1→ 11 --1→ 11 --0→ 10. Final state 10 is accepting, so 001110 is accepted.

  • For 100010: ε --1→ 1 --0→ 10 --0→ 00 --0→ q. The run reaches sink q and is rejected, so 100010 is rejected.

Conclusion: The completion that implements the transitions above (with the transition from the "00" state on input 0 going to the rejecting sink and all other transitions following the Yb rule) is the correct DFA for the language.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir