0% found this document useful (0 votes)
15 views191 pages

Introduction, DFA and NFA

Uploaded by

gemedakelbesa9
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
0% found this document useful (0 votes)
15 views191 pages

Introduction, DFA and NFA

Uploaded by

gemedakelbesa9
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1/ 191

Chapter – One

Introduction

Introduction to Languages
The syntax of a sentence concerns its form while the
semantics concerns

its meaning.

Natural languages (English, French, Amharic, etc) have


very complex rules of syntax and not necessarily well-
defined.

04/18/24 Automata and Complexity Theory: 1


Formal language

Formal language – is specified by well-defined set of rules


of syntax

We describe the sentences of a formal language using a


grammar.

Formal languages provide models for both natural


languages and programming languages.

04/18/24 2
Automata and Complexity Theory:
prepared by Kolana Korigne, CS, CCI,
04/18/24 WKU, Wolkite, Ethiopia 3
04/18/24 Automata and Complexity Theory: 4
04/18/24 5
04/18/24 Automata and Complexity Theory: 6
04/18/24 Automata and Complexity Theory: 7
04/18/24 Automata and Complexity Theory: 8
04/18/24 Automata and Complexity Theory: 9
04/18/24 Automata and Complexity Theory: 10
04/18/24 Automata and Complexity Theory: 11
04/18/24 Automata and Complexity Theory: 12
Descriptive definition of language:
The language is defined, describing the conditions imposed on its
words.
Example 1:
The language L of strings of odd length, defined over
Σ={a}, can be written as
L={a, aaa, aaaaa,…..}

Example 2:
The language L of strings that does not start with a,
defined over Σ={a,b,c}, can be written as
L={b, c, ba, bb, bc, ca, cb, cc, …}

04/18/24 Automata and Complexity Theory: 13


 Example 3:
The language L of strings of length 2, defined over
Σ={0,1,2}, can be written as
L={00, 01, 02,10, 11,12,20,21,22}

 Example 4:
The language L of strings ending in 0, defined over Σ
={0,1}, can be written as
L={0,00,10,000,010,100,110,…}

04/18/24 Automata and Complexity Theory: 14


04/18/24 Automata and Complexity Theory: 15
 Example 7:
The language INTEGER, of strings defined over
Σ={-,0,1,2,3,4,5,6,7,8,9}, can be written as
INTEGER = {…,-2,-1,0,1,2,…}

 Example 8:
The language EVEN, of strings defined over
Σ={-,0,1,2,3,4,5,6,7,8,9}, can be written as EVEN =
{ …,-4,-2,0,2,4,…}

04/18/24 Automata and Complexity Theory: 16


 Example 9:
The language {anbn}, of strings defined over Σ={a,b}, as
{anbn : n=1,2,3,…}, can be written as
{ab, aabb, aaabbb,aaaabbbb,…}

 Example 10:
The language {anbn an}, of strings defined over Σ={a,b}, as
{anbn an : n=1,2,3,…}, can be written as
{aba, aabbaa, aaabbbaaa,aaaabbbbaaaa,…}

04/18/24 Automata and Complexity Theory: 17


 Example 11:
The language factorial, of strings defined over
Σ={1,2,3,4,5,6,7,8,9} i.e. {1,2,6,24,120,…}

 Example 12:
The language FACTORIAL, of strings defined over Σ={a},
as {an! : n=1,2,3,…}, can be written as {a,aa,aaaaaa,…}.
It is to be noted that the language FACTORIAL can be defined
over any single letter alphabet.

04/18/24 Automata and Complexity Theory: 18


 Example 13:
The language DOUBLEFACTORIAL, of strings defined over
Σ={a, b}, as {an! bn! : n=1,2,3,…}, can be written as
{ab, aabb, aaaaaabbbbbb,…}

 Example 14:
The language SQUARE, of strings defined over Σ={a}, as
{an2 : n=1,2,3,…}, can be written as
{a, aaaa, aaaaaaaaa,…}

04/18/24 Automata and Complexity Theory: 19


 Example 15:
The language DOUBLESQUARE, of strings defined
over Σ={a,b}, as
{an2 bn2 : n=1,2,3,…}, can be written as
{ab, aaaabbbb, aaaaaaaaabbbbbbbbb,…}

 Example 16:
