0% found this document useful (0 votes)
57 views

Theory of Automata: Instructor: Dr. Muhammad Jehanzeb

The document discusses nondeterministic finite automata (NFA). It provides examples of NFAs that accept specific languages like {aa} and {ab, abab, ababab, ...}. An NFA may have multiple possible state transitions for a given input, unlike a DFA. A string is accepted if any computation path of the NFA consumes all input and reaches an accepting state.

Uploaded by

Talha Khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Theory of Automata: Instructor: Dr. Muhammad Jehanzeb

The document discusses nondeterministic finite automata (NFA). It provides examples of NFAs that accept specific languages like {aa} and {ab, abab, ababab, ...}. An NFA may have multiple possible state transitions for a given input, unlike a DFA. A string is accepted if any computation path of the NFA consumes all input and reaches an accepting state.

Uploaded by

Talha Khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Theory of Automata

Instructor: Dr. Muhammad Jehanzeb


[email protected]

Lecture 4

1
PREVIOUS LECTURE

 Finite Automata
 Deterministic Finite Automaton (DFA)

2
TODAY’S TOPIC

 Nondeterministic Finite Automaton (NFA)

3
LANGUAGE ACCEPTED BY DFA

  {a , b} a,b

q0 a,b q1

L ( M )  { }
Language of the empty string 4
LANGUAGE ACCEPTED BY DFA
a,b
  {a , b}

q0 a q1 b q2

b a accept

q3 a,b

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


LANGUAGE ACCEPTED BY DFA
  {0,1}
0,1
1 0
1

 0 0 00 1 001

0
L M  = { all binary strings containing substring 001 }
6
LANGUAGE ACCEPTED BY DFA
  {0,1}
1 0 0,1
1
0 1
 0 00 001
0
L M  = { all binary strings without substring 001 }
7
LANGUAGE ACCEPTED BY DFA
a
b
  {a , b}
b
q0 a q2 q3

b a
q1

a,b


L(M)  awa:w  a,b 
*
 8
NONDETERMINISTIC FINITE AUTOMATON
(NFA)

9
NONDETERMINISTIC FINITE AUTOMATON (NFA)

Alphabet = {a}
No transition

q1 a q2
Two choices a

q0
a
q3 No transition
10
NONDETERMINISTIC FINITE AUTOMATON (NFA)

First Choice

a a

q1 a q2
a

q0
a
q3 11
NONDETERMINISTIC FINITE AUTOMATON (NFA)

First Choice

a a

q1 a q2
a
q0
a
q3 12
NONDETERMINISTIC FINITE AUTOMATON (NFA)

First Choice

a a
All input is consumed

q1 a q2 “accept”
a
q0
a
q3 13
NONDETERMINISTIC FINITE AUTOMATON (NFA)

Second Choice

a a

q1 a q2
a

q0
a
q3 14
NONDETERMINISTIC FINITE AUTOMATON (NFA)

Second Choice

a a
Input cannot be consumed

q1 a q2
a

q0 Automaton Halts
a
q3 “reject” 15
NONDETERMINISTIC FINITE AUTOMATON (NFA)

Language accepted : ?

q1 a q2
a

q0
a L  {aa }
q3
16
NONDETERMINISTIC FINITE AUTOMATON (NFA)

An NFA accepts a string:


if there is a computation path of the NFA that
accepts the string

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

automaton is in an accepting state

17
NONDETERMINISTIC FINITE AUTOMATON (NFA)

An NFA rejects a string:


if there is no computation path of the NFA that
accepts the string

For each computation path:

• All the input is consumed and the


automaton is in a non accepting state
OR
• The input cannot be consumed 18
NONDETERMINISTIC FINITE AUTOMATON (NFA)

Lambda Transitions

q0 a q1  q2 a q3

19
NONDETERMINISTIC FINITE AUTOMATON (NFA)

Lambda Transitions

a a

q0 a q1  q2 a q3

20
NONDETERMINISTIC FINITE AUTOMATON (NFA)

a a

q0 a q1  q2 a q3

21
NONDETERMINISTIC FINITE AUTOMATON (NFA)

input tape head does not move

a a

q0 a q1  q2 a q3

Automaton changes state

22
NONDETERMINISTIC FINITE AUTOMATON (NFA)

all input is consumed

a a
“accept”
q0 a q1  q2 a q3

String aa is accepted

23
NONDETERMINISTIC FINITE AUTOMATON (NFA)

Language accepted : ?

q0 a q1  q2 a q3

L  {aa }
24
NONDETERMINISTIC FINITE AUTOMATON (NFA)

Another NFA Example

q0 a q1 b q2  q3

25
NONDETERMINISTIC FINITE AUTOMATON (NFA)

a b

q0 a q1 b q2  q3


26
NONDETERMINISTIC FINITE AUTOMATON (NFA)

a b

q0 a q1 b q2  q3


27
NONDETERMINISTIC FINITE AUTOMATON (NFA)

