CSC 392 · Automata Theory, Computability and Formal Languages
Our notes
2 min readThe idea
A finite automaton reads a string one symbol at a time, moving between a finite number of states. If it ends in an accepting state, the string is in the language. It has no memory beyond its current state.
Formal definition
A DFA is M = (Q, Σ, δ, q₀, F):
- Q: finite set of states,
- Σ: input alphabet,
- δ: transition function Q × Σ → Q (exactly one next state for each state and symbol),
- q₀: start state,
- F: set of accepting (final) states.
Example 1: even number of 1s
States E (even so far, start, accepting) and O (odd).
| State | 0 | 1 |
|---|---|---|
| → *E | E | O |
| O | O | E |
Trace 10110: E →1 O →0 O →1 E →1 O →0 O. Ends in O: rejected (three 1s). Trace 1001: E → O → O → O → E: accepted.
Example 2: binary strings ending in 01
States: q0 (start), q1 (last symbol 0), q2 (last two symbols 01, accepting).
| State | 0 | 1 |
|---|---|---|
| → q0 | q1 | q0 |
| q1 | q1 | q2 |
| *q2 | q1 | q0 |
Trace 1101: q0 →1 q0 →1 q0 →0 q1 →1 q2: accepted. Trace 0110: ... ends in q1: rejected.
Example 3: binary numbers divisible by 3
Keep the remainder mod 3 as the state. Reading bit b changes remainder r to (2r + b) mod 3.
| State | 0 | 1 |
|---|---|---|
| → *r0 | r0 | r1 |
| r1 | r2 | r0 |
| r2 | r1 | r2 |
Trace 110 (= 6): r0 → r1 → r0 → r0: accepted ✓. Trace 111 (= 7): r0 → r1 → r0 → r1: rejected ✓ (7 mod 3 = 1).
Uses
Lexical analysers in compilers, text search, vending machines, traffic lights, protocol checking, input validation (is this a valid phone number?).
Design tips
- Decide what the machine must remember about the input so far; each possibility is a state.
- Fill in every transition (a missing one goes to a dead state that never accepts).
- Test with strings that should be accepted and rejected, including ε.
Exams usually ask
- Give the formal definition of a DFA.
- Design a DFA for a described language, with diagram and table.
- Trace strings through a DFA.
Common mistake
Leaving out transitions. In a DFA every state needs exactly one transition for every symbol; add a dead state for the missing ones.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
No reading links here yet
Our team adds free books, videos and practice for each topic, and opens every link before it goes up.