The language PRIME, of strings defined over Σ={a}, as

{ap : p is prime}, can be written as


{aa,aaa,aaaaa,aaaaaaa,aaaaaaaaaaa…}

04/18/24 Automata and Complexity Theory: 20


04/18/24 Automata and Complexity Theory: 21
04/18/24 Automata and Complexity Theory: 22
04/18/24 Automata and Complexity Theory: 23
04/18/24 Automata and Complexity Theory: 24
04/18/24 Automata and Complexity Theory: 25
04/18/24 Automata and Complexity Theory: 26
04/18/24 Automata and Complexity Theory: 27
04/18/24 Automata and Complexity Theory: 28
04/18/24 Automata and Complexity Theory: 29
04/18/24 Automata and Complexity Theory: 30
Deterministic Finite Automata(DFA)
and Non-Deterministic Finite Automata(NFA)

2012 E.C. Formal Language and Automata 31


Deterministic Finite Automata(DFA)
In DFA, for each input symbol, one can
determine the state to which the machine
will move. Hence, it is called Deterministic
Automaton. As it has a finite number of
states, the machine is called Deterministic
Finite Machine or Deterministic Finite
Automaton.
Deterministic Finite Automaton (DFA)

Input Tape
String
Output
“Accept”
Finite
or
Automaton
“Reject”

Formal Language and Automata


2012 E.C. Theory 33
Transition Graph
a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

initial accepting
state state
transition
state
2012 E.C. Formal Language and Automata 34
Alphabet   {a , b }
a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

For every state, there is a transition


for every symbol in the alphabet

2012 E.C. Formal Language and Automata 35


head Initial Configuration
Input Tape
a b b a
Input String
a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

Initial state
2012 E.C. Formal Language and Automata 36
Scanning the Input

a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 37


a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 38


a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 39


Input finished

a b b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4 accept

Last state determines the outcome


2012 E.C. Formal Language and Automata 40
A Rejection Case

a b a
Input String
a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 41


a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 42


a b a

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 43


Input finished

a b a

a, b

reject
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

Last state determines the outcome


2012 E.C. Formal Language and Automata 44
Another Rejection Case

Tape is empty
( )

Input Finished (no symbol read)


a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

reject
2012 E.C. Formal Language and Automata 45
This automaton accepts only one string

Language Accepted: L  abba 

a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 46


To accept a string:
all the input string is scanned
and the last state is accepting

To reject a string:
all the input string is scanned
and the last state is non-accepting

2012 E.C. Formal Language and Automata 47


Another Example

L  , ab , abba 
a, b

q5
b a a a, b
b
q0 a q1 b q2 b q3 a q4
Accept Accept Accept
state state state
2012 E.C. Formal Language and Automata 48
Empty Tape
( )

Input Finished a, b

q5
b a a a, b
b
q0 a q1 b q2 b q3 a q4

accept
2012 E.C. Formal Language and Automata 49
Another Example

a a, b

q0 b q1 a, b q2

Accept trap state


state
2012 E.C. Formal Language and Automata 50
a a b
Input String
a a, b

q0 b q1 a, b q2

2012 E.C. Formal Language and Automata 51


a a b

a a, b

q0 b q1 a, b q2

2012 E.C. Formal Language and Automata 52


a a b

a a, b

q0 b q1 a, b q2

2012 E.C. Formal Language and Automata 53


Input finished

a a b

a a, b
accept

q0 b q1 a, b q2

2012 E.C. Formal Language and Automata 54


A rejection case

b a b
Input String
a a, b

q0 b q1 a, b q2

2012 E.C. Formal Language and Automata 55


b a b

a a, b

q0 b q1 a, b q2

2012 E.C. Formal Language and Automata 56


b a b

a a, b

q0 b q1 a, b q2

2012 E.C. Formal Language and Automata 57


Input finished

b a b

a a, b

q0 b q1 a, b q2

reject

2012 E.C. Formal Language and Automata 58


Language Accepted: L  {a b : n  0 } n

a a, b

q0 b q1 a, b q2

2012 E.C. Formal Language and Automata 59


Another Example
Alphabet:   {1}
1

q0 q1
1
Language Accepted:
EVEN  {x : x   and x is even}
*

 { , 11, 1111, 111111, }