a b
“accept”

q0 a q1 b q2  q3


28
NONDETERMINISTIC FINITE AUTOMATON (NFA)
Another String

a b a b

q0 a q1 b q2  q3


29
NONDETERMINISTIC FINITE AUTOMATON (NFA)

a b a b

q0 a q1 b q2  q3


30
NONDETERMINISTIC FINITE AUTOMATON (NFA)

a b a b

q0 a q1 b q2  q3


31
NONDETERMINISTIC FINITE AUTOMATON (NFA)

a b a b

q0 a q1 b q2  q3


32
NONDETERMINISTIC FINITE AUTOMATON (NFA)

a b a b

q0 a q1 b q2  q3


33
NONDETERMINISTIC FINITE AUTOMATON (NFA)

a b a b

q0 a q1 b q2  q3


34
NONDETERMINISTIC FINITE AUTOMATON (NFA)

a b a b

“accept”

q0 a q1 b q2  q3


35
NONDETERMINISTIC FINITE AUTOMATON (NFA)

Language accepted : ?

q0 a q1 b q2  q3


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

 ab 
36
NONDETERMINISTIC FINITE AUTOMATON (NFA)

Another NFA Example


Language accepted : ?
0
q0 q1 0, 1 q2
1


L ( M )   , 10 , 1010 , 101010 , ...
 10 
* 37
FORMAL DEFINITION OF NFAS

M  Q ,  ,  , q 0 , F 

Q: Set of states, i.e. q 0 , q1 , q 2 


: Input alphabet, i.e. a, b
 : Transition function
q 0 : Initial state
F : Accepting states
38
FORMAL DEFINITION OF NFAS

Transition Function 
 q , x   q1 , q 2 ,  , q k 
q1
x

q x
q2 resulting states reached
by following one transition
x
with input symbol x
qk 39
FORMAL DEFINITION OF NFAS

States reachable from q0 scanning 1

  q 0 , 1  q1
0
q0 q1 0, 1 q2
1


40
FORMAL DEFINITION OF NFAS

States reachable from q1 scanning 0

 ( q1 ,0 )  {q 0 , q 2 }
0
q0 q1 0, 1 q2
1


41
FORMAL DEFINITION OF NFAS

States reachable from q0 with one transition scanning


no input symbol
 ( q 0 ,  )  {q 2 }
0
q0 q1 0, 1 q2
1

 42
FORMAL DEFINITION OF NFAS

States reachable from q2 scanning 1

 ( q2 ,1)  
0
q0 q1 0, 1 q2
1

 43
FORMAL DEFINITION OF NFAS
*
Extended Transition Function 
Similar with  but applied on strings

 q 0 , a   q1 
*

q4 q5
a a
q0 a q1 b q2  q3

 44
FORMAL DEFINITION OF NFAS
*
Extended Transition Function 
States reachable from q0 scanning aa

 q 0 , aa   q 4 , q 5 
*

q4 q5
a a
q0 a q1 b q2  q3


45
FORMAL DEFINITION OF NFAS
*
Extended Transition Function 
States reachable from q0 scanning ab

 q 0 , ab   q 2 , q3 , q 0 
*

q4 q5
a a
q0 a q1 b q2  q3

 46
FORMAL DEFINITION OF NFAS

In general

q j   *  q i , 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

47
THE LANGUAGE OF AN NFA M
The language accepted by M is:
L  M   w1 , w2 ,..., wn 

Where for each w m


*
 (q 0 , w m )  {qi ,..., qk ,  , q j }

and there is some qk  F (accepting state)


48
THE LANGUAGE OF AN NFA M

*
w m  L M   (q 0 , w m )

qi
wm

q0 w
qk qk  F
m

wm qj
49
THE LANGUAGE OF AN NFA M

*
w m  L M   (q 0 , w m )

qi
wm

q0 w
qk qk  F
m

wm qj
50
THE LANGUAGE OF AN NFA M

F  q 0 , q5  q q5
4

a a
q0 a q1 b q2  q3

 q0 , aa   q4 , q5 
*
aa  L (M )
F 51
THE LANGUAGE OF AN NFA M

F  q 0 , q5  q q5
4

a a
q0 a q1 b q2  q3

 * q0 , ab   q2 , q3 , q0  ab  L  M 
F 52
THE LANGUAGE OF AN NFA M

F  q 0 , q5  q q5
4

a a
q0 a q1 b q2  q3

 q0 , abaa   q4 , q5 


*
abaa  L ( M )
F 53
THE LANGUAGE OF AN NFA M

F  q 0 , q5  q q5
4

a a
q0 a q1 b q2  q3

 q0 , aba   q1 


* aba  L  M 
F 54
NONDETERMINISTIC FINITE AUTOMATON (NFA)

55
NFA EXAMPLE N1

What language is represented by this machine?

56
NFA EXAMPLE N1A

What language is represented by this machine?

57
NFA EXAMPLE N2

What language is represented by this machine?

58

You might also like