Download - SR3_NFA
-
8/12/2019 SR3_NFA
1/33
-
8/12/2019 SR3_NFA
2/33
Outline
1 What is Non-Deterministic Finite Automaton(NFA)
Shaifur (CSE, BUET) CSE211: NFA Class 4 2 / 23
-
8/12/2019 SR3_NFA
3/33
Outline
1 What is Non-Deterministic Finite Automaton(NFA)
2 Examples of NFA
Shaifur (CSE, BUET) CSE211: NFA Class 4 2 / 23
-
8/12/2019 SR3_NFA
4/33
Outline
1 What is Non-Deterministic Finite Automaton(NFA)
2 Examples of NFA
3 Equivalence of NFA and DFA
Shaifur (CSE, BUET) CSE211: NFA Class 4 2 / 23
-
8/12/2019 SR3_NFA
5/33
What is NFA
Non-Deterministic Finite Automaton (NFA)For a single input symbol, transition from the current state to one ormore states
Transition from current state to one or more states withoutconsuming any input symbol (in other word, transition consuming )
Shaifur (CSE, BUET) CSE211: NFA Class 4 3 / 23
-
8/12/2019 SR3_NFA
6/33
-
8/12/2019 SR3_NFA
7/33
-
8/12/2019 SR3_NFA
8/33
NFA Example
NFA N1 has four states
Shaifur (CSE, BUET) CSE211: NFA Class 4 4 / 23
-
8/12/2019 SR3_NFA
9/33
-
8/12/2019 SR3_NFA
10/33
NFA Example
NFA N1 has four states
For input 1, q1 q1 OR q1 q2
State q2 has only transition for input 0 BUTnot for 1
Shaifur (CSE, BUET) CSE211: NFA Class 4 4 / 23
-
8/12/2019 SR3_NFA
11/33
NFA Example
NFA N1 has four states
For input 1, q1 q1 OR q1 q2
State q2 has only transition for input 0 BUTnot for 1N1 can transit q2 q3 without any input!
Shaifur (CSE, BUET) CSE211: NFA Class 4 4 / 23
-
8/12/2019 SR3_NFA
12/33
Examples of NFA (Contd.)
NFA Decision Tree
Shaifur (CSE, BUET) CSE211: NFA Class 4 5 / 23
-
8/12/2019 SR3_NFA
13/33
Examples of NFA (Contd.)
NFA Decision Tree for N1 for computation of010110
Shaifur (CSE, BUET) CSE211: NFA Class 4 6 / 23
-
8/12/2019 SR3_NFA
14/33
Examples of NFA (Contd.)
NFA N1
Equivalent DFA D1
Shaifur (CSE, BUET) CSE211: NFA Class 4 7 / 23
-
8/12/2019 SR3_NFA
15/33
Examples of NFA (Contd.)
An NFA which all strings of the form 0
k
wherek
is a multiple of 2 or 3
Shaifur (CSE, BUET) CSE211: NFA Class 4 8 / 23
( )
-
8/12/2019 SR3_NFA
16/33
Examples of NFA (Contd.)
An NFA which all strings of the form , a, baba, baa, . . .But does not accept b, bb, babba etc.
Shaifur (CSE, BUET) CSE211: NFA Class 4 9 / 23
F l D fi i f NFA
-
8/12/2019 SR3_NFA
17/33
Formal Defintion of NFA
NFA
a 5-tuple (Q,, ,q 0, F) where:
1 Q is a finite set of states
2 is a finite alphabet
3 :Q P(Q)
4 q0Q is the start-state
5 F Q is the accept-state set
Shaifur (CSE, BUET) CSE211: NFA Class 4 10 / 23
E l f NFA (C d )
-
8/12/2019 SR3_NFA
18/33
Examples of NFA (Contd.)
Give the formal definition of for the following NFA:
Shaifur (CSE, BUET) CSE211: NFA Class 4 11 / 23
E l f NFA (C d )
-
8/12/2019 SR3_NFA
19/33
Examples of NFA (Contd.)
Give the formal definition of for the following NFA:
Q= {q1, q2, q3, q4}
={0, 1}start-state,q0=q1
accept-states, F ={q4}
is:0 1
q1 {q1} {q1, q2}
q2 {q3} {q3}q3 {q4} q4 {q4} {q4}
Shaifur (CSE, BUET) CSE211: NFA Class 4 11 / 23
C t ti b NFA
-
8/12/2019 SR3_NFA
20/33
Computation by NFA
Formal Definition of Computation by NFA
N= (Q,, ,q 0, F) is an NFA, w is a string ofN accepts w ifw=y1 y2 . . . ym where each yi and sequence of
states r0, r1, . . . , rm each exists in Q such that:
1 r0=q02 ri+1(ri, yi+1) form= 0, 1, . . . ,m 1 and
3 rm F
Shaifur (CSE, BUET) CSE211: NFA Class 4 12 / 23
E i l f NFA d DFA
-
8/12/2019 SR3_NFA
21/33
Equivalence of NFA and DFA
Equivalence of Machines
Two machines are equivalent if they recognize the same languages
Theorem 1.39
Every NFA has an equivalent DFA
Shaifur (CSE, BUET) CSE211: NFA Class 4 13 / 23
-
8/12/2019 SR3_NFA
22/33
NFA DFA (Contd )
-
8/12/2019 SR3_NFA
23/33
NFA=DFA (Contd.)
NFA has an equivalent DFA . . . proof contd.
Let N= (Q,, ,q 0, F) be the NFAand M= (Q,, , q0, F
) be the equivalent DFA. Both N and Mrecognizes the same language A.
Case I: There is no arrow in the NFA N.1 Q =P(Q), because every state ofM is aset of statesofN
2 q0={q0}
3 F ={RQ| R contains an accept-state ofN}
4 For RQ and aQ
(R, a) ={qQ| q(r, a) for some rR}(R, a) =
rR
(r, a) set of all states reachable from all states ofRfor input a according to the ofN
Shaifur (CSE, BUET) CSE211: NFA Class 4 14 / 23
-
8/12/2019 SR3_NFA
24/33
-
8/12/2019 SR3_NFA
25/33
NFA=DFA (Contd )
-
8/12/2019 SR3_NFA
26/33
NFA=DFA (Contd.)
Corollary 1.40A language is regularif and only ifsome non-deterministic finiteautomaton recognizes it
ProofA language is regularifsome NFA recognizes itIf some NFA recognizes the language, so does an equivalent DFA.Hence, the language is regular.
A language is regularonly ifsome NFA recognizes itIf a language is regular, a DFA recognizes it. A DFA is also an NFA.So, an NFA also recognizes the regular language.
Shaifur (CSE, BUET) CSE211: NFA Class 4 16 / 23
Examples of Conversion from NFA to DFA
-
8/12/2019 SR3_NFA
27/33
Examples of Conversion from NFA to DFA
DFA= (Q,, ,q 0, F)
Q= {, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}, }
={a, b}
q0=E({1}) ={1, 3}
F ={ All states ofQ that have a final state ofN}={{1}, {1, 2}, {1, 3}, {1, 2, 3}}
Shaifur (CSE, BUET) CSE211: NFA Class 4 17 / 23
Examples of Conversion from NFA to DFA (Contd )
-
8/12/2019 SR3_NFA
28/33
Examples of Conversion from NFA to DFA (Contd.)
Transition Function =?
On input a: {2} {2, 3}, on input b: {2} {3}
On input a: {1} , on input b: {1} {2}
On input a: {3} {1, 3}, on input b: {3}
On input a: {1, 2} {2, 3}, on input b: {1, 2} {2, 3}
Similarly, for rest of the states . . .Shaifur (CSE, BUET) CSE211: NFA Class 4 18 / 23
Correction to class lecture
-
8/12/2019 SR3_NFA
29/33
Correction to class lecture
attention: follow after applying (), not before!
({1}, a) = INCORRECT!, (E({1}), a) =({1, 3}, a) ={1}But, ({3}, a) =E({1}) ={1, 3}
Shaifur (CSE, BUET) CSE211: NFA Class 4 19 / 23
Examples of Conversion from NFA to DFA (Contd.)
-
8/12/2019 SR3_NFA
30/33
Examples of Conversion from NFA to DFA (Contd.)
After conversion . . .
Shaifur (CSE, BUET) CSE211: NFA Class 4 20 / 23
Examples of Conversion from NFA to DFA (Contd.)
-
8/12/2019 SR3_NFA
31/33
Examples of Conversion from NFA to DFA (Contd.)
After conversion and simplification . . .
Dropping the states from which there is no outgoing arrow
Shaifur (CSE, BUET) CSE211: NFA Class 4 21 / 23
Try Yourself
-
8/12/2019 SR3_NFA
32/33
y
Convert the following NFA into the equivalent DFA
Shaifur (CSE, BUET) CSE211: NFA Class 4 22 / 23
-
8/12/2019 SR3_NFA
33/33
Question?
Shaifur (CSE, BUET) CSE211: NFA Class 4 23 / 23