2012 E.C. Formal Language and Automata 60
Formal Definition
Deterministic Finite Automaton (DFA)

M  Q, ,  , q0 , F 
Q : set of states
 : input alphabet
 : transition function
q0 : initial state
F : set of accepting states
2012 E.C. Formal Language and Automata 61
Set of States Q
Example

Q  q0 , q1, q2 , q3 , q4 , q5 
a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 62


Initial State q0

Example
a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 63


Set of Accepting States F  Q

Example
F  q4  a, b

q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 64


Transition Function  :Q  Q

 (q , x )  q 

q x q

Describes the result of a transition


from state q with symbol x

2012 E.C. Formal Language and Automata 65


Example:
 q0 , a   q1

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 66


 q0 , b   q5

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 67


 q2 , b   q3

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 68


Transition Table for 
symbols
 a b
q0 q1 q5
q1 q5 q2
states

q2 q5 q3
a, b
q3 q4 q5
q4 q5 q5 q5
q5 q5 q5 a, b
b a a b
q0 a q1 b q2 b q3 a q4
2012 E.C. Formal Language and Automata 69
Extended Transition Function
 :Q    Q
* *

 (q ,w )  q 
*

Describes the resulting state


after scanning string w from state q

2012 E.C. Formal Language and Automata 70


Example:  q0 , ab   q2
*

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
2012 E.C. Formal Language and Automata 71
 q0 , abbbaa   q5
*

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 72


 q1 , bba   q4
*

a, b

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

2012 E.C. Formal Language and Automata 73


Special case:

for any state q

 q ,    q
*

2012 E.C. Formal Language and Automata 74


In general:  q ,w   q 
*

implies that there is a walk of transitions

w   1 2  k
1 2 k
q q
states may be repeated

q w q
2012 E.C. Formal Language and Automata 75
Language Accepted by DFA

Language accepted by DFA M:


it is denoted as L M  and contains
all the strings accepted by M

We also say that M recognizes L M 

2012 E.C. Formal Language and Automata 76


For a DFA M  Q, ,  , q0 , F 
Language accepted by M:
L M   w   :  q0 ,w   F 
* *

q0 w q q  F

2012 E.C. Formal Language and Automata 77


Language rejected by M:

L M   w   :  q0 ,w   F 
* *

q0 w q q  F

2012 E.C. Formal Language and Automata 78


More DFA Examples
  {a , b }
a, b
a, b

q0 q0

L (M )  { } L (M )   *

Empty language All strings


2012 E.C. Formal Language and Automata 79
  {a , b }

a, b

q0 a, b q0

L (M )  {  }
Language of the empty string
2012 E.C. Formal Language and Automata 80
  {a , b }

LM = { all strings with prefix ab }


a, b

q0 a q1 b q2

b a accept

q3 a, b

2012 E.C. Formal Language and Automata 81


L M  = { all binary strings containing
substring 001 }

0,1
1 0
1

 0 0 00 1 001
0

2012 E.C. Formal Language and Automata 82


L M  = { all binary strings without
substring 001 }

1 0 0,1
1

 0 1
0 00 001

0
2012 E.C. Formal Language and Automata 83

L(M )  awa : w  a , b  *
 a
b
b
q0 a q2 q3

b a
q4

a, b
2012 E.C. Formal Language and Automata 84
Regular Languages
Definition:
A language L is regular if there is
a DFA M that accepts it ( L(M )  L )

The languages accepted by all DFAs


form the family of regular languages

2012 E.C. Formal Language and Automata 85


Example regular languages:

abba  , ab, abba


{a b : n  0} awa : w  a , b  
n *

{ all strings in {a,b}* with prefix ab }


{ all binary strings without substring 001}
{x : x  {1} and x is even}
*

{ } {  } {a , b } *

There exist DFAs that accept these


languages (see previous slides).
2012 E.C. Formal Language and Automata 86
Non-Deterministic
Finite Automata

2012 E.C. Formal Language and Automata 87


Non-deterministic Finite Machine
In NDFA, for a particular input symbol, the
machine can move to any combination of the
states in the machine. In other words, the
exact state to which the machine moves
cannot be determined. Hence, it is called
Non-deterministic Automaton. As it has
finite number of states, the machine is called
Non-deterministic Finite Machine or
Nondeterministic Finite Automaton.
Nondeterministic Finite Automaton (NFA)

