Documente Academic
Documente Profesional
Documente Cultură
Fall 2009
Automata theory
and formal languages
Andrej Bogdanov
http://www.cse.cuhk.edu.hk/~andrejb/csc3130
What else?
Recommend
books
Fly
airplanes
Impossibilities
Perpetual motion
In the middle ages, people
wanted a machine that does not
use any energy
Later, discoveries in physics
showed that energy cannot be
created out of thin air
Perpetual motion is a futile
endeavor
Automata theory
Automata theory studies the laws of
computation.
A simple computer
H
ITC
W
S
BATTERY
input: switch
output: light bulb
actions: flip
switch
states: on, of
A simple computer
H
ITC
W
S
f
BATTERY
start
on
of
f
input: switch
output: light bulb
actions: f for flip
switch
states: on, of
Another computer
1
1
start
of
BATTERY
1
of
1
2
of
on
A design problem
1
4
5
BATTERY
2
3
A design problem
Such devices are difficult to reason about,
because they can be designed in an infinite
number of ways
f
on
of
f
Turing
Machines
time-bounded
Turing
Machines
Push-down automata
These devices are related to grammars, which
describe the structure of programming (and
natural) languages
banana
Xian
Shanghai
Guangzhou
Hong Kong
Problems
Examples of problems we will consider
Strings
A string over alphabet is a finite sequence
of symbols in .
The empty string will be denoted by
Examples
abfbz is a string over 1 = {a, b, c, d, , z}
9021 is a string over 2 = {0, 1, , 9}
ab#bc is a string over 3 = {a, b, , z, #}
))()(() is a string over 4 = {(, )}
Languages
Finite Automata
of
f
Example
0
q0
1
1
q1
0,1
0
q2
states
table of
alphabet = {0, 1}
transition function
states Q = {q0, q1, q2}
inputs
initial state q0
0 1
accepting states F = {q0, q1}
q0 q0 q1
q1 q2 q1
q2 q2 q2
Language of a DFA
M:
on
of
f
Examples
= {0, 1}
0
q0
q1
q1
b
b
0
q0
1
1
q3
a
q1
q2
q2
b
b
q4
1
1
= {a, b}
q0
0,
1
Examples
Construct a DFA over alphabet {0, 1} that
accepts all strings with at most three 1s
Examples
Construct a DFA over alphabet {0, 1} that
accepts all strings with at most three 1s
Answer
0
0
q0
q1
0
1
q2
0
1
q3
0,
1
q4+
Examples
Construct a DFA that accepts the language
L = {010,
1}
( = {0, 1}
)
Examples
Construct a DFA that accepts the language
( = {0, 1}
)
L = {010,
1}
Answer
0
q0
1
0
q01
q010
1
0, 1
q1
0, 1
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:
q
1
1
0
q
q