Back to the 2022 paper

Module 1: Introduction & Regular Languages

20227m

Let L⊆{0,1,2}∗L \subseteq \{0,1,2\}^* be strings without consecutive identical symbols (no 0000, no 1111, no 2222). Design a DFA for LL.

Worked SolutionAI Assisted

Answer

Language: L={w∈{0,1,2}∗∣no 00,11,22 as substring}L = \{ w \in \{0,1,2\}^* \mid \text{no } 00, 11, 22 \text{ as substring} \}

DFA Construction

Idea: Track the last symbol seen (0, 1, or 2) or "none yet" (start). Forbid transition on same symbol as last.

States:

  • qϵq_\epsilon : start, no symbol yet (also accepting)
  • q0q_0 : last symbol was 0 (accepting)
  • q1q_1 : last symbol was 1 (accepting)
  • q2q_2 : last symbol was 2 (accepting)
  • q×q_\times : dead/reject state (non-accepting)

Alphabet: Σ={0,1,2}\Sigma = \{0,1,2\}

Transition Function δ\delta:

State \\backslash Input 0 1 2
qϵq_\epsilon q0q_0 q1q_1 q2q_2
q0q_0 q×q_\times q1q_1 q2q_2
q1q_1 q0q_0 q×q_\times q2q_2
q2q_2 q0q_0 q1q_1 q×q_\times
q×q_\times q×q_\times q×q_\times q×q_\times

Formal DFA: M=(Q,Σ,δ,qϵ,F)M = (Q, \Sigma, \delta, q_\epsilon, F) where

  • Q={qϵ,q0,q1,q2,q×}Q = \{q_\epsilon, q_0, q_1, q_2, q_\times\}
  • Σ={0,1,2}\Sigma = \{0,1,2\}
  • qϵq_\epsilon initial
  • F={qϵ,q0,q1,q2}F = \{q_\epsilon, q_0, q_1, q_2\} (all except dead)
  • δ\delta as table above

State Diagram (Mermaid)

MermaidDiagram
Rendering diagram…

Regular Expression (for verification)

L=ϵ+(0+1+2)((0+1+2)−(00+11+22))∗L = \epsilon + (0+1+2)( (0+1+2) - (00+11+22) )^*
More compactly using complement:
L=Σ∗∖Σ∗(00+11+22)Σ∗L = \Sigma^* \setminus \Sigma^*(00+11+22)\Sigma^*

Test Cases

Input Path Accept?
ϵ\epsilon qϵq_\epsilon Yes
012012 qϵ→0q0→1q1→2q2q_\epsilon \xrightarrow{0} q_0 \xrightarrow{1} q_1 \xrightarrow{2} q_2 Yes
010010 q0→q1→q0q_0 \to q_1 \to q_0 Yes
0000 q0→0q×q_0 \xrightarrow{0} q_\times No
101101 q1→q0→q1q_1 \to q_0 \to q_1 Yes
21212121 q2→q1→q2→q1q_2 \to q_1 \to q_2 \to q_1 Yes

Minimality

5 states are minimal (Myhill-Nerode: ϵ,0,1,2\epsilon, 0, 1, 2 are pairwise distinguishable; dead state needed).

Final Answer

DFA with 5 states (qϵ,q0,q1,q2,q×q_\epsilon, q_0, q_1, q_2, q_\times), accepting all except q×q_\times, transitions as table above. Rejects any string with 00,11,00, 11, or 2222.

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.