Alphabet = {a}

q1 a q2
a
q0
a
q3

2012 E.C. Formal Language and Automata 89


Alphabet = {a}

Two choices q1 a q2
a
q0
a
q3

2012 E.C. Formal Language and Automata 90


Alphabet = {a}

Two choices q1 a q2 No transition


a
q0
a
q3 No transition

2012 E.C. Formal Language and Automata 91


First Choice

a a

q1 a q2
a
q0
a
q3

2012 E.C. Formal Language and Automata 92


First Choice

a a

q1 a q2
a
q0
a
q3

2012 E.C. Formal Language and Automata 93


First Choice

a a
All input is consumed
q1 a q2 “accept”
a
q0
a
q3

2012 E.C. Formal Language and Automata 94


Second Choice

a a

q1 a q2
a
q0
a
q3

2012 E.C. Formal Language and Automata 95


Second Choice

a a
Input cannot be consumed
q1 a q2
a
q0 Automaton Halts
a
q3 “reject”

2012 E.C. Formal Language and Automata 96


An NFA accepts a string:
if there is a computation of the NFA
that accepts the string

i.e., all the input string is processed and the


automaton is in an accepting state

2012 E.C. Formal Language and Automata 97


aa is accepted by the NFA:

“accept”
q1 a q2 q1 a q2
a a
q0
a
q0
a
q3 q3 “reject”
because this
this computation
computation
is ignored
accepts aa
2012 E.C. Formal Language and Automata 98
Rejection example

q1 a q2
a
q0
a
q3

2012 E.C. Formal Language and Automata 99


First Choice

a
“reject”
q1 a q2
a
q0
a
q3

2012 E.C. Formal Language and Automata 100


Second Choice

q1 a q2
a
q0
a
q3

2012 E.C. Formal Language and Automata 101


Second Choice

q1 a q2
a
q0
a
q3 “reject”

2012 E.C. Formal Language and Automata 102


Another Rejection example

a a a

q1 a q2
a
q0
a
q3

2012 E.C. Formal Language and Automata 103


First Choice

a a a

q1 a q2
a
q0
a
q3

2012 E.C. Formal Language and Automata 104


First Choice

a a a
Input cannot be consumed
q1 a q2 “reject”
a
q0
a
Automaton halts
q3

2012 E.C. Formal Language and Automata 105


Second Choice

a a a

q1 a q2
a
q0
a
q3

2012 E.C. Formal Language and Automata 106


Second Choice

a a a
Input cannot be consumed
q1 a q2
a
q0 Automaton halts
a
q3 “reject”

2012 E.C. Formal Language and Automata 107


An NFA rejects a string:
if there is no computation of the NFA
that accepts the string.

For each computation:


• All the input is consumed and the
automaton is in a non final state

OR
• The input cannot be consumed
2012 E.C. Formal Language and Automata 108
a is rejected by the NFA:

“reject”
q1 a q2 q1 a q2
a a
q0 q0
a a
q3
“reject” q3

All possible computations lead to rejection


2012 E.C. Formal Language and Automata 109
aaa is rejected by the NFA:

“reject”
q1 a q2 q1 a q2
a a
q0
a
q0
a
q3 q3 “reject”

All possible computations lead to rejection


2012 E.C. Formal Language and Automata 110
Language accepted: L  {aa}

q1 a q2
a
q0
a
q3

2012 E.C. Formal Language and Automata 111


Lambda Transitions

q0 a q1  q2 a q3

2012 E.C. Formal Language and Automata 112


a a

q0 a q1  q2 a q3

2012 E.C. Formal Language and Automata 113


a a

q0 a q1  q2 a q3

2012 E.C. Formal Language and Automata 114


input tape head does not move

a a

q0 a q1  q2 a q3

2012 E.C. Formal Language and Automata 115


all input is consumed

a a

“accept”

q0 a q1  q2 a q3

String aa is accepted
2012 E.C. Formal Language and Automata 116
Rejection Example

a a a

q0 a q1  q2 a q3

2012 E.C. Formal Language and Automata 117


a a a

q0 a q1  q2 a q3

2012 E.C. Formal Language and Automata 118


(read head doesn’t move)

a a a

q0 a q1  q2 a q3

2012 E.C. Formal Language and Automata 119


