Chpter Five: Nondeterministic Finite Automt Forml Lnguge, chpter 5, slide 1 1
A DFA hs exctly one trnsition from every stte on every symol in the lphet. By relxing this requirement we get relted ut more flexile kind of utomton: the nondeterministic finite utomton or NFA. NFAs re it hrder to think out thn DFAs, ecuse they do not pper to define simple computtionl processes. They my seem t first to e unnturl, like puzzles invented y professors for the torment of students. But hve ptience! NFAs nd other kinds of nondeterministic utomt rise nturlly in mny wys, s you will see lter in this ook, nd they too hve vriety of prcticl pplictions. Forml Lnguge, chpter 5, slide 2 2
Outline 5.1 Relxing Requirement 5.2 Spontneous Trnsitions 5.3 Nondeterminism 5.4 The 5-Tuple for n NFA 5.5 The Lnguge Accepted y n NFA Forml Lnguge, chpter 5, slide 3 3
Not A DFA q 0 q 1, Does not hve exctly one trnsition from every stte on every symol: Two trnsitions from q 0 on No trnsition from q 0 (on either or ) Though not DFA, this cn e tken s defining lnguge, in slightly different wy Forml Lnguge, chpter 5, slide 4 4
Possile Sequences of Moves q 0 q 1, We'll consider ll possile sequences of moves the mchine might mke for given string For exmple, on the string there re three: From q 0 to q 0 to q 0, rejecting From q 0 to q 0 to q 1, ccepting From q 0 to q 1, getting stuck on the lst Our convention for this new kind of mchine: string is in L(M) if there is t lest one ccepting sequence Forml Lnguge, chpter 5, slide 5 5
Nondeterministic Finite Automton (NFA) q 0 q 1, L(M) = the set of strings tht hve t lest one ccepting sequence In the exmple ove, L(M) = {x x {,}*} A DFA is specil cse of n NFA: An NFA tht hppens to e deterministic: there is exctly one trnsition from every stte on every symol So there is exctly one possile sequence for every string NFA is not necessrily deterministic Forml Lnguge, chpter 5, slide 6 6
NFA Advntge An NFA for lnguge cn e smller nd esier to construct thn DFA Strings whose next-to-lst symol is 1: 0 DFA: 1 NFA: 0 0 0 1 1 0,1 1 0,1 1 Forml Lnguge, chpter 5, slide 7 7
Outline 5.1 Relxing Requirement 5.2 Spontneous Trnsitions 5.3 Nondeterminism 5.4 The 5-Tuple for n NFA 5.5 The Lnguge Accepted y n NFA Forml Lnguge, chpter 5, slide 8 8
Spontneous Trnsitions An NFA cn mke stte trnsition spontneously, without consuming n input symol Shown s n rrow leled with ε For exmple, {}* {}*: q 1 q 0 q 2 Forml Lnguge, chpter 5, slide 9 9
ε-trnsitions To Accepting Sttes q 1 q 0 q 2 An ε-trnsition cn e mde t ny time For exmple, there re three sequences on the empty string No moves, ending in q 0, rejecting From q 0 to q 1, ccepting From q 0 to q 2, ccepting Any stte with n ε-trnsition to n ccepting stte ends up working like n ccepting stte too Forml Lnguge, chpter 5, slide 10 10
ε-trnsitions For NFA Comining q 1 q 0 ε-trnsitions re useful for comining smller utomt into lrger ones This mchine is comines mchine for {}* nd mchine for {}* It uses n ε-trnsition t the strt to chieve the union of the two lnguges q 2 Forml Lnguge, chpter 5, slide 11 11
Incorrect Union A = { n n is odd} B = { n n is odd} A B? No: this NFA ccepts Forml Lnguge, chpter 5, slide 12 12
Correct Union A = { n n is odd} B = { n n is odd} A B Forml Lnguge, chpter 5, slide 13 13
Incorrect Conctention A = { n n is odd} B = { n n is odd} {xy x A nd y B}? No: this NFA ccepts Forml Lnguge, chpter 5, slide 14 14
Correct Conctention A = { n n is odd} B = { n n is odd} {xy x A nd y B} Forml Lnguge, chpter 5, slide 15 15
Outline 5.1 Relxing Requirement 5.2 Spontneous Trnsitions 5.3 Nondeterminism 5.4 The 5-Tuple for n NFA 5.5 The Lnguge Accepted y n NFA Forml Lnguge, chpter 5, slide 16 16
DFAs nd NFAs DFAs nd NFAs oth define lnguges DFAs do it y giving simple computtionl procedure for deciding lnguge memership: Strt in the strt stte Mke one trnsition on ech symol in the string See if the finl stte is ccepting NFAs do it without such cler-cut procedure: Serch ll legl sequences of trnsitions on the input string? How? In wht order? Forml Lnguge, chpter 5, slide 17 17
Nondeterminism The essence of nondeterminism: For given input there cn e more thn one legl sequence of steps The input is in the lnguge if t lest one of the legl sequences sys so We cn chieve the sme result y deterministiclly serching the legl sequences, ut...this nondeterminism does not directly correspond to nything in physicl computer systems In spite of tht, NFAs hve mny prcticl pplictions Forml Lnguge, chpter 5, slide 18 18
Outline 5.1 Relxing Requirement 5.2 Spontneous Trnsitions 5.3 Nondeterminism 5.4 The 5-Tuple for n NFA 5.5 The Lnguge Accepted y n NFA Forml Lnguge, chpter 5, slide 19 19
Powerset If S is set, the powerset of S is the set of ll susets of S: P(S) = {R R S} This lwys includes the empty set nd S itself For exmple, P({1,2,3}) = {{}, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}} Forml Lnguge, chpter 5, slide 20 20
The 5-Tuple An NFA M is 5-tuple M = (Q, Σ, δ, q 0, F), where: Q is the finite set of sttes Σ is the lphet (tht is, finite set of symols) δ (Q (Σ {ε}) P(Q)) is the trnsition function q 0 Q is the strt stte F Q is the set of ccepting sttes The only chnge from DFA is the trnsition function δ δ tkes two inputs: A stte from Q (the current stte) A symol from Σ {ε} (the next input, or ε for n ε-trnsition) δ produces one output: A suset of Q (the set of possile next sttes) Forml Lnguge, chpter 5, slide 21 21
, Exmple: q 0 q 1 q 2 Formlly, M = (Q, Σ, δ, q 0, F), where Q = {q 0,q 1,q 2 } Σ = {,} (we ssume: it must contin t lest nd ) F = {q 2 } δ(q 0,) = {q 0,q 1 }, δ(q 0,) = {q 0 }, δ(q 0,ε) = {q 2 }, δ(q 1,) = {}, δ(q 1,) = {q 2 }, δ(q 1,ε) = {} δ(q 2,) = {}, δ(q 2,) = {}, δ(q 2,ε) = {} The lnguge defined is {,}* Forml Lnguge, chpter 5, slide 22 22
Outline 5.1 Relxing Requirement 5.2 Spontneous Trnsitions 5.3 Nondeterminism 5.4 The 5-Tuple for n NFA 5.5 The Lnguge Accepted y n NFA Forml Lnguge, chpter 5, slide 23 23
The δ* Function The δ function gives 1-symol moves We'll define δ* so it gives whole-string results (y pplying zero or more δ moves) For DFAs, we used this recursive definition δ*(q,ε) = q δ*(q,x) = δ(δ*(q,x),) The intuition is the similr for NFAs, ut the ε-trnsitions dd some technicl hir Forml Lnguge, chpter 5, slide 24 24
NFA IDs An instntneous description (ID) is description of point in n NFA's execution It is pir (q,x) where q Q is the current stte x Σ* is the unred prt of the input Initilly, n NFA processing string x hs the ID (q 0,x) An ccepting sequence of moves ends in n ID (f,ε) for some ccepting stte f F Forml Lnguge, chpter 5, slide 25 25
The One-Move Reltion On IDs We write I! J if I is n ID nd J is n ID tht could follow from I fter one move of the NFA Tht is, for ny string x Σ* nd ny ω Σ or ω = ε, ( q,ωx)! ( r,x) if nd only if r δ( q,w) Forml Lnguge, chpter 5, slide 26 26
The Zero-Or-More-Move Reltion We write I! J if there is sequence of zero or more moves tht strts with I nd ends with J: I! "! J Becuse it llows zero moves, it is reflexive reltion: for ll IDs I, I! I Forml Lnguge, chpter 5, slide 27 27
The δ* Function Now we cn define the δ* function for NFAs: δ q, x { } ( ) = r ( q, x)! ( r,ε) Intuitively, δ*(q,x) is the set of ll sttes the NFA might e in fter strting in stte q nd reding x Our definition llows ε-trnsitions, including those mde efore the first symol of x is red, nd those mde fter the lst Forml Lnguge, chpter 5, slide 28 28
M Accepts x Now δ*(q,x) is the set of sttes M my end in, strting from stte q nd reding ll of string x So δ*(q 0,x) tells us whether M ccepts x: A string x Σ* is ccepted y n NFA M = (Q, Σ, δ, q 0, F) if nd only if δ*(q 0, x) contins t lest one element of F. Forml Lnguge, chpter 5, slide 29 29
The Lnguge An NFA Defines For ny NFA M = (Q, Σ, δ, q 0, F), L(M) denotes the lnguge ccepted y M, which is L(M) = {x Σ* δ*(q 0, x) F {}}. Forml Lnguge, chpter 5, slide 30 30