0% found this document useful (0 votes)
11 views19 pages

Toc L#05

Uploaded by

alexkhan656
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views19 pages

Toc L#05

Uploaded by

alexkhan656
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH

CSC3113: THEORY OF COMPUTATION


Lecture: # 5 Week: # 3 Semester: Spring 2022-2023

NON-DETERMINISTIC FINITE
AUTOMATON (NFA)

Instructor: Md. Reazul Islam, Lecturer,


Department of Computer Science, Faculty of Science & Technology.
[email protected] 1
LECTURE OUTLINE

 Nondeterministic Finite Automata (NFA).


 Running NFA, NFA Tree.
 Formal Definition of NFA.
 Practice, solve exercise of NFA.

CSC3113: Theory of Computation 2


LEARNING OBJECTIVE

 Understand, learn & practice with example


 Formal Definition of Nondeterministic Finite Automata (NFA)
 Practice designing NFA.

CSC3113: Theory of Computation 3


LEARNING OUTCOME
ALL OUTCOME ARE REPRESENTED WITH
EXAMPLES
 Understand, learn & formal definition of NFA.
 Practice & Design of NFA

CSC3113: Theory of Computation 4


NONDETERMINISTIC FINITE AUTOMATA (NFA)

STATE DIAGRAM AND THE PROPERTIES OF NFA


 We already know DFA, so it would be sufficient to look into the
differences of properties between the two.
 In NFA a state may have –
 Zero or more exiting arrows for each alphabet symbol.
 Zero or more exiting arrows with the label ε.
 So we can see that, not all steps of a computation follows in a unique
way from the preceding step. There can be multiple choices to move
from one state to another with a symbol. That’s the reason it’s
computation is called nondeterministic.
CSC3113: Theory of Computation 5
RUNNING AN NFA
 If we encounter a state with multiple ways to proceed –
 The machine splits into multiple copies of itself and follows all the possibilities in parallel.
 Each copy of the machine takes one of the possible ways to proceed and continues as before.
 If there are subsequent choices, the machine splits again.
 If a state with an ε symbol on an exiting arrow is encountered without reading any
input, the machine splits into multiple copies,
 one following each of the exiting ε-labeled arrows and
 one staying in the current state.
 If the next input symbol doesn’t appear on any of the arrows exiting the state occupied
by a copy of the machine, that copy of the machine dies, along with the branch of the
computation associated with it.
 If any one of these copies of the machine is in an accept state at the end of the input,
the NFA accepts the input strings.
 So, nondeterminism may be viewed as a kind of parallel computation wherein several
processes can be running concurrently.
 If at least one of these processes accepts then the entire computation accepts.
CSC3113: Theory of Computation 6
RUNNING AN NFA
 Another way of viewing a
nondeterministic computation is as a
tree of possibilities.
 The root corresponds to the start
of the computation.
 Every branching point in the tree
corresponds to a point in the
computation at which the machine
has multiple choices.
 The machine accepts if at least
one of the computation branches
ends in an accept state.

TREE REPRESENTATION

CSC3113: Theory of Computation 7


SIMULATION – NFA TREE
0,1 0,1

010110 1 0, ε 1
a1 a2 a3 a4
Symbol read
a1
0 ----------------------------------------------------------------------------------
a1
1 -----------------------------------------------------------------------
a1 a2
0 ----------------------------------------------------------------
a1 a3
1 ----------------------------------------------------------
a1 a2 a3 a4
1 ------------------------------------------------
a1 a2 a3 a4 a4
0 ------------------------------------------
a1 a3 a4 a4
CSC3113: Theory of Computation 8
FORMAL DEFINITION OF NFA
NFA is a 5-tuple (Q, Σ, , q0, F)
Q is a finite set of states.
Σ is a finite alphabet.
 : Q  Σ  P(Q).
The transition function takes a state and an input
symbol or the empty string (Σ=Σ  ) and produces the
set of possible next states (P(Q) is the power set of Q).
q0Q is the start state.
F  Q is the set of accepted states.

CSC3113: Theory of Computation 9


NONDETERMINISTIC FINITE AUTOMATA (NFA)