Input cannot be consumed

a a a

Automaton halts
“reject”

q0 a q1  q2 a q3

String aaa is rejected


2012 E.C. Formal Language and Automata 120
Language accepted: L  {aa}

q0 a q1  q2 a q3

2012 E.C. Formal Language and Automata 121


Another NFA Example

q0 a q1 b q2  q3


2012 E.C. Formal Language and Automata 122
a b

q0 a q1 b q2  q3


2012 E.C. Formal Language and Automata 123
a b

q0 a q1 b q2  q3


2012 E.C. Formal Language and Automata 124
a b

“accept”
q0 a q1 b q2  q3


2012 E.C. Formal Language and Automata 125
Another String

a b a b

q0 a q1 b q2  q3


2012 E.C. Formal Language and Automata 126
a b a b

q0 a q1 b q2  q3


2012 E.C. Formal Language and Automata 127
a b a b

q0 a q1 b q2  q3


2012 E.C. Formal Language and Automata 128
a b a b

q0 a q1 b q2  q3


2012 E.C. Formal Language and Automata 129
a b a b

q0 a q1 b q2  q3


2012 E.C. Formal Language and Automata 130
a b a b

q0 a q1 b q2  q3


2012 E.C. Formal Language and Automata 131
a b a b

“accept”
q0 a q1 b q2  q3


2012 E.C. Formal Language and Automata 132
Language accepted

L  ab, abab, ababab, ...



 ab

q0 a q1 b q2  q3


2012 E.C. Formal Language and Automata 133
Another NFA Example

0
q0 q1 0, 1 q2
1

2012 E.C. Formal Language and Automata 134
Language accepted

L(M ) = {λ, 10, 1010, 101010, ...}


= {10} *
0
q0 q1 0, 1 q2
1 (redundant
state)

2012 E.C. Formal Language and Automata 135
Remarks:
•The  symbol never appears on the
input tape

•Simple automata:

M1 M2
q0 q0

L(M1 ) = {} L(M 2 ) = {λ}


2012 E.C. Formal Language and Automata 136
•NFAs are interesting because we can
express languages easier than DFAs

NFA M1 DFA M2 a
q2
q0 a q1
a
q0 a q1

L( M1 ) = {a} L( M 2 ) = {a}
2012 E.C. Formal Language and Automata 137
Formal Definition of NFAs
M  Q, ,  , q0 , F 

Q : Set of states, i.e. q0 , q1, q2 


 : Input aplhabet, i.e. a, b


: Transition function

q0 : Initial state

F : Accepting states
2012 E.C. Formal Language and Automata 138
Transition Function 

 q , x   q1 , q2 ,  , qk 

q1
x resulting states with
q x
q2 following one transition
x
with symbol x

qk
2012 E.C. Formal Language and Automata 139
 q0 , 1  q1

0
q0 q1 0, 1 q
2
1

2012 E.C. Formal Language and Automata 140
 (q1,0)  {q0 , q2 }

0
q0 q1 0, 1 q
2
1

2012 E.C. Formal Language and Automata 141
 (q0 ,  )  {q2 }

0
q0 q1 0, 1 q
2
1

2012 E.C. Formal Language and Automata 142
 (q2 ,1)  

0
q0 q1 0, 1 q
2
1

2012 E.C. Formal Language and Automata 143
*
Extended Transition Function 
Same with  but applied on strings

 q0 , a   q1 
*

q4 q5
a a
q0 a q1 b q2  q3

2012 E.C. Formal Language and Automata 144
 q0 , aa   q4 , q5 
*

q4 q5
a a
q0 a q1 b q2  q3

2012 E.C. Formal Language and Automata 145
 q0 , ab   q2 , q3 , q0 
*

q4 q5
a a
q0 a q1 b q2  q3

2012 E.C. Formal Language and Automata 146
Special case:

for any state q

q   q ,  
*

2012 E.C. Formal Language and Automata 147


In general
q j   qi ,w  : there is a walk from qi to q j
*

with label w

qi w qj

w   1 2  k
1 2 k
qi qj

2012 E.C. Formal Language and Automata 148


The Language of an NFA M
The language accepted by M is:
L M   w 1 ,w 2 ,...wn 

where  (q0 ,w m )  {qi ,..., qk , , q j }


*

