COMS W3261
Computer Science Theory
Lecture 3: September 12, 2012
Finite Automata
Outline
- Review
- Deterministic finite automata
- Examples of DFAs
- Nondeterministic finite automata
- Equivalence of DFAs and NFAs: the Subset Construction
- Bad Case for the Subset Construction
1. Review
- Operations on languages
- Regular expressions
2. Deterministic Finite Automata
- A deterministic finite automaton (DFA) is one of the simplest models of computation.
- DFAs and regular expressions are equivalent ways of representing regular languages.
We will soon see that every regular language can be represented by a regular expression or a DFA.
- A DFA has five components:
- A finite set of states Q.
- An input alphabet consisting of a finite set of symbols Σ.
- A transition function δ that maps Q × Σ to Q.
This transition function can be represented by a transition diagram
in which the nodes are labeled by states and arcs by symbols.
- A start state which is one of the states in Q.
- A set of final (or accepting) states F.
- A DFA accepts an input string x if there is a path of transitions
from the initial state to a final state that spells out x.
- L(A), the language defined by a DFA A is the set of
strings accepted by A.
- A language accepted by a DFA is called a regular language.
3. Example DFA for 0*10*
- Consider the following DFA D with:
- The finite set of states Q = {
A, B, C}
- The input alphabet Σ = {
0, 1}
- The transition function δ as represented by the following
transition table:
State |
Input Symbol |
0 |
1 |
A |
A |
B |
B |
B |
C |
C |
C |
C |
- Start state
A
- The set of final states F = {
B}
- Given the input string
0010, D makes the following transitions
started off in its initial start state A:
- 0 0 1 0
- A A A B B
- This sequence of transitions takes D from its start state
A to the final state B.
Thus, the input 0010 is accepted by D.
- Given the input string
101, D makes the following transitions
started off in its initial start state A:
- 1 0 1
- A B B C
- This sequence of transitions takes D from its start state
A to the nonfinal state B.
Therefore, the input 101 is not accepted by D.
- The language defined by D is the set of strings of 0's and 1's having exactly
one 1.
- The regular expression 0*10* defines the same language.
4. Example DFA for Binary Numbers Divisible by 3
- We want a DFA to recognize all strings of
0's and 1's representing binary numbers divisible by three.
We assume the empty string represents 0, 0 represents 0, 1 represents 1,
00 represents 0, 01 represents 1, 10 represents 2, 11 represents 3, and so on.
- Consider the following DFA D with:
- The finite set of states Q = {
A, B, C}
- The input alphabet Σ = {
0, 1}
- The transition function δ as represented by the following
transition table:
State |
Input Symbol |
0 |
1 |
A |
A |
B |
B |
C |
A |
C |
B |
C |
- Start state
A
- The set of final states F = {
A}
- State A represents all prefixes of binary strings that are congruent to 0 mod 3,
state B all prefixes congruent to 1 mod 3, and
state C all prefixes congruent to 2 mod 3.
- Given the input string
0010, D makes the following transitions
started off in its initial start state A:
- 1 0 0 1
- A B C B A
- This sequence of transitions takes D from its start state
A to the final state A.
Thus, the binary input 1001, which represents 9, is accepted by D.
5. Nondeterministic Finite Automata
- A nondeterministic finite automaton (NFA) consists of
- A finite set of states Q.
- An input alphabet consisting of a finite set of symbols Σ.
- A transition function δ that maps Q × Σ to
P(Q), the set of subsets of Q.
Like a DFA, this transition function can be represented by a transition diagram
in which the nodes are labeled by states and arcs by symbols.
Unlike a DFA, an NFA may have transitions to zero or more states from
a given state on a given input symbol.
- A start state that is one of the states in Q.
- A set of final (or accepting) states F.
F is a subset of Q.
- An NFA accepts an input string x if there is a path of transitions
from the initial state to a final state that spells out x.
Note that, unlike for a DFA, in an NFA there may be more than one path from
the initial state to a final state that spells out x.
- Note the definition of an extended transition function
for an NFA. See Sect 2.3.3 of HMU.
- L(A), the language defined by an NFA A is the set of
strings accepted by A.
6. Equivalence of DFAs and NFAs: the Subset Construction
- From an NFA N =
(QN, Σ, δN, q0, FN),
we can construct a DFA D =
(QD, Σ, δD, {q0}, FD)
that simulates all possible moves of N on any given input.
- QD is the set of all subsets of QN.
- The input alphabet of D is the same as that of N.
- For each state S in QN and each input symbol a in Σ,
- δD(S,a) is the union of all states in
δN(p,a) for all p in S.
- The start state of D is the state {q0}.
- FD, the final states of D, are those states of QD that
contain a state in FN.
- We can prove by induction on the length of an input string w that D can reach
deterministic state S in QD on w iff N can reach each
nondeterministic state p in S on w. See Sect. 2.3.5 of HMU.
7. Bad Case for the Subset Construction
- Let L be the language (a+b)*a(a+b)n-1, that is,
all strings of a's and b's in which the nth
character from the end is an "a". The smallest DFA that accepts L must
have at least 2n states.
8. Practice Problems
- Construct a DFA for a light switch.
- Let L be the language
{
w | w is any string of a's and
b's containing at least one a and
at least one b }.
- Construct a DFA for L.
- Show the behavior of your DFA processing the input string
aabaa.
- Construct a regular expression for L.
- Let L be the language
{
abxba | x is any string of a's,
b's, and c's not containing ba }.
This language models comments in the programming language C.
- Construct a DFA for L.
- Show the behavior of your DFA processing the input string
abcbaba.
- Construct a regular expression for L.
- Show how your regular expression generates
ababcba.
- Construct a DFA for the language L(
(a+b)*abba(a+b)*).
- Let L be the language consisting of all strings of
a's
and b's having an even number of a's and an
even number of b's.
- Construct a DFA for L.
- Show the behavior of your DFA processing the input string
abbaabab.
- Construct a regular expression for L.
- Show how your regular expression generates
abbaabab.
- Construct an NFA that accepts all strings of a's and b's ending in abb.
- Show all sequences of moves that your NFA can make on the input string ababb.
- Use the subset construction to convert your NFA into an equivalent DFA.
- Construct an NFA that accepts (a+b)*a(a+b)(a+b).
- Use the subset construction to convert your NFA into an equivalent DFA.
9. Reading Assignment
aho@cs.columbia.edu