FORMAL DEFINITION
 Let, the above NFA N1 = (Q1, Σ, 1, a1, F1). 1 in form  : Q  Σ  P(Q)
 Q1 = {a1, a2, a3, a4}.
 Σ = {0, 1}. 1(a1, 0) = {a1} 1(a3, 0) = 
 1 | 0 1 1(a1, 1) = {a1, a2} 1(a3, 1) = {a4}
 1(a1, ) =  1(a3, ) = 
a1 | {a1} {a1, 1(a2, 0) = {a3} 1(a4, 0) = {a4}
a 2}  1(a2, 1) =  1(a4, 1) = {a4}
a2 | {a3}  1(a2, ) = {a3} 1(a4, ) = 
{a3}
Q  Σa =3 {(a1, |0), (a1, 1), (a1, ), (a2, 0), (a2, 1),
{a4(a} 2, ), (a3, 0), (a3, 1), (a3, ), (a4, 0), (a4, 1), (a4, )}
P(Q) = {, {a1}, {a2}, {a3}, {a4}, {a1,a2}, {a1,a3}, {a1,a4}, {a2,a3}, {a2,a4}, {a3,a4},
a4 | {a4} {a2,a
{a1,a 4} 3}, {a1,a2,a4}, {a1,a3,a4}, {a2,a3,a4}, {a1,a2,a3, a4}}
CSC3113: Theory of Computation
 10
NONDETERMINISTI
C FINITE AUTOMATA
(NFA)

EXAMPLE

 Let, the above NFA N2 = (Q2, Σ, 2, b1, F2).


 Q2 = {b1, b2, b3}.
 Σ = {0, 1}.
 2 is given as –
| 0 1 
b1 |  {b2} {b3}
b2 | {b2, b3} {b3} 
b3 | {b1}  
 b1 is the start state.
 F2 = {b1}.
CSC3113: Theory of Computation 11
PRACTICE NFA

CSC3113: Theory of Computation 12


PRACTICE NFA

1. Draw the state diagram of the NFA for the following Languages
over the alphabet is {0, 1}.
a) L={w | w begins/starts with a 0},
b) L={w | w begins/starts with a 1},

2. Draw the state diagram of the NFA for the following Languages
over the alphabet is {a, b}.
a) L={w | w ends with a},
b) L={w | w ends with b},
c) L={w | w contains with b}
d) L={w | w contains with ab}

CSC3113: Theory of Computation 13


B1 ={w : w is a binary string containing an odd number of 1s}.
B2 ={w : w is a binary string containing an even number of 0s}.
∑ = {0,1}
0
1 0

B1 q1 q2

1
1
1 0 1

0
B2 q1 q2 q3

CSC3113: Theory of Computation 14


B3 ={w| w ends with a 0}.
B4 ={w| w begins with a 1}.
B5 ={w| w begins with a 1 and ends with a 0}.
∑ = {0,1}
0, 1
0
B3 q1 q2

1 0, 1
B4 q1 q2

0, 1

1 0
B5 q1 q2 q3

CSC3113: Theory of Computation 15


B6 ={w| w has at least two 1s}.
B7 ={w| w has at most two 1s}.
∑ = {0,1}

0 0 0, 1

1 1
B6 q1 q2 q3

0 0 0

1 1
B7 q1 q2 q3

16
B8 ={w| w has substring 101}.
B9 ={w| w has substring 011}.
∑ = {0,1} 0,1

1 0 1
B8 qs q1 q10 q101 0, 1

0, 1 0

0 1 1
B9 qs q0 q01 q011 0, 1
0

What happens for the language, A2 ={w| w does not have substring 011}?

17
B10 ={w| w starts with a 1 and has even length or
w starts with a 0 and has odd length}.
∑ = {0,1}
0, 1

0, 1
1 q2 q3

B10 q1 0, 1

0 0, 1
q4 q5

18
REFERENCES
NONDETERMINISTIC FINITE AUTOMATA
 Introduction to Theory of Computation, Sipser, (3rd ed), NFA.

CSC3113: Theory of Computation 19

You might also like