and there is some qk  F (accepting state)


2012 E.C. Formal Language and Automata 149
w m  L M 
 (q0 ,w m )
*

qi
wm

q0 w
qk qk  F
m

wm qj

2012 E.C. Formal Language and Automata 150


F  q0 ,q5 
q4 q5
a a
q0 a q1 b q2  q3


 q0 , aa   q4 , q5
*
 aa  L(M )
F
2012 E.C. Formal Language and Automata 151
F  q0 ,q5 
q4 q5
a a
q0 a q1 b q2  q3


 q0 , ab   q2 , q3 , q0
*
 ab  LM 
F
2012 E.C. Formal Language and Automata 152
F  q0 ,q5 
q4 q5
a a
q0 a q1 b q2  q3


 q0 , abaa   q4 , q5
*
 abaa  L(M )
F
2012 E.C. Formal Language and Automata 153
F  q0 ,q5 
q4 q5
a a
q0 a q1 b q2  q3

 * q0 , aba   q1  aba  LM 


F
2012 E.C. Formal Language and Automata 154
q4 q5
a a
q0 a q1 b q2  q3

L M   ab  *  ab  * {aa }

2012 E.C. Formal Language and Automata 155


NFAs accept the Regular
Languages

2012 E.C. Formal Language and Automata 156


Equivalence of Machines

Definition:

Machine M1 is equivalent to machine M 2

if LM1   LM 2 

2012 E.C. Formal Language and Automata 157


Example of equivalent machines

NFA M1
0
LM1   {10} *
q0 q1
1

DFA M2 0,1
0
LM 2   {10} *
q0 q1 1 q2
1
0
2012 E.C. Formal Language and Automata 158
Theorem:


Languages
Regular
accepted
Languages
by NFAs
Languages
accepted
by DFAs

NFAs and DFAs have the same computation power,


accept the same set of languages
2012 E.C. Formal Language and Automata 159
Proof: we only need to show

Languages
accepted  Regular
Languages
by NFAs
AND
Languages
accepted  Regular
Languages
by NFAs

2012 E.C. Formal Language and Automata 160


Proof-Step 1

Languages
accepted  Regular
Languages
by NFAs

Every DFA is trivially an NFA

Any language L accepted by a DFA


is also accepted by an NFA
2012 E.C. Formal Language and Automata 161
Proof-Step 2

Languages
accepted  Regular
Languages
by NFAs
Any NFA can be converted to an
equivalent DFA

Any language L accepted by an NFA


is also accepted by a DFA
2012 E.C. Formal Language and Automata 162
Conversion NFA to DFA
a
NFA M
q0 a q1  q2
b

DFA M
q0 

2012 E.C. Formal Language and Automata 163


 * (q0 , a )  {q1 , q2 }
M a
NFA
q0 a q1  q2
b

DFA M
q0  a
q1, q2 

2012 E.C. Formal Language and Automata 164


 * (q0 , b )   empty set

M a
NFA
q0 a q1  q2
b

DFA M
q0  a
q1, q2 
b

 trap state
2012 E.C. Formal Language and Automata 165
 (q1 , a )  {q1 , q2 }
*

M a  * (q2 , a )  
NFA
q0 a q1  q2 union

b q1, q2 

a
DFA M
q0  a
q1, q2 
b


2012 E.C. Formal Language and Automata 166
 (q1 , b )  {q0 }
*

M a  * (q2 , b )  {q0 }
NFA
a  union
q0 q1 q2
b q0 

b a
DFA M
q0  a
q1, q2 
b


2012 E.C. Formal Language and Automata 167
M a
NFA
q0 a q1  q2
b

b a
DFA M
q0  a
q1, q2 
b

 a, b trap state
2012 E.C. Formal Language and Automata 168
END OF CONSTRUCTION

M a
NFA
q0 a q1  q2 q1  F
b
a
DFA M b

q0  a
q1, q2 
q1, q2  F 
b

 a, b
2012 E.C. Formal Language and Automata 169
General Conversion Procedure

Input: an NFA M

Output: an equivalent DFA M 


LM   L(M )
with

2012 E.C. Formal Language and Automata 170


The NFA has states q0 , q1, q2 ,...

The DFA has states from the power set

, q0 , q1 , q0 , q1 , q1 , q2 , q3 , ....

