Automata Theory and Formal Languages
Automata Theory and Formal Languages
BATTERY
input: switch
output: light bulb
actions: flip switch
states: on, off
A simple “computer”
input: switch
output: light bulb bulb is on if and only if
there was an odd number
actions: f for “flip switch” of flips
states: on, off
Another “computer” 1
1 start off off
1
2 2 2 2
BATTERY
1
2
off on
1
?
5
BATTERY
Xian
Chengdu Shanghai
Guangzhou
Hong Kong
Easy in principle: Try the cities in every possible order
Hard in practice: For 100 cities, this would take 100+ years
even on the fastest computer!
Preliminaries of automata theory
How do we formalize the question
off on
There are states off and on, the automaton starts in off and tries
to reach the “final state” on
What sequences of fs lead to the final state?
Answer: {f, fff, fffff, …} = {f n: n is odd}
This is an example of a deterministic finite automaton over
alphabet Σ={f}
Deterministic finite automata
q0 1 q1 0 q2
states
q1 q2 q1
q2 q2 q2
Language of a DFA
The language of a DFA M=(Q, S, d, q0, F) is the set of
all strings over S that, starting from q0 and
following the transitions as the string is read from left
to right, will reach some accepting state.
M: off on
0 1
1
q0 q1
0
0 1 0,1
q0 1 q1 0 q2
L = {010, 1} ( S = {0, 1} )
Examples
Construct a DFA that accepts the language
L = {010, 1} ( S = {0, 1} )
Answer
q0 1 q01 0 q010
0
0 1
qe 0, 1
1 0, 1
q1 qdie
0, 1
Examples
Construct a DFA over alphabet {0, 1} that accepts all strings
that end in 101
Examples
Construct a DFA over alphabet {0, 1} that accepts all strings
that end in 101
Hint: The DFA must “remember” the last 3 bits of the string
it is reading
Examples
Construct a DFA over alphabet {0, 1} that accepts all strings
that end in 101
Sketch of answer: 0
1
0 0 q2 1
q3
1 q1
q0
0 1