Non Deterministic Automt Linz: Nondeterministic Finite Accepters, pge 51 1
Nondeterministic Finite Accepter (NFA) Alphbet ={} q 1 q2 q 0 q 3 2
Nondeterministic Finite Accepter (NFA) Alphbet ={} Two choices q 1 q2 q 0 q 3 3
Nondeterministic Finite Accepter (NFA) Alphbet ={} Two choices q 1 q2 No trnsition q 0 q 3 No trnsition 4
First Choice q 1 q2 q 0 q 3 5
First Choice q 1 q2 q 0 q 3 6
First Choice q 1 q2 q 0 q 3 7
First Choice All input is consumed q 1 q2 ccept q 0 q 3 8
Second Choice q 1 q2 q 0 q 3 9
Second Choice q 1 q2 q 0 q 3 10
Second Choice q 1 q2 q 0 q 3 No trnsition: the utomton hngs 11
Second Choice Input cnnot be consumed q 1 q2 q 0 q 3 reject 12
An NFA ccepts string: when there is computtion of the NFA tht ccepts the string All the input is consumed nd the utomton is in finl stte 13
Exmple is ccepted by the NFA: ccept q 1 q2 q 1 q2 q 0 q 3 q 0 q 3 reject becuse this computtion ccepts 14
Rejection exmple q 1 q2 q 0 q 3 15
First Choice q 1 q2 q 0 q 3 16
First Choice reject q 1 q2 q 0 q 3 17
Second Choice q 1 q2 q 0 q 3 18
Second Choice q 1 q2 q 0 q 3 19
Second Choice q 1 q2 q 0 q 3 reject 20
An NFA rejects string: when there is no computtion of the NFA tht ccepts the string All the input is consumed nd the utomton is in non finl stte The input cnnot be consumed 21
Exmple is rejected by the NFA: q 1 q2 reject q 1 q2 q 0 q 3 reject q 0 q 3 All possible computtions led to rejection 22
Rejection exmple q 1 q2 q 0 q 3 23
First Choice q 1 q2 q 0 q 3 24
First Choice q 1 q2 q 0 q 3 No trnsition: the utomton hngs 25
First Choice Input cnnot be consumed q 1 q2 reject q 0 q 3 26
Second Choice q 1 q2 q 0 q 3 27
Second Choice q 1 q2 q 0 q 3 28
Second Choice q 1 q2 q 0 q 3 No trnsition: the utomton hngs 29
Second Choice Input cnnot be consumed q 1 q2 q 0 q 3 reject 30
is rejected by the NFA: reject q 1 q2 q 1 q2 q 0 q 3 q 0 q 3 reject All possible computtions led to rejection 31
Lnguge ccepted: L {} q 1 q2 q 0 q 3 32
Lmbd Trnsitions q0 q q3 1 q2 33
q0 q q3 1 q2 34
q0 q q3 1 q2 35
(red hed doesn t move) q0 q q3 1 q2 36
q0 q q3 1 q2 37
ll input is consumed q0 q q3 1 q2 ccept String is ccepted 38
Rejection Exmple q0 q q3 1 q2 39
q0 q q3 1 q2 40
(red hed doesn t move) q0 q q3 1 q2 41
q0 q q3 1 q2 No trnsition: the utomton hngs 42
Input cnnot be consumed q0 q q3 1 q2 reject String is rejected 43
Lnguge ccepted: L {} q0 q q3 1 q2 44
Another NFA Exmple q b q 2 q0 1 q 3 45
b q b q 2 q0 1 q 3 46
b q b q 2 0 q 1 q 3 47
b q q b 1 0 q 2 q 3 48
b q q b 1 0 ccept q 2 q 3 49
Another String b b q b q q3 0 q1 2 50
b b q b q q3 0 q1 2 51
b b q b q q3 0 q1 2 52
b b q b q q3 0 q1 2 53
b b q b q q3 0 q1 2 54
b b q b q q3 0 q1 2 55
b b q b q q3 0 q1 2 56
b b q b q q3 0 ccept q1 2 57
Lnguge ccepted L b, bb, bbb,... b q b q 2 q0 1 q 3 58
Another NFA Exmple 0 q0 1 1 q 0,1 q2 59
Lnguge ccepted L(M ) = = { } λ, 10, { 10}* 0 1010, 101010,... q0 1 1 q 0,1 q2 60
Remrks: The symbol never ppers on the input tpe Extreme utomt: M 1 q 0 M 2 q 0 L(M 1 ) = {} (M ) = {λ} L 2 61
NFAs re interesting becuse we cn express lnguges esier thn DFAs NFA M 1 DFA M 2 q 0 q1 q 2 q 0 q 1 L( M1) = { } L( M 2) = { } 62
Forml Definition of NFAs M Q,,, q0, F Q : Set of sttes, i.e. q, q q 0 1, 2 : Input plhbet, i.e., b : Trnsition function q 0 : Initil stte F : Finl sttes 63
Trnsition Function q, q 0 1 1 0 q0 1 1 q 0,1 q2 64
( q1,0) { q0, q2} 0 q 0 1 q 0,1 1 q2 65
( q0, ) { q0, q2} 0 q 0 1 q 0,1 1 q2 66
( q 2,1) q 0 0 1 q 0,1 1 q2 67
Extended Trnsition Function * * q q 0, 1 q 4 q 5 q 0 q 1 b q 2 q 3 68
q * q q 0, 4, 5 q 4 q 5 q 0 q 1 b q 2 q 3 69
q b * q q q 0, 2, 3, 0 q 4 q 5 q 0 q 1 b q 2 q 3 70
It holds q Formlly j * qi, w if nd only if there is wlk from with lbel w qi to q j 71
The Lnguge of n NFA M F q 0,q 5 q 4 q 5 q 0 q 1 b q 2 q 3 q * q q 0, 4, 5 L(M ) 72
F q 0,q 5 q 4 q 5 q 0 q 1 b q 2 q 3 q b * q q q b LM 0, 2, 3, 0 73
F q 0,q 5 q 4 q 5 q 0 q 1 b q 2 q 3 q b * q q 0, 4, 5 b L(M ) 74
F q 0,q 5 q 4 q 5 q 0 q 1 b q 2 q 3 * q b q b LM 0, 1 75
q 4 q 5 q 0 q 1 b q 2 q 3 L M b* b 76
Formlly The lnguge ccepted by NFA M is: L M,,... w1 w w, 2 3 where *( q 0, w m ) { q i, q j,...} nd there is some q k F (finl stte) 77
w L M *( q 0, w) w q i q0 w qk q k F w q j 78
Equivlence of NFAs nd DFAs Linz: 2.3 Equivlence of Deterministic nd Nondeterministic Finite Accepters, pge 58 79
Equivlence of Mchines For DFAs or NFAs: Mchine M1 is equivlent to mchine M 2 if LM 1 L M 2 80
L M 1 {10} * Exmple 0 q0 1 1 NFA q 0,1 q2 M 1 L M 2 {10} * 0 DFA q q 1 0 1 q2 1 0 M 2 0,1 81
Since L 10* M1 L M2 M M 2 mchines 1 nd re equivlent NFA M1 0 q q 0 1 2 1 0,1 q DFA M 2 0 q q 0 1 2 1 0 1 0,1 q 82
Equivlence of NFAs nd DFAs Question: NFAs = DFAs? Sme power? Accept the sme lnguges? 83
Equivlence of NFAs nd DFAs Question: NFAs = DFAs? YES! Sme power? Accept the sme lnguges? 84
We will prove: Lnguges ccepted by NFAs Lnguges ccepted by DFAs NFAs nd DFAs hve the sme computtion power 85
Step 1 Lnguges ccepted by NFAs Lnguges ccepted by DFAs Proof: Every DFA is trivilly n NFA A lnguge ccepted by DFA is lso ccepted by n NFA 86
Step 2 Lnguges ccepted by NFAs Lnguges ccepted by DFAs Proof: Any NFA cn be converted to n equivlent DFA A lnguge ccepted by n NFA is lso ccepted by DFA 87
NFA M NFA to DFA q 0 q1 q2 b DFA M q 0 88
NFA M NFA to DFA q 0 q1 q2 b DFA M q 0 q 1,q 2 89
NFA M NFA to DFA q 0 q1 q2 b DFA M q 0 q 1,q 2 b 90
NFA M NFA to DFA q 0 q1 q2 b DFA M q 0 q 1,q 2 b 91
NFA M NFA to DFA q 0 q1 q2 b DFA M b q 0 q 1,q 2 b 92
NFA M NFA to DFA q 0 q1 q2 b DFA M b q 0 q 1,q 2 b,b 93
NFA M NFA to DFA q 0 q1 q2 b LM L(M) DFA M b q 0 q 1,q 2 b,b 94
NFA to DFA: Remrks We re given n NFA M We wnt to convert it to n equivlent DFA M With LM L(M) 95
If the NFA hs sttes q0, q1, q2,... the DFA hs sttes in the powerset,,,,,,,..., q0 q1 q1 q2 q3 q4 q7 96
Procedure NFA to DFA 1. Initil stte of NFA: q 0 Initil stte of DFA: q 0 97
NFA M Exmple q 0 q1 q2 b DFA M q 0 98
Procedure NFA to DFA 2. For every DFA s stte { q, q,..., q } i j m Compute in the NFA * * q q i j,,,, { qi, qj,..., qm }... Add trnsition to DFA q, q,..., q }, { q, q,..., q } { i j m i j m 99
NFA DFA M M Exmpe q 0 q1 q2 b *( q0, ) { q1, q2} q 0 q 1,q 2 q, q q 0 1, 2 100
Procedure NFA to DFA Repet Step 2 for ll letters in lphbet, until no more trnsitions cn be dded. 101
NFA M Exmple q 0 q1 q2 b DFA M b q 0 q 1,q 2 b,b 102
Procedure NFA to DFA 3. For ny DFA stte { qi, q j,..., qm} If some q j is finl stte in the NFA Then, { qi, q j,..., qm} is finl stte in the DFA 103
NFA M Exmple q 0 q1 q2 b q F 1 DFA M b b q 0 q 1,q 2,b q q F 1, 2 104
Tke NFA M Theorem Apply procedure to obtin DFA M Then M nd M re equivlent : LM LM 105
Finlly We hve proven Lnguges ccepted by NFAs Lnguges ccepted by DFAs 106
We hve proven Lnguges ccepted by NFAs Lnguges ccepted by DFAs Regulr Lnguges 107
We hve proven Lnguges ccepted by NFAs Lnguges ccepted by DFAs Regulr Lnguges Regulr Lnguges 108
We hve proven Lnguges ccepted by NFAs Lnguges ccepted by DFAs Regulr Lnguges Regulr Lnguges Thus, NFAs ccept the regulr lnguges 109