You are on page 1of 46

Finite Automata and

Non Determinism
http://cis.k.hosei.ac.jp/~yukita/
2
Definition 1.1: Finite Automaton
. the is 5.
and , the is 4.
, the is : 3.
, the called set finite a is 2.
, the called set finite a is 1.
where ), , , , , ( tupple - 5 a is A
0
0
states accept of set
state start
function transition
alphabet
states
automaton finite
Q F
Q q
Q Q
Q
F q Q
_
e
E
E
E
o
o
3
State Diagram for M
1
q
3 q
1
q
2
0
1
1
0
0, 1
4
Data Representation for M
1
. } { 5.
and state, start the is 4.
,
1 0
as described is 3.
{0,1} 2.
} , , { 1.
2
1
2 2 3
2 3 2
2 1 1
3 2 1
q F
q
q q q
q q q
q q q
q q q Q
=
= E
=
o
5
Task 01
DFA
1. Implement M
1
with your favorite
programming language.
2. GUI
Two buttons for input 0 and 1
State chart with the current state highlighted
6
Language of M
1
} 1 last the follow 0s of number even an
and 1 one least at contains | { ) (
. say that can We
accepts. machine that strings all of set the is
), ( as written , The
1
w w M L
A M
M
M L M
=
recognizes
machine of language
7
State Diagram for M
5
q
2
q
1
q
0
0
1
1
2
1, <RESET>
2
0, <RESET>
0
8
Data Representation for M
5
. } { 5.
and state, start the is 4.
,
2 1 0
as described is 3.
,0,1,2} RESET { 2.
} , , { 1.
0
0
1 0 2 0 2
0 2 1 0 1
2 1 0 0 0
2 1 0
q F
q
q q q q q
q q q q q
q q q q q
R
q q q Q
=
= E
=
o
9
Informal Description of M
5
M
5
keeps a running count of the sum of
the numerical symbols it reads, modulo 3.
Every time it receives the <RESET>
symbol it resets the count to 0.
M
5
accepts if the sum is 0, modulo 3.
10
Definition 1.7: Regular Language
A language is called a regular language if
some finite automaton recognizes it.
11
Example 1.9: A finite automaton E
2
E
2
recognizes the regular language of all
strings that contain the string 001 as a
substring.
0010, 1001, 001, and 1111110011110 are
all accepted,
but 11 and 0000 are not.
12
Find a set of states of E
2
You
1. havent just seen any symbols of the
pattern,
2. have just seen a 0,
3. have just seen 00 or,
4. have just seen the entire pattern 001.
Assign the states q,q
0
,q
00
, and q
001
to these
possibilities.
13
Draw a State Diagram for E
2
q
00
q
001
0
0, 1
1
1
0
q
0
0
q

1
14
Regular Operations on Languages
operation. a one last the and
, operations are operations first two The
}. each and 0 | { :
}. and | { :
}. or | { :
languages. be and Let
2 1
*
unary
binary
A x k x x x A
B y A x xy B A
B x A x x B A
B A
i k
e > =
e e =
e e =

Star
ion Concatenat
Union
15
Example 1.11
}. , goodbadbad
d, goodbadgoo goodbad, good od, goodgoodgo
badbad, goodbad, goodgood, bad, good, , {
and }, badgirl badboy, goodgirl, goodboy, {
}, girl boy, bad, good, {
have we Then, }. girl boy, { and } bad good, { Let
}. z , , b a, { be alphabet Let the
*

c =
=
=
= =
E
A
B A
B A
B A
16
Theorem 1.12 Closedness for Union
. is so
languages, regular are and if s, other word In
operation. union the
under closed is languages regular of class The
2 1
2 1
A A
A A

Proof of Th 1.12 17
Proof of Theorem 1.12
on. constructi the of s correctnes check the Then,
. ) , , , , ( where
, recognize to Construct
. ) , , , , ( where , recognize and
), , , , , ( where , recognize Let
2 1
2 2 2 2 2 2 2
1 1 1 1 1 1 1
F q Q M
A A M
F q Q M A M
F q Q M A M
o
o
o
E =

E =
E =
Proof of Th 1.12 18
Construction of M
}. or | ) , {( ) ( ) ( 5.
). , ( 4.
)) , ( ), , ( ( ) ), , (( ; , ) , ( 3.
(Why?) . alphabet
same the have and that assume can We 2.
}. and | ) , {( 1.
2 2 1 1 2 1 2 1 2 1
2 1 0
2 2 1 1 2 1 2 1
2 1
2 2 1 1 2 1 2 1
F r F r r r F Q Q F F
q q q
a r a r a r r a Q r r
M M
Q r Q r r r Q Q Q
e e = =
=
= E e e
E
e e = =
o o o
Proof of Th 1.12 19
Correctness
You should check the following.
1. For any string recognized by M
1
is
recognized by M.
2. For any string recognized by M
2
is
recognized by M.
3. For any string recognized by M is
recognized by M
1
or M
2
.
20
Theorem 1.13 Closedness for
concatenation
. is so
languages, regular are and if s, other word In operation.
ion concatenat under closed is languages regular of class The
2 1
2 1
A A
A A

21
Nondeterminism
To prove Theorem 1.13, we need
nondeterminism.
Nondeterminism is a generalization of
determinism. So, every deterministic
automaton is automatically a
nondeterministic automaton.
22
Nondetermistic Finite Automata
A nondeterministic finite automaton can be
different from a deterministic one in that
for any input symbol, nondeterministic one
can transit to more than one states.
epsilon transition
NFA and DFA stand for nondeterministic
finite automaton and deterministic finite
automaton, respectively.
23
NFA N
1
q
3 q
1
q
2
0,1
1 0,c
q
4
0,1
1
24
Parallel world and NFA
.
.
.

.
.
.

accept
25
Example 1.14 NFA N
2
q
3 q
1
q
2
0,1
1 0,1
q
4
0,1
Let language A consist of all strings over {0,1} containing a 1 in the third
position from the end. N
2
recognizes A.
26
A DFA equivalent to N
2
q
010 q
000
q
100
0
0 0
q
110
q
011 q
001
q
101
1
q
111
1
0
1
0
0
1
0
1
1
0 1
1
27
Example 1.15 NFA N
3
c
0
Let language A consist of all strings 0
k
, where k is a multiple of 2 or 3. N
3

recognizes A.
c
0
0
0
0
28
A DFA equivalent to N
3
0
q

q

q
3
q
5
0
q
0
0 0 0
q
4
0
q
-1
1
1
1 1
1
1
0, 1
29
Example 1.16 NFA N
4
q
1
q
2
q
3
a
b
a,b
c
a
N
4
accepts c, a, baba, and baa. N
4
does not accept b, nor babba.
30
Definition 1.17: NFA
. the is 5.
and , the is 4.
, the is 2 : 3.
, the called set finite a is 2.
, the called set finite a is 1.
where ), , , , , ( tupple - 5 a is A
0
0
states accept of set
state start
function transition
alphabet
states
automaton finite nistic nondetermi
Q F
Q q
Q
Q
F q Q
Q
_
e
E
E
E
c
o
o
31
Example 1.18 NFA N
1
}. { 5.
state. start the is 4.
} { } {
} {
} { } {
} , { } {
1 0
as given is 3.
} 1 , 0 { 2.
}, , , , { 1.
4
1
4 4 4
4 3
3 3 2
2 1 1 1
4 3 2 1
q F
q
q q q
q q
q q q
q q q q
q q q q Q
=
C
C C
C
C
= E
=
c
o
q
3
q
1
q
2
0,1
1 0,c
q
4
0,1
1
32
In what situation is Non
Determinism relevant?
Von Neumann machines are deterministic.
However, there are many cases where
machine specification is all we need.
33
Theorem 1.19
Every nondeterministic finite automaton
has an equivalent deterministic finite
automaton.
Def. The two machines are equivalent is they
recognize the same language.
Proof of Th 1.19 34
Proof of Th. 1.19
}. | { 4.
and }, { 3.
, ) , ( ) , ( 2.
, 2 1.
such that ) , , , , ( Construct
arrows. no has first that assume us Let
. language some g recognizin NFA the be ) , , , , ( Let
0 0
0
0
C =
'
e =
'
=
'
=
'
=
'
' ' '
E
'
=
E =
e
F R Q R F
q q
a r a R
Q
F q Q M
N
A F q Q N
R r
Q

o o
o
c
o
Proof of Th 1.19 35
Incorporate c arrows
0
0 0
( ) { | can be reached from by traveling along zero or
more arrows.}
We modify as follows.
( , ) { | ( ( , )) for some }.
We modify as follows.
({ }).
We omit the correctness p
E R q q R
R a q Q q E r a r R
q
q E q
c
o
o o
=
'
'
= e e e
'
'
=
roof.
36
Corollary 1.20
A language is regular if and only if some
nondeterministic finite automaton
recognizes it.
37
Example 1.21 NFA N
4
to DFA

1
2

3

a
b
a,b
c
a
}}. 3 , 2 , 1 { }, 3 , 2 { }, 3 , 1 { }, 2 , 1 { }, 3 { }, 2 { }, 1 { , { 2
as takes be may set state s ' The . DFA equivalent an
construct want to we , }} 3 { , 1 , }, , { }, 3 , 2 , 1 {{ Given
} 3 , 2 , 1 {
4
C =
=
D D
b a N o
38
Task 02
Parallel World
1. Write a program that simulates N
4
.
2. GUI
Three buttons for input 0, 1, and epsion.
State chart that reflect the branching of the
world.
39
Start and Accept states
follows. as given is diagram state The
}}. 3 , 2 , 1 { }, 3 , 2 { }, 3 , 1 { }, 3 {{ is states accept of set The
}. 3 , 1 { }) 1 ({ is state start The = E
40
The state diagram of D
| {1}
{2} {1,2}
{3} {1,3}
{2,3}
{1,2,3}
a,b
a,b
a
a
a
a
a
a
b
b
b
b
b
b
41
Theorem 1.22 The class of regular languages is
closed under the union operation.
N
1
N
2
N
c
c
42
Proof of Th. 1.22

= = C
= =
e
e
=
=
=
E =
E =
E =
. and for
and for } , {
for ) , (
for ) , (
) , ( 4.
3.
of state start the is state The 2.
} { 1.
. recognize to ) , , , , { Construct
. recognize ) , , , , (
and , recognize ) , , , , ( Let
0
0 2 1
2 2
1 1
2 1
0
2 1 0
2 1 0
2 2 2 2 2 2
1 1 1 1 1 1
c
c
o
o
o
o
o
o
a q q
a q q q q
Q q a q
Q q a q
a q
F F F
N. q
Q Q q Q
A A F q Q N
A F q Q N
A F q Q N

43
Theorem 1.23 The class of regular languages is
closed under the concatenation operation.
N
1
N
2
N
c
c
44
Proof of Th. 1.23

e
= e
= e
e e
=
=
E =
E =
E =
. for ) , (
and for } { ) , (
and for ) , (
and for ) , (
) , ( 4.
of that as same the is states accept of set The 3.
. of that as same the is state start The 2.
1.
. recognize to ) , , , , { Construct
. recognize ) , , , , (
and , recognize ) , , , , ( Let
2 2
1 2 1
1 1
1 1 1
2
1 1
2 1
2 1 2 1
2 2 2 2 2 2
1 1 1 1 1 1
Q q a q
a F q q a q
a F q a q
F q Q q a q
a q
N
N q
Q Q Q
A A F q Q N
A F q Q N
A F q Q N
o
c o
c o
o
o
o
o
o

45
Theorem 1.24 The class of regular languages is
closed under the star operation.
N
1
N

c
c
c
46
Proof of Th. 1.24

= = C
= =
= e
= e
e e
=
=
=
E =
E =
. and for
and for } {
and for } { ) , (
and for ) , (
and for ) , (
) , ( 4.
} { 3.
state. start new the is state start The 2.
} { 1.
. recognize to ) , , , , { Construct
. recognize ) , , , , ( Let
0
0 1
1 1 1
1 1
1 1 1
1 0
0
1 0
*
1 0
1 1 1 1 1 1
c
c
c o
c o
o
o
o
o
a q q
a q q q
a F q q a q
a F q a q
F q Q q a q
a q
F q F
q
Q q Q
A F q Q N
A F q Q N

You might also like