Back to the 2026 paper

Module 1: Introduction, Lexical Analysis

20267m

Construct a DFA over {0,1}\{0, 1\} that accepts all strings containing an even number of 00s and an odd number of 11s. Verify the constructed DFA using suitable accepted and rejected input strings.

Worked SolutionAI Assisted

DFA for: even number of 0s and odd number of 1s over {0,1}\{0,1\}

Idea: track two parities, the parity of the number of 0s and the parity of the number of 1s seen so far. That gives 2×2=42 \times 2 = 4 states.

State #0s #1s
AA (start) even even
BB odd even
CC (final) even odd
DD odd odd

Reading a 0 flips the parity of 0s; reading a 1 flips the parity of 1s. Accepting state: CC (even 0s, odd 1s).

Transition table

State on 0 on 1
→A\to A BB CC
BB AA DD
∗C*C DD AA
DD CC BB

Transition diagram

MermaidDiagram
Rendering diagram…

Formally M=({A,B,C,D},{0,1},δ,A,{C})M = (\{A,B,C,D\}, \{0,1\}, \delta, A, \{C\}).

Verification

Input Path Final state 0s / 1s Result
1 A→CA \to C CC 0 / 1 Accepted
001 A→B→A→CA \to B \to A \to C CC 2 / 1 Accepted
10011 A→C→D→C→A→CA \to C \to D \to C \to A \to C CC 2 / 3 Accepted
01 A→B→DA \to B \to D DD 1 / 1 Rejected
0110 A→B→D→B→AA \to B \to D \to B \to A AA 2 / 2 Rejected
11 A→C→AA \to C \to A AA 0 / 2 Rejected
ε\varepsilon AA AA 0 / 0 Rejected

Every accepted string has an even count of 0s and an odd count of 1s, and every rejected one violates at least one condition, so the DFA is correct.

Similar questions

Free AppAndroid App

Coursify Android App

Generate AI courses, take quick quizzes between classes, and master complex engineering concepts on the go.