2012 E.C. Formal Language and Automata 171


Conversion Procedure Steps

step
1. Initial state of NFA: q0

Initial state of DFA: q0 

2012 E.C. Formal Language and Automata 172


Example
M a
NFA
q0 a q1  q2
b

DFA M
q0 

2012 E.C. Formal Language and Automata 173


step
2. For every DFA’s state {qi , q j ,..., qm }

compute in the NFA


 * qi , a 
  * q j , a 
Union
 {qk , ql,..., qn }
...
  * qm , a 

add transition to DFA


 {qi , q j ,..., qm }, a   {qk , ql,..., qn }
2012 E.C. Formal Language and Automata 174
Example  * (q0 , a )  {q1, q2 }
M a
NFA
q0 a q1  q2
b

 q0 , a   q1, q2 
DFA M
q0  a
q1, q2 

2012 E.C. Formal Language and Automata 175


step
3. Repeat Step 2 for every state in DFA and
symbols in alphabet until no more states
can be added in the DFA

2012 E.C. Formal Language and Automata 176


Example
M a
NFA
q0 a q1  q2
b

b a
DFA M
q0  a
q1, q2 
b

 a, b
2012 E.C. Formal Language and Automata 177
step
4. For any DFA state {qi , q j ,..., qm }

if some q j is accepting state in NFA

Then, {qi , q j ,..., qm }


is accepting state in DFA

2012 E.C. Formal Language and Automata 178


Example
M a
NFA
q0 a q1  q2 q1  F
b
a
DFA M b

q0  a
q1, q2 
q1, q2  F 
b

 a, b
2012 E.C. Formal Language and Automata 179
Lemma:
If we convert NFA M to DFA M 
then the two automata are equivalent:
LM   LM 

Proof:
We only need to show: LM   LM 
AND
LM   LM 
2012 E.C. Formal Language and Automata 180
First we show: LM   LM 

We only need to prove:

w L(M ) w  L(M )

2012 E.C. Formal Language and Automata 181


NFA
Consider w L(M )

q0 w qf

symbols
w   1 2  k
1 2 k
q0 qf

2012 E.C. Formal Language and Automata 182


symbol
i
qi qj

denotes a possible sub-path like

symbol
  i 
qi qj

2012 E.C. Formal Language and Automata 183


We will show that if w L(M )

w   1 2  k
1 2 k
NFA M: q0 qf

then

1 2 k
DFA M:
{q0 } {q f ,}
state
w  L(M ) state
label label
2012 E.C. Formal Language and Automata 184
More generally, we will show that if in M:
(arbitrary string) v  a1a2  an
a1 a2 an
NFA M: q0 qi qj ql qm

then

a1 a2 an
DFA M:
{q0 } {qi ,} {q j ,} {ql ,} {qm ,}

2012 E.C. Formal Language and Automata 185


Proof by induction on |v|

Induction Basis: |v | 1 v  a1

a1
NFA M: q0 qi

a1
DFA M:
{q0 } {qi ,}

is true by construction of M 
2012 E.C. Formal Language and Automata 186
Induction hypothesis: 1 | v | k
v  a1a2  ak

Suppose that the following hold


a1 a2 ak
M: q0 qi qj qc qd
NFA

a1 a2 ak
DFA M:
{q0 } {qi ,} {q j ,} {qc ,} {qd ,}

2012 E.C. Formal Language and Automata 187


Induction Step: | v | k  1
v  a1a2  ak ak 1  vak 1
   
v
Then this is true by construction of M 
a1 a2 ak ak 1
NFA M: q0 qi qj qc qd qe

v
a1 a2 ak ak 1
DFA M:
{q0 } {qi ,} {q j ,} {qc ,} {qd ,} {qe ,}

2012 E.C.
v
Formal Language and Automata 188
Therefore if w L(M )
w   1 2  k
1 2 k
NFA M: q0 qf

then

1 2 k
DFA M:
{q0 } {q f ,}
w  L(M )
2012 E.C. Formal Language and Automata 189
We have shown: LM   LM 

With a similar proof


we can show: LM   LM 

Therefore: L M   L M 

END OF LEMMA PROOF


2012 E.C. Formal Language and Automata 190
r -One
h ap te
Of C
E nd

2012 E.C. Formal Language and Automata 191

You might also like