Deterministic finite automata
The DFA as a five-tuple, its transition function and the extended transition function, acceptance and the language of a DFA, transition tables and state diagrams, complete DFAs and the dead state, how a run proceeds step by step, why a DFA needs only constant memory and time linear in the input, how many DFAs there are, and the standard small examples (ends with 01, even number of a's, divisible by 3).
Why it exists
A finite automaton is the simplest model of a computer: a machine with a fixed, finite amount of memory that reads its input once, from left to right, and then says yes or no. It is also the model of a great many real things: the lexical analyser of a compiler (see lexical analysis), a vending machine, the control of a traffic light, a network protocol's state. The deterministic version has no choices: in every state the next symbol decides the next state. Everything in this subject is built on it, and the questions GATE asks are of three kinds: what language does this DFA accept, design a DFA for this language, and how many states are needed.
Prerequisites
You need strings, alphabets and languages (alphabets, strings and languages).
Precise definitions
DFA. A deterministic finite automaton is a 5-tuple :
- : a finite set of states;
- : the input alphabet;
- : the transition function (a total function: exactly one next state for every state and symbol);
- : the start state;
- : the set of accepting (final) states.
Extended transition function. is defined by and : the state reached from after reading the whole string .
Acceptance and language. accepts if . The language of is . A language is regular if some DFA accepts it.
Representations. A transition table lists for every and (with marks for the start and accepting states). A state diagram draws states as circles (accepting ones doubled), the start state with an arrow from nowhere, and an edge whenever (parallel edges are drawn as one edge with several labels).
Complete and partial DFAs. In the definition every state has an edge for every symbol. Diagrams in books often omit the edges that lead to a dead state (trap state) , a non-accepting state with for all ; a machine with missing edges is a partial DFA, and the missing edges mean "go to the dead state and reject". When counting states, a complete DFA must include the dead state if it is needed.
How it works
A run
Reading a string is a walk through the diagram: start in , and for each symbol follow the edge with that label. There is exactly one such walk, with steps; the string is accepted if the walk ends in an accepting state. The animation shows a DFA for the binary strings that end with : the three states mean "the string so far does not end with or with " (, which includes the empty string), "ends with " (), and "ends with " (, accepting). On the input :
DFA for the binary strings that end with 01: start
Simulated, not typedDouble circle = accepting state. Arrow from nowhere = start state.
Step 0
Start in the start state q0. The machine reads the input from left to right, one symbol at a time, and every symbol moves it along exactly one edge.
Another machine, for the strings over with an even number of s, run on (three s, so rejected). It has two states: one remembers "even so far", one "odd so far".
DFA for the strings over {a, b} with an even number of a's: start
Simulated, not typedDouble circle = accepting state. Arrow from nowhere = start state.
Step 0
Start in the start state E. The machine reads the input from left to right, one symbol at a time, and every symbol moves it along exactly one edge.
Reading a transition table
(An arrow marks the start state, a star an accepting state.) This is the machine of the first animation. To find : , an accepting state.
What a DFA can and cannot do
- Time and memory. It makes exactly one transition per input symbol: time , and its memory is its current state, a constant amount independent of the input. It can never "count" beyond what its finite number of states can remember: for example no DFA accepts (shown with the pumping lemma later).
- Remembering information. Each state stands for a set of strings with the same future: after reading and after reading the machine is in the same state only if every continuation gives the same verdict for and . Designing a DFA means deciding what must be remembered (design patterns).
- Examples. Binary numbers divisible by : the state is the remainder of the number read so far modulo ; reading the bit turns the value into , so the remainder becomes : three states. Strings with an even number of s: two states. Strings containing : four states (progress to with an absorbing accepting state).
How many DFAs are there?
For states and symbols the number of transition functions is (each of the table entries is one of states), there are choices of start state and choices of accepting set: labelled DFAs. For , : (many accept the same language). With the start state fixed there are .
Finite languages need dead states
A DFA for the language of all strings of length at most needs states: one for each length and a dead state for longer strings (checked by counting the distinguishable classes for ). In general a complete DFA for a finite language whose longest string has length needs at least states.
Worked examples
EX 1Which strings are accepted?
EasyThe DFA with of the table above. : , not accepting. : , accepted. : , rejected. : , accepted. : stays in , rejected. The language is .
EX 2Complete the DFA
EasyA diagram has states with the edges , , (and accepting, accepting) over . The edge is missing: reading an in kills the run. Completing it adds a dead state with and . The language is and the complete DFA has states.
EX 3Divisible by 3
MediumState remainder. Input (): (), (), : accepted, and is divisible by . Input (): () (): rejected. The empty string is read as and accepted.
EX 4Counting states and machines
MediumHow many different DFAs (as 5-tuples with states labelled ) are there with states over ? . With the start state fixed: . If the question asks for the number of different languages the answer is much smaller, because many machines accept the same language.
EX 5Typical statements
GATE level(a) A DFA with states accepts a string of length only if it visits some state twice: true (pigeonhole); this is the idea of the pumping lemma. (b) A DFA for can be turned into a DFA for by making the accepting states non-accepting and vice versa: true for a complete DFA (not for a partial one). (c) Every language accepted by a DFA is accepted by a DFA with exactly one accepting state: false (the language over : the start state must accept, and a single accepting state would have to loop on and so also accept ). (d) A DFA can have no accepting state: yes, it accepts . (e) The minimum number of states of a DFA accepting a finite language with longest string of length : . (f) Time to run a DFA on an input of length : .
Cheat box
Cheat box
- , total. . .
- Run: exactly transitions; one path; constant memory. Complete DFA: add a dead state for missing edges.
- Complement: flip accepting/non-accepting in a complete DFA.
- Number of DFAs: (start fixed: ).
- A finite language with longest string of length needs states (complete DFA).
- Divisible by (binary): remainder, , states. Even number of s: states.
- Regular language accepted by some DFA.
Traps and GATE patterns
Connections
Builds on
Unlocks
DFAs are drawn like the state machines of digital logic (state machines) but they have accepting states and no outputs. The lexical analyser of a compiler is a DFA (lexical analysis). Design methods are in design patterns; allowing choices gives the NFA, which accepts exactly the same languages.
PYQs
6 previous year questions from your book. I re-solved each one myself (6 by running or simulating, 0 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the following two finite automata D1 and D2 (as shown in the figure). Which of the following statements is/are true?
- (a). L(D1)=L(D2)
- (b). L(D1) is a proper subset of L(D2)
- (c). L(D1)∩L(D2)={ε}
- (d). (L(D1)∪L(D2))* consists of all strings in {0,1}* whose length is divisible by 3
Consider the following deterministic finite automaton
(DFA) defined over the alphabet, Σ = {a, b}. Identify which
of the following language(s) is/are accepted by the given
DFA.
THEORY OF COMPUTATION- (a)The set of all strings containing an even number of b's.
- (b)The set of all strings containing the pattern bab.
- (c)The set of all strings ending with the pattern bab.
- (d)The set of all strings not containing the pattern aba.
The above DFA accepts the set of all strings over {0,1}
that- (a)begin either with 0 or 1 .
- (b)end with 0.
- (c)end with 00.
- (d)contain the substring 00 THEORY OF COMPUTATION
If the final states and non-final states in the DFA
below are interchanged, then which of the following
languages over the alphabet {a, b} will be accepted
by the new DFA?- (a)Set of all strings that do not end with ab
- (b)Set of all strings that begin with either an a or a b
- (c)Set of all strings that do not contain the substring ab
- (d)The set described by the regular expression b*aa*(ba)*b*
In the automaton below,s is the start state and t is the only final state. Consider the strings u = abbaba, v = bab, and w = aabb. Which of the following statements is true?
- (a)The automaton accepts u and v but not w
- (b)The automaton accepts each of u, v, and w
- (c)The automaton rejects each of u, v, and w
- (d)The automaton accepts u but rejects v and w
Consider the machine M: THEORY OF COMPUTATION The language recognized by M is:
- (a){ w ∈ {a, b}* | every a in w is followed by exactly two b's }
- (b){ w ∈ {a, b}* | every a in w is followed by at least two b's }
- (c){ w ∈ {a, b}* | w contains the substring 'abb' }
- (d){ w ∈ {a, b}* | w does not contain 'aa' as a substring }
Self-check
Question 1
Give the transition table of a DFA over that accepts the strings whose length is a multiple of .
Show answerHide
Three states (start, accepting), , with .
Question 2
How many states does a complete DFA need for the language of all binary strings of length exactly ?
Show answerHide
: states for lengths and a dead state for longer strings.
Question 3
If , what can you say about and for every ?
Show answerHide
They end in the same state, so both are accepted or both rejected.
Question 4
How many DFAs with states over a one-letter alphabet exist (start state not fixed)?
Show answerHide
.
Revision card
One-screen revision
- 5-tuple, total, , ; run = one path of steps.
- Complete DFAs have a dead state; complement = flip (complete only).
- Number of DFAs ; finite language with longest string : states.
- Constant memory: cannot count unboundedly.
References
- ·Sipser, Introduction to the Theory of Computation (3rd edition), Section 1.1 Finite automata
- ·Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation (3rd edition), Section 2.2 Deterministic finite automata
- ·Kozen, Automata and Computability, Lecture 3 Deterministic finite automata
Verification
Every DFA drawn on this page was compared with an independent predicate (ends with 01, even number of a's, contains aba, binary number divisible by 3) on every string up to length 10; the runs of the animations were replayed by a separate simulation. The number of DFAs with n states over k symbols (n^(nk) transition functions, n start choices, 2^n accepting sets) was confirmed by enumeration for small n and k; the statement that a complete DFA for the finite language of all strings of length at most n needs exactly n + 2 states was confirmed for n up to 5 by counting Myhill-Nerode classes. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (state counts, derivations, parse-tree and move counts, decomposition counts); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)