Non-Deterministic Finite Automt Fll 2018 Costs Busch - RPI 1
Nondeterministic Finite Automton (NFA) Alphbet ={} q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 2
Nondeterministic Finite Automton (NFA) Alphbet ={} q q2 1 λ Σ- q3 Σ- q 1 q 2 q 1 q 2 q 1 q 2 A B C Fll 2018 Costs Busch - RPI 3
Alphbet ={} Two choices q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 4
Alphbet ={} Two choices q q2 1 No trnsition q 0 q 3 No trnsition Fll 2018 Costs Busch - RPI 5
First Choice q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 6
First Choice q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 7
First Choice All input is consumed q q2 1 ccept q 0 q 3 Fll 2018 Costs Busch - RPI 8
Second Choice q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 9
q 0 Second Choice Input cnnot be consumed q q2 1 q 3 Automton Hlts reject Fll 2018 Costs Busch - RPI 10
An NFA ccepts string: if there is computtion of the NFA tht ccepts the string i.e., ll the input string is processed nd the utomton is in n ccepting stte Fll 2018 Costs Busch - RPI 11
is ccepted by the NFA: ccept q q1 2 q1 q2 q 0 q 3 becuse this computtion ccepts Fll 2018 Costs Busch - RPI 12 q 0 q 3 reject this computtion is ignored
Rejection exmple q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 13
First Choice reject q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 14
Second Choice 1 q q2 q 0 q 3 Fll 2018 Costs Busch - RPI 15
Second Choice 1 q q2 q 0 q 3 reject Fll 2018 Costs Busch - RPI 16
Another Rejection exmple q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 17
First Choice q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 18
First Choice Input cnnot be consumed q q2 1 reject q 0 q 3 Automton hlts Fll 2018 Costs Busch - RPI 19
Second Choice q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 20
q 0 Second Choice Input cnnot be consumed q q2 1 q 3 Automton hlts reject Fll 2018 Costs Busch - RPI 21
An NFA rejects string: if there is no computtion of the NFA tht ccepts the string. For ech computtion: All the input is consumed nd the utomton is in non finl stte OR The input cnnot be consumed Fll 2018 Costs Busch - RPI 22
is rejected by the NFA: q q1 2 reject q1 2 q q 0 q 3 reject q 0 q 3 All possible computtions led to rejection Fll 2018 Costs Busch - RPI 23
is rejected by the NFA: reject q q1 2 q1 q2 q 0 q 3 q 0 q 3 reject All possible computtions led to rejection Fll 2018 Costs Busch - RPI 24
Lnguge ccepted: L {} q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 25
NFA: Mouse Mze Fll 2018 Costs Busch - RPI 26
Lmbd Trnsitions q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 27
q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 28
q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 29
input tpe hed does not move q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 30
ll input is consumed q0 ccept q1 q 2 q3 String is ccepted Fll 2018 Costs Busch - RPI 31
Rejection Exmple q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 32
q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 33
(red hed doesn t move) q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 34
Input cnnot be consumed Automton hlts reject q0 q1 q 2 q3 String is rejected Fll 2018 Costs Busch - RPI 35
Lnguge ccepted: L {} q0 q1 q 2 q3 Fll 2018 Costs Busch - RPI 36
Another NFA Exmple q b q 2 q0 1 q 3 Fll 2018 Costs Busch - RPI 37
b q b q 2 q0 1 q 3 Fll 2018 Costs Busch - RPI 38
b q b q 2 0 q 1 q 3 Fll 2018 Costs Busch - RPI 39
b ccept q q1 b 0 q 2 q 3 Fll 2018 Costs Busch - RPI 40
Another String b b q q b 1 q2 q3 0 Fll 2018 Costs Busch - RPI 41
b b q q b 1 q2 q3 0 Fll 2018 Costs Busch - RPI 42
b b q q b 1 q2 q3 0 Fll 2018 Costs Busch - RPI 43
b b q q b 1 q2 q3 0 Fll 2018 Costs Busch - RPI 44
b b q q b 1 q2 q3 0 Fll 2018 Costs Busch - RPI 45
b b q q b 1 q2 q3 0 Fll 2018 Costs Busch - RPI 46
b b q q b 1 q2 q3 0 ccept Fll 2018 Costs Busch - RPI 47
Lnguge ccepted L b, bb, bbb,... b q b q 2 q0 1 q 3 Fll 2018 Costs Busch - RPI 48
Another NFA Exmple Wht is the lnguge ccepted?? 0 q0 1 1 q 0,1 q2 Fll 2018 Costs Busch - RPI 49
Lnguge ccepted 0 q0 1 1 q 0,1 q2 (redundnt stte) Fll 2018 Costs Busch - RPI 50
Remrks: The symbol never ppers on the input tpe Simple utomt: M 1 q 0 M 2 q 0 L(M 1 ) ={} (M ) = {λ} L 2 Fll 2018 Costs Busch - RPI 51
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( M2) = { } Fll 2018 Costs Busch - RPI 52
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 : Accepting sttes Fll 2018 Costs Busch - RPI 53
Trnsition Function q x q, q,,, 1 2 q k x q 1 resulting sttes with q x x q 1 following one trnsition with symbol x q k Fll 2018 Costs Busch - RPI 54
q, q 0 1 1 0 q0 1 1 q 0,1 q2 Fll 2018 Costs Busch - RPI 55
( q1,0) { q0, q2} 0 q 0 1 0 q 0,1 q2 1 Fll 2018 Costs Busch - RPI 56
( q, ) { q } 0 2 0 q 0 1 q 0,1 q2 1 Fll 2018 Costs Busch - RPI 57
( q,1) 2 q 0 0 1 q 0,1 q2 1 Fll 2018 Costs Busch - RPI 58
Extended Trnsition Function * Sme with but pplied on strings * q, q 0 1 q 4 q 5 q 0 q 1 b q 2 q 3 Fll 2018 Costs Busch - RPI 59
* q, q, q 0 4 5 q 4 q 5 q 0 q 1 b q 2 q 3 Fll 2018 Costs Busch - RPI 60
* q, b q, q, q 0 2 3 0 q 4 q 5 q 0 q 1 b q 2 q 3 Fll 2018 Costs Busch - RPI 61
Specil cse: for ny stte q q * q, Fll 2018 Costs Busch - RPI 62
Fll 2018 Costs Busch - RPI 63 w q q i j, * : there is wlk from to with lbel i q j q w i q j q w w k 2 1 1 2 k i q j q In generl
The Lnguge of n NFA The lnguge ccepted by M is: M M w w L,... 1, 2 w n where * ( q 0, w m ) { q i,..., q k,, q j } nd there is some q k F (ccepting stte) Fll 2018 Costs Busch - RPI 64
w m L M * ( q, w 0 m ) w m q i q0 w m qk q k F w m q j Fll 2018 Costs Busch - RPI 65
F q 0,q 5 q 4 q 5 q 0 q 1 b q 2 q 3 * q, q, q 0 4 5 F L(M) Fll 2018 Costs Busch - RPI 66
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 F Fll 2018 Costs Busch - RPI 67
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 bl(m ) F Fll 2018 Costs Busch - RPI 68
F q 0,q 5 q 4 q 5 q 0 q 1 b q 2 q 3 * q 0, b q b LM 1 F Fll 2018 Costs Busch - RPI 69
q 4 q 5 q 0 q 1 b q 2 q 3 L M b* b * { } Fll 2018 Costs Busch - RPI 70
NFAs ccept the Regulr Lnguges Fll 2018 Costs Busch - RPI 71
Equivlence of Mchines Definition: Mchine M1 is equivlent to mchine M2 if LM 1 L M 2 Fll 2018 Costs Busch - RPI 72
Exmple of equivlent mchines LM 1 {10} * NFA 0 q q 0 1 1 M 1 LM 2 {10} * q q 1 0 1 q2 1 Fll 2018 Costs Busch - RPI 73 0 DFA 0 M 2 0,1
0 q1 1 q2 Fll 2018 Costs Busch - RPI 74
Theorem: Lnguges ccepted by NFAs Regulr Lnguges Lnguges ccepted by DFAs NFAs nd DFAs hve the sme computtion power, ccept the sme set of lnguges Fll 2018 Costs Busch - RPI 75
Proof: we only need to show Lnguges ccepted by NFAs Lnguges ccepted by NFAs AND Regulr Lnguges Regulr Lnguges Fll 2018 Costs Busch - RPI 76
Proof-Step 1 Lnguges ccepted by NFAs Regulr Lnguges Every DFA is trivilly n NFA Any lnguge L ccepted by DFA is lso ccepted by n NFA Fll 2018 Costs Busch - RPI 77
Proof-Step 2 Lnguges ccepted by NFAs Regulr Lnguges Any NFA cn be converted to n equivlent DFA Any lnguge L is lso ccepted by DFA ccepted by n NFA Fll 2018 Costs Busch - RPI 78
NFA M Conversion NFA to DFA q 0 q1 q2 b DFA M q 0 Fll 2018 Costs Busch - RPI 79
NFA M * ( q0, ) { q1, q2 } q 0 q1 q2 b DFA M q 0 q 1,q 2 Fll 2018 Costs Busch - RPI 80
NFA M * ( q 0, b) q 0 q1 q2 b empty set DFA M q 0 q 1,q 2 b trp stte Fll 2018 Costs Busch - RPI 81
NFA DFA M M q 0 q1 q2 b q 0 q 1,q 2 b * ( q1, ) { q1, q2 } * ( q 2, ) union q 1,q 2 Fll 2018 Costs Busch - RPI 82
NFA M q 0 q1 q2 b * ( q1, b) { q0} * q, b) { q } ( 2 0 union q 0 DFA M b q 0 q 1,q 2 b Fll 2018 Costs Busch - RPI 83
NFA M q 0 q1 q2 b DFA M b q 0 q 1,q 2 b,b trp stte Fll 2018 Costs Busch - RPI 84
NFA M END OF CONSTRUCTION q 0 q1 q2 b q F 1 DFA M b q 0 q 1,q 2 b q q F 1, 2,b Fll 2018 Costs Busch - RPI 85
Generl Conversion Procedure Input: n NFA M Output: n equivlent DFA with LM L(M ) M Fll 2018 Costs Busch - RPI 86
The NFA hs sttes q, q, q,... 0 1 2 The DFA hs sttes from the power set,,,,,,,..., q q q q q q q 0 1 0 1 1 2 3 Fll 2018 Costs Busch - RPI 87
Conversion Procedure Steps step 1. Initil stte of NFA: q 0 Initil stte of DFA: q 0 Fll 2018 Costs Busch - RPI 88
Exmple NFA M q 0 q1 q2 b DFA M q 0 Fll 2018 Costs Busch - RPI 89
Fll 2018 Costs Busch - RPI 90 2. For every DFA s stte compute in the NFA dd trnsition to DFA },...,, { m j i q q q q q q m j i, *..., *, * },...,, { n l k q q q },...,, { },,...,, { n l k m j i q q q q q q Union step
Exmple NFA M *( q0, ) { q1, q2} q 0 q1 q2 b DFA M q, q q 0 1, q 0 q 1,q 2 2 Fll 2018 Costs Busch - RPI 91
step 3. Repet Step 2 for every stte in DFA nd symbols in lphbet until no more sttes cn be dded in the DFA Fll 2018 Costs Busch - RPI 92
Exmple NFA M q 0 q1 q2 b DFA M b q 0 q 1,q 2 b,b Fll 2018 Costs Busch - RPI 93
step 4. For ny DFA stte { qi, q j,..., qm} if some q j is ccepting stte in NFA Then, { qi, q j,..., qm} is ccepting stte in DFA Fll 2018 Costs Busch - RPI 94
Exmple NFA M q 0 q1 q2 b q F 1 DFA M b q 0 q 1,q 2 b q q F 1, 2,b Fll 2018 Costs Busch - RPI 95
Lemm: If we convert NFA M to DFA then the two utomt re equivlent: LM LM M Proof: We only need to show: LM LM AND LM LM Fll 2018 Costs Busch - RPI 96
First we show: LM LM We only need to prove: wl(m ) wl(m ) Fll 2018 Costs Busch - RPI 97
NFA Consider wl(m ) q0 w q f symbols w 1 2 k q0 1 2 k q f Fll 2018 Costs Busch - RPI 98
symbol q i i q j denotes possible sub-pth like qi symbol i q j Fll 2018 Costs Busch - RPI 99
We will show tht if wl(m ) NFA M : q0 1 2 w 1 2 k k q f then DFA M : { q 0 } stte lbel 1 2 w L(M ) Fll 2018 Costs Busch - RPI 100 k {, } q f stte lbel
More generlly, we will show tht if in : M NFA (rbitrry string) M : q0 v 1 1 2 qi 2 q j n ql n qm then DFA M : { q 0 } 1 2 {, } q i n { q, } { q, } {, } j l q m Fll 2018 Costs Busch - RPI 101
Proof by induction on v v Induction Bsis: v 1 1 NFA M : q 1 0 q i DFA M : { q 0 } 1 {, } q i is true by construction of M Fll 2018 Costs Busch - RPI 102
Induction hypothesis: 1 v k v 1 2 k NFA M Suppose tht the following hold : q0 1 2 qi q j qc k qd DFA M : { q 0 } 1 2 k { q, } { q, } { q, } {, } i j c q d Fll 2018 Costs Busch - RPI 103
Induction Step: v k 1 NFA M : q0 v 1 2 qi 1 2 k k1 k1 v Then this is true by construction of M q j qc k qd v k1 q e v DFA M : { q 0 } 1 2 k { q, } { q, } { q, } {, } i j c q d k1 {, } q e Fll 2018 Costs Busch - RPI 104 v
Therefore if wl(m ) w 1 2 k NFA M : q0 1 2 k q f then DFA M : { q 0 } 1 2 k {, } q f w L(M ) Fll 2018 Costs Busch - RPI 105
We hve shown: LM LM With similr proof we cn show: LM LM Therefore: LM LM END OF LEMMA PROOF Fll 2018 Costs Busch - RPI 106