Documente Academic
Documente Profesional
Documente Cultură
A simple model of
computation
Outline
Deterministic finite automata (DFA)
How a DFA works
How to construct a DFA
2301379
CONTROL
UNIT
is in exactly one
state at a time
Start state
Final state(s)
TAPE
HEAD
INPUT TAPE
Store input of the DFA
Can be of any length
Jaruloj Chongstitvatana
2301379
Jaruloj Chongstitvatana
2301379
2301379
Jaruloj Chongstitvatana
2301379
Example of a DFA
q
(q,a)
f
1
Transition diagram
Transition function
Jaruloj Chongstitvatana
2301379
a finite automaton.
a start state s in Q
a set of final states F contained in Q
a transition function is a function Q Q
2301379
How an FA works
0
f
1
Input: 001101
0 0 1 1 0 1
Input: 01001
Jaruloj Chongstitvatana
0 1 0 0 1
2301379
ACCEPT
REJECT
Configurations
Definition
Let M =(Q, , , s, F ) be a deterministic finite automaton.
A configuration of M is an element of Q
Current state
configurations of M
(s, ),
(s, 00),
(s, 01101),
(f, ),
(f, 0011011001),
(f, 1111), (f, 011110)
Jaruloj Chongstitvatana
2301379
f
1
Transition diagram of M
Chapter 2 Finite Automata
10
2301379
11
f
1
001101
Jaruloj Chongstitvatana
2301379
(s, 001101)
M (s, 01101)
M (s, 1101)
M (f, 101)
M (s, 01)
M (s, 1)
M (f, )
12
Jaruloj Chongstitvatana
2301379
13
f
1
(s, 01001)
(s, 001101)
*M (f, 101)
*M (f, 001)
*M (s, 01)
*M (f, 001)
*M (f, )
*M (f, 1)
*M (s, )
*M (f, )
Jaruloj Chongstitvatana
2301379
14
Accepting a string
Definition
2301379
15
f
1
Jaruloj Chongstitvatana
2301379
16
Example
0
0, 1
0
1
1
1
1
1
Jaruloj Chongstitvatana
2301379
1
0
0, 1
0
17
2301379
18
Jaruloj Chongstitvatana
2301379
19
Example
Got 00
and got 1
Got 00 as
substring
0
Got 0 as
substring
Got 00 and 11
as substrings
0, 1
0
1
s
Got
nothing
1
1
1
1
Got 1 as
substring
Jaruloj Chongstitvatana
Got 11 as
substring
2301379
1
0
0, 1
0
Got 11
and got 0
Chapter 2 Finite Automata
Got 11 and 00
as substrings
20
L = {0, 00, 11, 000, 011, 110, 0000, 0011, 0110, 1001, 00000, ...}.
remembering that the portion of the string that has been read so far is
divisible by 3
Choose this!!
Why?
Jaruloj Chongstitvatana
2301379
21
Using 2 states
Jaruloj Chongstitvatana
2301379
22
Using 3 states
Jaruloj Chongstitvatana
2301379
23
Current
remainder
Next
symbol
New
number
New
remainder
3n
6n
3n
6n+1
3n+1
6n+2
3n+1
6n+3
3n+2
6n+4
3n+2
6n+5
Jaruloj Chongstitvatana
2301379
24
Transition table
Current
number
Current
Current
state
remainder
Next
symbol
New
number
New
Next
state
remainder
3n
6n
3n
6n+1
3n+1
6n+2
3n+1
6n+3
3n+2
6n+4
3n+2
6n+5
Jaruloj Chongstitvatana
2301379
25
Example DFA
Current
state
Next
symbol
Next
state
q0
q0
q0
q1
q1
q2
q1
q2
q1
q2
q2
Jaruloj Chongstitvatana
q0
2301379
q0
1
1
1
0
q1
q2
26
Nondeterministic move
On reading an input symbol, the automaton can choose to
make a transition to one of selected states. 0
0
Jaruloj Chongstitvatana
2301379
27
a start state s in Q
a set of final states F contained in Q
a transition function is a function Q({})2Q
2301379
28
Example of NFA
An NFA accepting {w{0,1} |w ends with 11}
1
DFA
0
1
0
0,1
1
Jaruloj Chongstitvatana
1
2301379
29
Jaruloj Chongstitvatana
2301379
30
2301379
31
Accepting a string
Definition
Jaruloj Chongstitvatana
2301379
32
Same as the
definition for
a DFA
Jaruloj Chongstitvatana
2301379
33
0,1
s, 1111
s, 111
Jaruloj Chongstitvatana
2301379
s, 01111
s, 11
s, 1
s,
q,
q, 111
q, 11 f, 11
q, 1
f, 1
f,
34
0,1
0,1
0,1
0
0,1
0,1
0,1
Jaruloj Chongstitvatana
0,1
2301379
35
Jaruloj Chongstitvatana
2301379
36
2301379
37
Finally, prove
f F (s,) |-*Mn (f, )
f 'F ' (E(s), ) |-*Md (f ' , ).
Jaruloj Chongstitvatana
2301379
38
0,1
s
0
Jaruloj Chongstitvatana
2301379
s,q
s,q,f
39
r
s
f
1
p,q, r
0 ,1
r
Jaruloj Chongstitvatana
2301379
0,1
p,q,r,f
40
Closure of state q
Let M = (Q, , , s, F) be an NFA, and qQ.
2301379
41
Example of closure
M=({s, q, f}, {a, b, c}, , s, {f})
where is defined below.
a
state
closure
s, q, f
q, f
f
L(M)={ai bj ck | i, j, k 0}
Jaruloj Chongstitvatana
2301379
42
q0
a
q1
q3
1 q1
b
a
a
q1
q2
q2 , q3
q3
2 q2 , q3
3
q2
b
q0
q2
q1 q0 ,q4
q4
q2
q1
q2, q3
q4
q3 q4
q4
Jaruloj Chongstitvatana
q3 q4
2301379
q3
43
F' = {f Q | f F })
a
q
Jaruloj Chongstitvatana
DFA
2301379
44
E(q0)
q3
q2
q0, q1,
q2, q3
E(q1)
E(q2) E(q3)
q1, q2, q2
q3
q3
E(q4)
q3,q4
b
q4
Jaruloj Chongstitvatana
2301379
45
q3
q0,q1,q2,q3
a
q3,q4
a
q0,q1,q2,q3,q4
(q,a,r)
q0
q1
q2
q0 q4
q2
q3
(q,b,r) (q,,r)
q1
q2 q3
q4
q4
a
q2,q3,q4
a
b
q3,q4
a,b
q4
Jaruloj Chongstitvatana
q3
2301379
46
F' = {f Q | f F }
Prove , fF (s,) |-*Mn (f, ) f 'F ' (E(s), )
|-*Md (f', ) and ff' by induction.
2301379
47
Proof
Part I:
Jaruloj Chongstitvatana
2301379
48
Proof
Basis:
2301379
49
Proof
Induction hypothesis:
For any non-negative integer k, string in *, and
states q and r in Q, there exists R Q:
(q, ) *Mn (r, ) in k steps -> (E(q), ) *Md (R, ) and
rR.
Induction step:
Prove, for any non-negative integer k, string in *,
and states q and r in Q, there exists R Q:
(q, ) *Mn (r, ) in k+1 steps -> (E(q), ) *Md (R, )
and rR.
Jaruloj Chongstitvatana
2301379
50
Proof
Let be a string in *, q and r be states in Q,
and (q, ) *Mn (r, ) in k+1 steps.
Because (q, ) *Mn (r, ) in k+1 steps and k0,
there exists a state p in Q and a string *
such that (q, ) *Mn (p, a) in k steps and (p, a)
Mn (r, ) for some a {}.
Jaruloj Chongstitvatana
2301379
51
Proof
From the induction hypothesis and (q, ) *Mn (p, a) in
k steps, we know that there exists PQ such that
(E(q), ) *Md (P, a) and pP.
Since (p, a) Mn (r, ), r(p, a).
2301379
52
Proof
Part II:
For any string in *, and states q and r in Q, there exists R Q
such that rR and
(E(q), ) *Md (R, ) -> (q, ) *Mn (r, ).
E(q)
Jaruloj Chongstitvatana
2301379
rR
53
Proof
Basis:
2301379
54
Proof
Induction hypothesis:
Induction step:
Prove, for any non-negative integer k, string in *, and
states q and r in Q, there exists R Q such that rR:
Jaruloj Chongstitvatana
2301379
55
Proof
Let be a string in *, q and r be states in Q, and (E(q), ) *Md
(R, ) in k+1 steps.
Because (E(q), ) *Md (R, ) in k+1 steps and k0, there exists
P2Q (i.e. PQ) and a string * such that =a, (E(q), )
*Md (P,) in k steps and (P, a) Md (R, ) for some a.
E(q)
q
Jaruloj Chongstitvatana
2301379
k+1 steps
rR
56
Proof
From the induction hypothesis and (E(q), ) *Md (P, ) in k
steps, we know that there exists pP such that (q, )*Mn(p,)
(i.e. (q, a) *Mn (p, a) ).
Since (P, a) Md (R, ), there exists rR such that r= (p, a).
Then, for some rR, (p, a) *Mn (r, ).
Thus, (q, ) *Mn (p, a) *Mn (r, ) for some rR.
E(q)
pP
a
p
q
Jaruloj Chongstitvatana
2301379
k+1 steps
rR
57
Closure Properties
The class of languages accepted by FAs is
closed under the operations
Union
Concatenation
Complementation
Kleenes star
Intersection
Jaruloj Chongstitvatana
2301379
58
sA
Let MA = (QA, , A, sA, FA) and
2301379
59
Proof
To prove L(M) = L(MA) L(MB), we prove:
I. For any string * L(MA) or L(MB) L(M) &
II. For any string * L(MA) and L(MB). L(M)
For I, consider (a) L(MA) or (b) L(MB).
For (a), let L(MA).
From the definition of strings accepted by an FA, there is a
state fA in FA such that (sA, ) |-*MA (fA, ).
Because A,
(sA, ) |-*M (fA, ) also.
sA
Because sA(s,), (s, ) |-M (sA, ).
sB
Similarly for (b).
Jaruloj Chongstitvatana
2301379
60
Proof
For (II), let L(MA)L(MB).
Because (s, , {sA, sB}), either (s,) |-M (sA,) or (s, ) |-M (sB, ) only.
Because L(MA), there exists no fA in FA such that (sA,) |-*MA (fA,).
sA
sB
Jaruloj Chongstitvatana
2301379
61
sA
sB
MB
MA
Jaruloj Chongstitvatana
2301379
62
sA
MA
DFA only
Jaruloj Chongstitvatana
2301379
63
sA
fA
Jaruloj Chongstitvatana
2301379
64
2301379
65
2301379
66
Example
p0,q0
q0
p1,q1
p0,q1
1
1
0
q1
1
0
p0,q2
q2
p1,q0
1
0,1
p0
Jaruloj Chongstitvatana
p1
2301379
p2
p2,q0
p1,q2
1
p2,q1
Chapter 2 Finite Automata
p2,q2
67
Check list
Basic
Advanced
Configuration change
etc.
2301379
Surprise!
Chapter 2 Finite Automata
68