Sunteți pe pagina 1din 68

Finite Automata

A simple model of
computation
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 2
Outline
Deterministic finite automata (DFA)
How a DFA works
How to construct a DFA
Non-deterministic finite automata (NFA)
How an NFA works
How to construct an NFA
Equivalence of DFA and NFA
Closure properties of the class of languages
accepted by FA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 3
Finite Automata (FA)
CONTROL
UNIT
INPUT TAPE
TAPE
HEAD
Finite set of states
Move to the right one cell
at a time
Store input of the DFA
Can be of any length
Start state
Final state(s)
is in exactly one
state at a time
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 4
What does an FA do?
Read an input string from tape
Determine if the input string is in a language
Determine if the answer for the problem is
YES or NO for the given input on the tape
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 5
How does an FA work?
At the beginning,
an FA is in the start state (initial state)
its tape head points at the first cell
For each move, FA
reads the symbol under its tape head
changes its state (according to the transition function) to
the next state determined by the symbol read from the
tape and its current state
move its tape head to the right one cell
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 6
When does an FA stop working?
When it reads all symbols on the tape
Then, it gives an answer if the input is in the
specific language:
Answer YES if its last state is a final state
Answer NO if its last state is not a final state
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 7
Example of a DFA
q a o(q,a)
s 0 s
s 1 f
f 0 f
f 1 s
s
f
0 1
0
1
Transition diagram
Transition function
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 8
How to define a DFA
a 5-tuple (Q, L, o, s, F), where
a set of states Q is a finite set
an alphabet L is a finite, non-empty set
a start state s in Q
a set of final states F contained in Q
a transition function o is a function Q - L Q
See formal definition
Thats why its called
a finite automaton.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 9
How an FA works
s
f
0 1
0
1
Input: 001101
Input: 01001
0 0 1 1 0 1
0 1 0 0 1
ACCEPT
REJECT
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 10
Configurations
Definition
Let M =(Q, L, o, s, F ) be a deterministic finite
automaton.
A configuration of M is an element of Q - L
-
configurations of M
(s, s), (s, 00),
(s, 01101), (f, s),
(f, 0011011001),
(f, 1111), (f, 011110)
s
f
0 1
0
1
Transition diagram of M
Unread input string
Current state
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 11
Yielding next configuration
Definition
Let M = (Q, L, o, s, F ) be a deterministic finite automaton,
and (q
0
,
0
) and (q
1
,
1
) be two configurations of M.
We say (q
0
,
0
) yields (q
1
,
1
) in one step, denoted by (q
0
,

0
)
M
(q
1
,
1
), if o(q
0
, a) = q
1
, and
0
=a
1
, for some a L.
When a configuration yields another configuration, the first
symbol of the string is read and discarded from the
configuration.
Once a symbol in an input string is read, it does not effect
how the DFA works in the future.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 12
Example: yielding next
configuration
(s, 001101)

M
(s, 01101)

M
(s, 1101)

M
(f, 101)

M
(s, 01)

M
(s, 1)

M
(f, s)
s
f
0 1
0
1
0 0 1 1 0 1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 13
Yield in zero step or more
Definition
Let M = (Q, L, o, s, F) be a DFA, and (q
0
,
0
) and
(q
1
,
1
) be two configurations of M. (q
0
,
0
) yields
(q
1
,
1
) in zero step or more, denoted by (q
0
,
0
)
*
M
(q
1
,
1
), if
q
0
= q
1
and
0
=
1
, or
(q
0
,
0
)
M
(q
2
,
2
) and (q
2
,
2
) *
M
(q
1
,
1
) for
some q
2
and
2
.
This definition is an inductive definition, and it is often
used to prove properties of DFAs.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 14
Example: Yield in zero step or
more
(s, 001101)
*
M
(f, 101)
*
M
(s, 01)
*
M
(f, s)
*
M

