Designing DFAs, NFAs and Turing Machines: A Theory of Computation Study Guide
Design a DFA by deciding what each state remembers, trace an NFA with state sets, apply the subset construction and run a simple Turing machine on a tape.

Designing DFAs, NFAs and Turing Machines: A Theory of Computation Study Guide
Automata questions look like puzzles, but there is a reliable way in: decide what the machine needs to remember, give each piece of memory its own state, then fill in the moves. This guide applies that idea to a deterministic automaton, shows how a nondeterministic one is simulated and converted, and finishes with a tiny Turing machine.
What a finite automaton is
A finite automaton reads an input string one symbol at a time. It has a finite set of states, one start state, a set of accepting states and a transition rule. After the last symbol, the string is accepted if the machine sits in an accepting state.
In a DFA (deterministic finite automaton) every state has exactly one move for every symbol. In an NFA (nondeterministic) a state may have several moves for a symbol, none at all, or empty moves that consume nothing. An NFA accepts if at least one possible path ends in an accepting state.
Worked example 1: a DFA for multiples of three
Task: accept binary strings whose value is divisible by 3.
What must the machine remember? Not the whole number, only its remainder when divided by 3. So use three states, R0, R1 and R2, with R0 as both start and accepting state.
Reading a new bit b doubles the old value and adds b. The new remainder is therefore (2r + b) mod 3:
- R0 on 0 goes to R0; R0 on 1 goes to R1.
- R1 on 0 goes to R2; R1 on 1 goes to R0.
- R2 on 0 goes to R1; R2 on 1 goes to R2.
Trace 110, which is 6: R0, then 1 to R1, then 1 to R0 (because 2·1 + 1 = 3), then 0 to R0. It ends in R0, so it is accepted.
Trace 101, which is 5: R0, then R1, then R2 (2·1 + 0 = 2), then R2 (2·2 + 1 = 5, remainder 2). It ends in R2 and is rejected. Both answers agree with ordinary arithmetic.
Worked example 2: an NFA and the subset construction
Task: accept strings over {a, b} whose second-to-last symbol is a.
An NFA can guess. State q0 loops on a and b. On an a it may also jump to q1, betting that this a is the second-to-last symbol. From q1 any symbol leads to q2, which is accepting and has no moves.
To simulate it, track the set of states the machine could be in. Reading bab: start {q0}; after b, {q0}; after a, {q0, q1}; after b, {q0, q2}. The final set contains q2, so bab is accepted. Reading abb ends in {q0}, so it is rejected.
The subset construction turns those sets into DFA states. Starting from {q0} and following every symbol, only four sets ever appear: {q0}, {q0, q1}, {q0, q2} and {q0, q1, q2}. Any set containing q2 is accepting. The result is a four-state DFA with no guessing. Notice that the DFA must remember the last two symbols, which is exactly four possibilities.
Worked example 3: a Turing machine that flips bits
A Turing machine adds a tape it can read, write and move along in either direction. Rules have the form: in state s reading symbol x, write y, move left or right, go to state t.
A machine that flips every bit needs just three rules: in q0 reading 0, write 1 and move right; in q0 reading 1, write 0 and move right; in q0 reading a blank, stay and halt. On input 1011 the head moves right four times, leaving 0100, and halts on the fifth step.
Common mistakes
- Leaving out moves in a DFA. Every state needs a move for every symbol, even if it goes to a dead state.
- Marking the wrong states as accepting after a subset construction. Any set that contains an original accepting state counts.
- Forgetting empty moves when computing the starting set of an NFA.
- Assuming a Turing machine that has not halted after many steps will never halt.
How to check a machine
Write a short list of strings that should be accepted and another that should be rejected, including the empty string and edge cases such as a single symbol. Run every one. For the multiples-of-three machine, test 0, 11 (3), 1001 (9) and 111 (7). A single wrong verdict points straight to the faulty transition.
Doing it with the tool
In the Turing Machine and Finite Automata Simulator, open the DFA and NFA tab, list the states R0 R1 R2, set R0 as start and accepting, and type the six transitions one per line in the form R0 1 R1. Step through 110 to watch the highlighted state move, then paste several strings into the batch test. For the NFA, enter the q0, q1, q2 rules and press the convert button to see the four-state DFA appear. The Turing machine tab accepts rules written as state, read, write, move, next, with _ as the blank.
Limits
The simulator does not prove that a machine is correct; it only runs the inputs you give it. Very large subset constructions are cut off, Turing machines are single-tape and deterministic, and a run stops after a fixed number of steps rather than detecting infinite loops. Pushdown automata and grammars are not included. Use it as a study aid alongside your own diagrams and proofs.


