Exercise 2
Deterministic Finite Automata (DFA)
Chapter 3: Regular Languages
Date: January 26, 2026
Problem 1: DFA Analysis
Problem 1: DFA Analysis
Q = {q1, q2, q3, q4, q5}
Start state: q3
State
u
d
q1
q1
q2
q2
q1
q3
q3
q2
q4
q4
q3
q5
q5
q4
q5
(a) State Diagram
d
q1
d
q2
u
d
q3
u
u
d
q4
u
q5
u
d
Figure 1: State Diagram of DFA M
Legend: Double circle indicates accepting state. Arrow points to start state q3.
2
Problem 2: DFA Design
(b) Start State
The start state is q3.
(c) Set of Accepted States
The set of accepted states is F = {q3}.
(d) State Sequence on Input "uudddddduuuu"
Input string: w = uudddddduuuu
Starting from q3, we trace through each symbol:
q3
q1
q2
q1
d
q2
d
q3
d
q4
d
q5
d
q5
d
q5
State sequence: q3, q2, q1, q2, q3, q4, q5, q5, q5, q4, q3, q2, q1
(e) Does the machine accept "uudddddduuuu"?
The machine ends in state q1 after processing "uudddddduuuu".
Since q1 ∈
/ F = {q3}, the machine does NOT accept this string.
Answer: No
(f) Does the machine accept ε (empty string)?
For the empty string ε, the machine stays in the start state q3.
Since q3 ∈ F = {q3}, the machine DOES accept the empty string.
Answer: Yes
Problem 2: DFA Design
Design DFAs for the following languages over alphabet Σ = {0, 1}.
3
q4
q3
q2
Problem 2: DFA Design
(a) Strings containing substring "1010"
L = {w ∈ {0, 1}∗ ∣ w contains 1010 as a substring}
We need to track progress toward seeing "1010":
q0: Initial state (no progress)
q1: Saw "1"
q2: Saw "10"
q3: Saw "101"
q4: Saw "1010" (accepting)
1
q0
q1
1
0
q2
1
q3
0
0
q4
0
1
0
1
Figure 2a: DFA for strings containing "1010"
(b) Length at least 3 and third symbol is 0
L = {w ∈ {0, 1}∗ ∣ ∣w∣ ≥ 3 and w[3] = 0}
States track the position and the third symbol:
q0, q1 , q2: Counting positions (0, 1, 2 symbols seen)
qaccept: Third symbol was 0 (accepting)
qreject: Third symbol was 1 (non-accepting trap)
4
Problem 2: DFA Design
0
q0
0,1
q1
0,1
q2
qa
0,1
1
qr
0,1
Figure 2b: DFA for strings with |w|>=3 and w[3]=0
(c) Neither "01" nor "10" as substring
L = {w ∈ {0, 1}∗ ∣ w contains neither 01 nor 10}
This means the string must be all 0s or all 1s (including empty string):
q0: Empty string or all same symbol so far (accepting)
q1: Saw at least one 0, no 1 yet
q2: Saw at least one 1, no 0 yet
qtrap: Saw both 0 and 1 (non-accepting)
0
q0
q1
1
0
1
q2
qt
0
0,1
1
Figure 2c: DFA for strings without "01" or "10"
5
Problem 2: DFA Design
(d) Starts with 0 and odd length, or starts with 1 and even length
L = {w ∈ {0, 1}∗ ∣ (w[1] = 0 ∧ ∣w∣ is odd) ∨ (w[1] = 1 ∧ ∣w∣ is even)}
States track first symbol and parity of length:
q0: Initial state
q0,odd: Started with 0, odd length (accepting)
q0,even: Started with 0, even length
q1,odd: Started with 1, odd length
q1,even: Started with 1, even length (accepting)
0,1
0
q0o
q0e
0,1
q0
0,1
1
q1e
q1o
0,1
Figure 2d: DFA for (starts 0, odd) or (starts 1, even)
(e) All strings except "11" and "111"
L = {0, 1}∗ ∖ {11, 111}
We need to detect and reject exactly "11" and "111":
1
q1
q0
0
1
0
q2
1
q3
qa
1
0
0
Figure 2e: DFA for all strings except "11" and "111"
6
0,1
Problem 2: DFA Design
(f) Length at most 4
L = {w ∈ {0, 1}∗ ∣ ∣w∣ ≤ 4}
Count symbols up to 4, then trap for longer strings:
q0
0,1
q1
0,1
q2
0,1
q3
0,1
q4
0,1
qt
0,1
Figure 2f: DFA for strings with length at most 4
(g) Language {epsilon, 0}
L = {ε, 0}
1
q0
qt
0
q1
0,1
0,1
Figure 2g: DFA for {epsilon, 0}
(h) All strings except the empty string
L = {0, 1}+ = {0, 1}∗ ∖ {ε}
Accept if at least one symbol is read:
7
Problem 2: DFA Design
q0
0,1
q1
0,1
Figure 2h: DFA for all non-empty strings
8