(f, s)
s
f
0 1
0
1
(s, 01001)
*
M
(f, 001)
*
M
(f, 001)
*
M
(f, 1)
*
M
(s, s)
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 15
Accepting a string
Definition
Let M = (Q, L, o, s, F) be a DFA, and L*.
We say M accepts if (s, ) *
M
(f, s), when f
F. Otherwise, we say M rejects .
(s, 001101) *
M

(f, s) M accepts 001101
(s, 01001) *
M
(s, s) M rejects 01001
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 16
Language accepted by a DFA
Let M = (Q, L, o, s, F ) be a DFA. The language accepted
by M, denoted by L(M ) is the set of strings accepted by M.
That is, L(M) = {L*|(s, ) *
M
(f, s) for some f F }
Example:
L(M) = {x {0,1}* | the number of 1s in x is odd}.
s
f
0 1
0
1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 17
Example
s
0
1
1
1
1
1
1
1
0
0
0
0
0
0, 1
0
0, 1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 18
How to construct a DFA
Determine what a DFA need to memorize in order to
recognize strings in the language.
Hint: the property of the strings in the language
Determine how many states are required to memorize
what we want.
final state(s) memorizes the property of the strings in the
language.
Find out how the thing we memorize is changed once
the next input symbol is read.
From this change, we get the transition function.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 19
Constructing a DFA: Example
Consider L= {{0,1}*| has both 00 and 11 as
substrings}.
Step 1: decide what a DFA need to memorize
Step 2: how many states do we need?
Step 3: construct the transition diagram
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 20
Example
s
0
1
1
1
1
1
1
1
0
0
0
0
0
0, 1
0
0, 1
Got
nothing
Got 0 as
substring
Got 00 as
substring
Got 11
and got 0
Got 00 and 11
as substrings
Got 1 as
substring
Got 11 as
substring
Got 00
and got 1
Got 11 and 00
as substrings
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 21
Constructing a DFA: Example
Consider L= {{0,1}*| represents a binary number divisible by
3}.
L = {0, 00, 11, 000, 011, 110, 0000, 0011, 0110, 1001, 00000, ...}.
Step 1: decide what a DFA need to memorize
remembering that the portion of the string that has been read so far is
divisible by 3
Step 2: how many states do we need?
2 states remembering that
the string that has been read is divisible by 3
the string that has been read is indivisible by 3.
3 states remembering that
the string that has been read is divisible by 3
the string that has been read - 1 is divisible by 3.
the string that has been read - 2 is divisible by 3.
Choose this!!
Why?
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 22
Using 2 states
Reading a string w representing a number divisible
by 3.
Next symbol is 0. w 0, which is 2*w, is also divisible by
3.
If w=9 is divisible by 3, so is 2*w=18.
Next symbol is 1. w 1, which is 2*w +1, may or may
not be divisible by 3.
If 8 is indivisible by 3, so is 17.
If 4 is indivisible by 3, but 9 is divisible.
Using these two states is not sufficient.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 23
Using 3 states
Each state remembers the remainder of the
number divided by 3.
If the portion of the string that has been read so
far, say w, represents the number whose
remainder is 0 (or, 1, or 2),
If the next symbol is 0, what is the remainder of w 0?
If the next symbol is 1, what is the remainder of w 1?
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 24
How remainder changes
Current
number
Current
remainder
Next
symbol
New
number
New
remainder
3n 0 0 6n 0
3n 0 1 6n+1 1
3n+1 1 0 6n+2 2
3n+1 1 1 6n+3 0
3n+2 2 0 6n+4 1
3n+2 2 1 6n+5 2
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 25
Transition table
Current
number
Current
remainder
Next
symbol
New
number
New
remainder
3n 0 0 6n 0
3n 0 1 6n+1 1
3n+1 1 0 6n+2 2
3n+1 1 1 6n+3 0
3n+2 2 0 6n+4 1
3n+2 2 1 6n+5 2
Current
state
Next
state
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 26
Example DFA
Current
state
Next
symbol
Next
state
q
0
0 q
0
q
0
1 q
1
q
1
0 q
2
q
1
1 q
0
q
2
0 q
1
q
2
1 q
2
M= ({q
0
, q
1
, q
2
}, {0, 1},
o, q
0
, {q
0
})
q
0
q
1
q
2
0
1
0
0
1
1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 27
Nondeterministic Finite
Automata
Similar to DFA
Nondeterministic move
On reading an input symbol, the automaton can choose to
make a transition to one of selected states.
Without reading any symbol, the automaton can choose
to make a transition to one of selected states or not.
0
0
s
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 28
How to define an NFA
a 5-tuple (Q, L, o, s, F), where
a set of states Q is a finite set
an alphabet L is a finite, non-empty set
a start state s in Q
a set of final states F contained in Q
a transition function o is a function Q-(L{s})2
Q
See formal definition
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 29
Example of NFA
An NFA accepting {w{0,1}
-
|w ends with 11}
0,1
1 1
0
0 0
1
1
1
0
1
1
0
1 0
1
0
DFA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 30
Yielding next configuration
Definition
Let M = (Q, L, o, s, F) be a non-deterministic
finite automaton, and (q
0
,
0
) and (q
1
,
1
) be two
configurations of M.
We say (q
0
,
0
) yields (q
1
,
1
) in one step,
denoted by (q
0
,
0
)
M
(q
1
,
1
), if q
1
o (q
0
, a,),
and
0
=a
1
, for some a L {s}.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 31
Yield in zero step or more
Definition
Let M = (Q, L, o, s, F) be an NFA, and (q
0
,
0
)
and (q
1
,
1
) be two configurations of M. (q
0
,

0
) yields (q
1
,
1
) in zero step or more,
denoted by (q
0
,
0
) *
M
(q
1
,
1
), if
q
0
= q
1
and
0
=
1
, or
(q
0
,
0
)
M
(q
2
,
2
) and (q
2
,
2
) *
M
(q
1
,

1
) for some q
2
and
2
.
Same as that for DFA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 32
Accepting a string
Definition
Let M = (Q, L, o, s, F) be an NFA, and
L*. We say M accepts if (s, ) *
M
(f, s),
when f F. Otherwise, we say M rejects .
Same as the
definition for
a DFA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 33
Language accepted by an NFA
Let M = (Q, L, o, s, F) be an NFA.
The language accepted by M, denoted by
L(M) is the set of strings accepted by M. That
is, L(M) = {L*| (s,) *
M
(f, s) for some
fF}
Same as the
definition for
a DFA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 34
How NFAs work
(s,01111) - (s,1111) - (s,111)
- (s,11) - (s,1) - (s,s)
(s,01111) - (s,1111) - (s, 111)
- (s,11) - (s,1) - (q,s)
(s,01111) - (s, 1111) - (s, 111)
- (s,11) - (q,1) - (f, s)
(s,01111) - (s, 1111) - (s, 111)
- (q,11) - (f,1)
(s,01111) - (s, 1111) - (q, 111)
- (f,11)
0,1
1 1
s, 01111
s q f
s, 1111
s, 111 q, 111
s, 11
f, s
q, 1
q, 11
s, s
s, 1
q, s
f, 1
f, 11
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 35
Other examples of NFA
{w {0,1}* | w has either 00
or 11 as substring}
{w {0,1}* | w has 00 and
11 as substrings and 00
comes before 11}
0,1
0
0,1
0,1
1 1
0
s
s
0
1 1
0
s
0,1
0,1
0,1
0,1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 36
DFA and NFA are equivalent
M
d
and M
n
are equivalent L(M
d
) = L(M
n
).
DFA and NFA are equivalent
For any DFA M
d
, there exists an NFA M
n
such that
M
d
and M
n
are equivalent. (part 1)
For any NFA M
n
, there exists a DFA M
d
such that M
d
and M
n
are equivalent. (part 2)
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 37
Part 1 of the equivalence proof
For any DFA M
d
, there exists an NFA M
n
such that
M
d
and M
n
are equivalent.
Proof: Let M
d
be any DFA. We want to construct an
NFA M
n
such that L(M
n
) = L(M
d
).
From the definitions of DFA and NFA, if M is a DFA
then it is also an NFA.
Then, we let M
n
= M
d
.
Thus, L(M
d
) = L(M
n
).
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 38
Part 2 of the equivalence proof
For any NFA M
n
, there exists a DFA M
d
such that
M
d
and M
n
are equivalent.
Proof: Let M
n
= (Q, L, o, s, F) be any NFA. We want to
construct a DFA M
d
such that L(M
d
) = L(M
n
).
First define the closure of q, denoted by E(q).
Second, construct a DFA M
d
=(2
Q
, L, o', E(s), F')
Finally, prove V L
-
n f F (s,) |-
*
Mn
(f, s)
n f 'F ' (E(s), ) |-
*
Md
(f ' , s).
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 39
Eliminating transitions to multiple
states
s q f
0,1
1 1
s s,q
1
s,q,f
1
0
0
1
0
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 40
Eliminating empty-string
transitions
s p q
r f
0
0
0

,1
1
1 1

s p,q, r
r p,q,r,f
0
0,1
1
1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 41
Closure of state q
Let M = (Q, L, o, s, F) be an NFA, and qQ.
The closure of q, denoted by E(q), is
the set of states which can be reached from q
without reading any symbol.
{pQ| (q, s) |-
M
*
(p, s)}
If an NFA is in a state q, it can also be in any
state in the closure of q without reading any
input symbol.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 42
Example of closure
s q f
a b c
s s
M=({s, q, f}, {a, b, c}, o, s, {f})
where o is defined below.
L(M)={a
i
b
j
c
k
| i, j, k > 0}
state closure
s q f s, q, f
q f q, f
f f
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 43
Another example of closure
q
0
q
1
q
2
q
3
q
4
1 q
1
q
2
, q
3
q
3
2 q
2
, q
3
3
q (q,a,r) (q,b,r) (q,e,r)
q
0
q
2
q
1
q
1
q
0
,q
4
q
2
, q
3
q
2
q
4
q
3
q
4
q
4
q
3
q
0
q
1
q
2
q
3
q
4
b
e
e
e
a
b
e
a
a
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 44
Constructing the equivalent
DFA
Let M
n
= (Q, L, o, s, F) be any NFA. We construct a
DFA M
d
=(2
Q
, L, o', E(s), F'), where :
o'(q',a) = {rE(p)| p o(q,a) } and
F' = {f _ Q | f F = })
qq'
q
p r
a
a

DFA
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 45
Example of DFA construction
E(q
0
) E(q
1
) E(q
2
) E(q
3
) E(q
4
)
q
0
, q
1
,
q
2
, q
3
q
1
, q
2
,
q
3
q
2
q
3
q
3
,q
4
q
0
q
1
q
2
q
3
q
4
b
s
s
s
a
b
s
a
a
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 46
Example of DFA construction
q
0
,q
1
,q
2
,q
3
q
0
,q
1
,q
2
,q
3
,q
4
q
2
,q
3
,q
4
q
3
,q
4

a
b
b
a
a
b
b
a
a,b
E(q
0
) E(q
1
) E(q
2
) E(q
3
) E(q
4
)
q
0
, q
1
,
q
2
, q
3
q
1
,
q
2
, q
3
q
2
q
3
q
3
,q
4
o (q,a,r) (q,b,r) (q,e,r)
q
0
q
2
q
1
q
1
q
0
q
4
q
2
q
3
q
2
q
4
q
3
q
4
q
4
q
3
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 47
Prove property of o and o'
Let M
n
= (Q, L, o, s, F) be any NFA, and M
d
= (2
Q
, L, o',
E(s), F') be a DFA, where
o'(q', a) = {rE(p)| po(q,a)} and
F' = {f _ Q | f F = }
Prove V L
-
, n fF (s,) |-
*
Mn
(f, s) n f 'F ' (E(s), )
|-
*
Md
(f', s) and ff' by induction.
Prove a more general statement V L
-
, V p, qQ
(p,) |-
*
Mn
(q, s) (E(p), ) |-
*
Md
(q', s) and qq'.
qq'
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 48
Proof
Part I:
For any string in *, and states q and r in Q,
there exists R _ Q such that
(q, ) *
Mn
(r, ) (E(q), ) *
Md
(R, ) and
rR.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 49
Proof
Basis:
Let be a string in *, q and r be states in Q, and (q,
) *
Mn
(r, ) in 0 step.
Because (q, ) *
Mn
(r, ) in 0 step, we know (1) q=r ,
and (2) = .
Then, (E(q), ) = (E(r), ).
Thus, (E(q), ) *
Md
(E(r), ) .
That is, there exists R=E(r) such that r R and
(E(q),) *
Md
(R, ).
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 50
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 Chapter 2 Finite Automata 51
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 k>0,
there exists a state p in Q and a string E*
such that (q, ) *
Mn
(p, a) in k steps and (p, a)

Mn
(r, ) for some a {}.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 52
Proof
From the induction hypothesis and (q, ) *
Mn
(p, a) in
k steps, we know that there exists P_Q such that
(E(q), ) *
Md
(P, a) and pP.
Since (p, a)
Mn
(r, ), ro(p, a).
From the definition of o'of M
d
, E(o(p, a)) _ o'(P, a)
because pP.
Because ro(p, a) and E(o(p, a)) _ o'(P, a), ro'(P,
a).
Then, for R=o'(P, a), (P, a) *
Md
(R, ) and rR.
Thus, (E(q), ) *
Md
(P, a) *
Md
(R, ) and rR.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 53
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)
R
q
r
rR
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 54
Proof
Basis:
Let be a string in *, q and r be states in Q, R be a
subset of Q such that r R and (E(q), ) *
Md
(R, )
in 0 step.
Because (E(q),) *
Md
(R, ) in 0 step, E(q)=R and =.
From the definition of E, o'(q, )=R because E(q)=R.
Then, for any rR, (q, ) *
Mn
(r, ).
That is, there exists R=E(q) such that r R and (q, )
*
Mn
(r, ).
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 55
Proof
Induction hypothesis:
For any non-negative integer k, string in *, and states
q and r in Q, there exists R _ Q such that rR and:
(E(q), ) *
Md
(R, ) in k steps ->(q, ) *
Mn
(r, ).
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:
(E(q),)*
Md
(R, ) in k+1 steps ->(q, ) *
Mn
(r, ).
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 56
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 k>0, there exists
P2
Q
(i.e. P_Q) and a string E* such that =Ea, (E(q), E)
*
Md
(P,) in k steps and (P, a)
Md
(R, ) for some a.
E(q)
R
q
r
rR
P
k+1 steps
a
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 57
Proof
From the induction hypothesis and (E(q), E) *
Md
(P, ) in k
steps, we know that there exists pP such that (q, E)
*
Mn
(p,)
(i.e. (q, Ea) *
Mn
(p, a) ).
Since (P, a)
Md
(R, ), there exists rR such that r= o(p, a).
Then, for some rR, (p, a) *
Mn
(r, ).
Thus, (q, ) *
Mn
(p, a) *
Mn
(r, ) for some rR.
E(q)
R
q
r rR
P
p
pP
k+1 steps
a
a
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 58
Closure Properties
The class of languages accepted by FAs is
closed under the operations
Union
Concatenation
Complementation
Kleenes star
Intersection
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 59
Closure Property under Union
The class of languages accepted
by FA is closed under union.
Proof:
Let M
A
= (Q
A
, , o
A
, s
A
, F
A
) and
M
B
= (Q
B
, , o
B
, s
B
, F
B
) be any FA.
We construct an NFA M=
(Q, , o, s, F) such that
Q = Q
A
Q
B
{s}
o = o
A
o
A
{(s, , {s
A
, s
B
})}
F = F
A
F
B
s
A
s
B
We prove that L(M) = L(M
A
)L(M
B
).
s

Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 60


Proof
To prove L(M) = L(M
A
) L(M
B
), we prove:
I. For any string * L(M
A
) or L(M
B
) L(M) &
II. For any string * ZL(M
A
) and ZL(M
B
). ZL(M)
For I, consider (a) L(M
A
) or (b) L(M
B
).
For (a), let L(M
A
).
From the definition of strings accepted by an FA, there is a
state f
A
in F
A
such that (s
A
, ) |-*
MA
(f
A
, ).
Because o
A
o, (s
A
, ) |-*
M
(f
A
, ) also.
Because s
A
o(s,), (s, ) |-
M
(s
A
, ).
Thus, (s, ) |-
M
(s
A
, ) |-*
M
(f
A
, ).
Because f
A
F, L(M).
Similarly for (b).
s
s
A
s
B

Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 61


Proof
For (II), let ZL(M
A
)L(M
B
).
Because (s, , {s
A
, s
B
})o, either (s,) |-
M
(s
A
,) or (s, ) |-
M
(s
B
, ) only.
Because ZL(M
A
), there exists no f
A
in F
A
such that (s
A
,) |-*
MA
(f
A
,).
Because ZL(M
B
), there exists no f
B
in F
B
such that (s
B
, ) |-*
MB
(f
B
, ).
Since there is no transition between states in Q
A
and Q
B
in M, there
exists no state f in F=F
A
F
B
such that (s, ) |-
M
(s
A
, ) |-*
M
(f
A
, )
or (s, ) |-
M
(s
B
, ) |-*
M
(f
B
, ).
That is, ZL(M).
Thus, L(M) = L(M
A
)L(M
B
).
s
s
A
s
B

Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 62


Closure under concatenation

s
A
M
A
s
B
M
B
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 63
Closure under complementation
s
A
M
A
DFA only
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 64
Closure under Kleenes star
s
A
f
A
s f
s s
s
s
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 65
Closure under intersection
The class of languages accepted by FA is closed under intersection.
Proof: Let L
1
and L
2
be languages accepted by FA.
L
1
L
2
= (DL
1
DL
2
)
By the closure property under complementation, there are FA
acceptingDL
1
andDL
2
.
By the closure property under union, there is an FA acceptingDL
1
DL
2
.
By the closure property under complementation, there is an FA
accepting(DL
1
DL
2
).
Thus, the class of languages accepted by FA is closed under
intersection.
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 66
DFA accepting the intersection of two
languages
Let M
A
= (Q
A
, , o
A
, s
A
, F
A
) and
M
B
= (Q
B
, , o
B
, s
B
, F
B
) be any FA.
We construct an NFA M= (Q, , o, s, F) such
that
Q = Q
A
- Q
B
o = o
A
-o
A
(i.e. o((q
A
,q
B
),a) = o
A
(q
A
,a)-o
B
(q
B
,a))
s = (s
A
, s
B
)
F = F
A
- F
B
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 67
Example
q
0
q
1
q
2
0
1
0
0
1
1
0,1
1 1
p
0
p
1
p
2
p
0
,q
1
p
0
,q
0
p
0
,q
2
0
1
0
0
1
1
p
1
,q
1
1
p
1
,q
0
1
p
1
,q
2
1
p
2
,q
0
1
p
2
,q
1
1
p
2
,q
2
1
Jaruloj Chongstitvatana 2301379 Chapter 2 Finite Automata 68
Check list
Basic
Explain how DFA/NFA work
(configuration, yield next
configuration)
Find the language accepted by
DFA/NFA
Construct DFA/NFA accepting a
given language
Find closure of a state
Convert an NFA into a DFA
Prove a language accepted by FA
Construct FA from other FAs
Advanced
Prove DFA/NFA accepting a
language
Prove properties of DFA/NFA
Configuration change
Under some modification
etc.
Prove some properties of
languages accepted by
DFA/NFA
Under some modification
Surprise!

S-ar putea să vă placă și