0% found this document useful (0 votes)
41 views

TOC Lec3

Uploaded by

Mohammed Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
41 views

TOC Lec3

Uploaded by

Mohammed Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 51
NONDETERMINISTIC FINITE ACCEPTER (NFA) For each input symbol and every state, the transiti + Zero or more transitions (None/one/more outgoing arrows) diagram may have Unlike a DFA M (where M can only bi one state at a time), an NFA can be in multiple states at one allows running processes simultaneously (parallelly). Ais considered as one input symbol + Mransition allows moving from one state to another without consuming any input symbol a € E. Non-determi * Allows bi ing automata in an easier way. NFA: Formal definition + ANFA is a quintuple (Q, 5, 5, dy F), where: * Qis a finite and non-empty set of internal states. * Lis a finite input alphabet. +8: Qx (ZU {A}) > 22% is the transition function. * do € Qis the initial state. * F CQis the set of accepting states. + The input of 6 is an ordered pair of state and input symbol or i. + The output values of 5 may be a set of states. 5@, x) = {41,492 6:Q@xzr —-Q@ 6G x)= % —% NFA-Transition Function yt ZT S(a0,1)= ta} 8 (40,4) = {40,42} COED 0 re A 8(q, D> a =a.) ce aa Naud 0,1 SCG a)E222, 5(q2,A) =??? Oe *'@ 4 ee gy WY \ wae LJ 4% NFA Transition Function M = (Q, %, 8, qo, F) eed 2 O< 2 UN) > 2° Oe n oo (404) = (40. 42} q , 5(41,0) = (40, 42} F= {ao 8(a1 1) = {a2} aa [few or | oe) IDENTIFY DFA/NFA ? ab —~ > 92 | accept Bie cy aay +40)-9 (G1) +(e) 293) 94, NFA CONSTRUCTION- EASY ~ Accept all strings with at least length three that contains a1 in the third from the end z={0,1}, The form of the strings - w,1w,W,, w, 8 {0, 1}*, w, £ {0,1}, w, 2 £0, 1} (a9) + What makes this difficult for a DFA? 0,1 ‘Accept all strings containing substring 001 = (00001, 000100, 00010100...) z={0,1} 1 o jaz 1 i of 0,1 ea. 0) © 00) 1.600) STRING ACCEPTANCE/REJECTION BY NFA es 6 First Choice UY 4 a\a aja (2.4 (+ @) ia © 40\ Automaton Halts a reject o Input symbols cannot be ZF consumed. comet EK i STRING ACCEPTANCE/REJECTION BY NFA i Second Choice Y STRING ACCEPTANCE/REJECTION BY NFA es YY pine Second Choice @+@© “accept” All input symbols are consumed. fs String Acceptance/Rejection by NFA Q Accept + Ifthere isa computation/path of the NFA with label w which leads to accepting state - ie. ‘The automaton starts from the initial state. and All the input symbols of string are processed/read and The automaton reaches to accepting state. OQ Reject + _ If there is no computation/path of the NFA with label w which leads to accepting state. aa is accepted by the NFA: “reject” Because this computation accepts 2a “This conpisstonia wale —‘String Rejection by NFA: First Choice =a ~falala alala a @---@) -o. é — gi iz oA 3) t alala OH+@©® “reject” Input cannot be @ 2 = consumed. © € Automaton halts 5 (3) Za) Y J string Rejection by NFA: Second Choice ~~ “ | O “lala alala (@)--@) _— ye oy Automaton halts Ne il Input cannot be consumed. Y ie YY \ Z A-Transition Olt could potentially occur at any stage — and allows the automaton to change state with no input. OsString aa is accepted.- tring pt —-@ a a)-4 (4) a @) a\a : -~ ain ; --@--@* @-@) a\a aa a (a, (g,\_A 4 —Go)* (ny -@ a ee d-Transition-Example adlaja @---@-4.@-2-G) Go) a (q)-A “© (read head on tape doesn’t move) String el is rejected ‘4 i % Example-3 it Oph strings accepted/rejected by the NFA EXTENDED TRANSITION FUNCTION a .@ <> > 22 &(qo.4)= (44) 5" qo,4a) = {94,95} 8" do,ab)= {42.45.40} J] Language of NFA ae TJ LUM) ={e, 10, 1010, 101010, ...} L={ab, abab, ababab, ...} =(10}* = {ab}* 0 —~> 01 accept ae 2 hia state Trap state) Designing NFA wibbw,, wy, W2 €{a, b}* b NFA w abbaw,, w}, W2 E{a, b}* b a \ ea ab NFA m2 (424 ()+(3) Designing NFA * An NFA that accepts string over {a, b} An NFA accepts all strings over {a, b} of even length with substring aa or bb * There are 2 distinct acceptance paths for the string abaaabb Designing NFA PNOAR ON > i. 12, 13. 14, 15. 16. 7. UM) = {abab" : n >=0 JU {aber UM) = {abab" :n >=0 JU faba": m UM) = {abab" sn >=0 } U {abaa 0 } with no more than five states. Find an NFA with three states for L= {as n > 1}U{b"at: m, k > O}. Find an NFA with four states for L= {a": n 2 O}U{b"a: m 2 1}. UM) = {lab} "sn >=0} U {labe)" : m >=0 }. UM) = {ws w € {ab, abe }* }. All strings such that the third symbol from the right end is a "0" over {0, 1}. All strings that contain the substring 0101 over {0, 1}. } } with no more than five states. . Construct an NFA for the language L = {0 k is multiple of 2 or 3}. The set of strings over alphabet {0, 1, 2 ... 9} such that the final digit has appeared before. The set of strings over alphabet {0, 1, 2... 9} such that the final digit has not appeared before. All strings containing exactly 4"0"s or an even number of "1"s. All strings that contain an even number of zeros or exactly two ones. Construct NFA to define identifiers in C programming Language (Hint: Ullman-Compiler). Construct NFA to identi nal operators (Hi Construct NFA to identify decimal numbers (Real, Integers, Scientific ) (Hint: Ullman-Compiler). Exercise UM) = {(ab) "0 >=0} U {(abe}": m >=0) Construct an NFA for the language L = {0 kis multiple of 2 or 3). @Q—6) b a Q—O FIND LANGUAGES ? b ab ae) sa M, is union of M, and M,. DFA vs. NFA a All transitions are deterministic. + Each transition leads to exactly one state. States can be changed after processing one symbol. Accepts input if the last state is the final state after processing the input string. Harder to construct. Practical implementation is feasible. 1. w Some transitions could be deterministic. non- + Atransition could lead to a set of states. States can be changed without processing the input symbol (A-transition) Accepts input if at least one final state is reachable after processing the input string. Easier to construct in comparison to DFA. Practical implementation should be deterministic (so it needs conversion to DFA). But DFAs and NFAs are equivalent (in their power) !! Equivalent Machines * Two finite accepters, M, and M, are equivalent if both accept the same language. L(M1) = L(M2) L(M;) = {10}* Removing Nondeterminism (Conversion from NFA to DFA) + e-Closure(q) = 8*(q, A) + In an NFA, the e-closure(q) of a state q is the set of all states which are reachable from q by a path whose edges are labeled by ¢/A. e-closure(qy) = {q0, q1, q2, 43} e-closure(q,) = {ql, q3} e-closure(q,) = {q2, 1, 43} 8.0) aT, e-closure(T) move(T, a) move(T, a) Removing Nondeterminism NFA N=(Q,%, 8, qo, F) e-closure(q) a DFA with Subset Construction NFA N => DFA M construction: + DFA Mhas a trap state ERR Given N = (Q, ©, 8, Go, F) Construct M = (Q’, 5, 8, q'o F’) Q’< 22, all the possible states of NFA, M could be in. qo = s-closure(qq) — Initial state of DFA M Define transition for all new states and alla € 5. 8°(T, a) = e-closure(move(T, a)) for alla © Tis the set of state(s). If there is no new state, stop. The final state of DFA is the one in which at least one state is NFA’s final state F= {qe Q|q'nF #2} NFA-to-DFA: No-A transition Subset Construction 1. The subset construction gives us 25 = 32 states; including ‘no! reachable states’. 2. Consider the ‘reachable states from 0? (subsets of q) and defines transitions for all new states. Use a transition table/transition diagram to convert an NFA to DFA a b o {1,2} {4} 1 {0} co 2 {8} co 3 {0} NFA-to-DFA: No-A transition Subset Construction an NFA to DFA >(0} {1,2} {4} 12) 3} {0.3} {1,2} {0,4} 40,4) (1,2) U4} 4 0 O a b {1,2} {4} a ow = 0 NFA-to-DFA: No-A transition Subset Construction NFA oO 1 Start —— DFA CONVERSION: NFA TO DFA NFA M ae) g ee Conversion: NFA to DFA.. DFA If DFA = io a | +({¢0}) {{a.42}) ~ |} ——{q.9) Se nin sl ( © )trap state Conversion: NFA to DFA..... Conversion: NFA to DFA rae) NFA a iC mon “© QeF DFA i “(o: ei la.a}eF Convert the following NFAs to DFAs Exercise-1 Exercise-2 Go {doa} > {a} % {Gorn} {a2} a + favab a 6 {ayaa} {a1 a2} a {a2} ¢ 4 % e ¢ % Exercise-3 ct {Gorn} I srings such thet te thd symbol from the right end ise "1" over 0, 1}. Convert NFA. into DFA. {a a2} ‘Construct NFA for ail strings that contain the substring 0101 over {Q, 1}. Convert NFA into DFA, Minimum DFA > Any DFA accepts a unique language (regular language), + Fora given language, there exist many DFA’s- Ditferent DFAs for the same language have different number of slates, + Considerable difference in the number of states of such equivelent DFAs. + Theorem: For every regular language L, a unique minimal DFA M exists such that L= LM, It is not true for NFAS, + _ Two minimal NFAs for the same language. L= {w,0"lw,: n >= 0, w, € {0, 1}, w, € {0, 1}*} In figure (a) + The DPA (a) consists of inaccessiblefunreachablefuseless oe states. (qs plays no role), +The inaccessible states can be removed along with : | ‘wansitions without any effect. + qyand g, are images ofeach other. + quand q, are images of each othr: Minimum DFA + Minimize a DFA, + "Minimal”?- Minimum Number Of States. * Find an equivalent DFA with the least possible number of states (minimum DFA). + “Unique”? + Unique up to the renaming of states, i.e, it has the same shape. (/somorphic). + Why Minimization? + To write a program (e.g., A compiler) or to design hardware using DFA, there will be a significant benefit in mi it before implementing it. Indistinguishable States: Key Idea + Let M be a DFA. + For all w £ Z*, two states, p, and g, are called indistinguishable (equivalent) if 5*(p, w) « F implies 5*(q, w) ¢ F Or 8*(p, w) € F implies 3*(q, w) ¢ F pa the “indistinguishable” relation is an “equivalent” relation. + LetMbea DFA, For states | and 2, w= a, w=b 5*(1,a)=2 €F and 5¢(2,0)~6€F S*(1,b)=7€F and 5°2,b)=3€F Ir means states I and 2 are inistinguishable forall strings with length one Forstates I and 2 and waa 8*(1,aa)= 6 F and 8°, 2 ‘means states Land 2 are not indistinguishable for waa s®. Check all pairs for w 22, (1,2) (3) (1, 4 (1, 5) (1) (057) (1,8) (1,9) (10) IGM roe 1,10) DISTINGUISHABLE STATES + Let M be a DFA. If there exists some string w € 3* such that 5*(p, w) €Fand 6*(q,w) EF Or — S*(p, w) € Fand 6%(q, w) EF + Then, the states p and q are distinguished by a string w. * The “distinguishable” relation is the “not equivalent” relation. For states 4 and 5 8*(4, 0) =5¢F and 6*5,a)=10eF lt means states 4 and 5 are distinguishable for w = a € 2. i.e., states 4 and 5 are distinguishable for strings of length one. Indistinguishable/Distinguishable Relation + Indistinguishable (“= js an equivalenc P (reflexive) (symmetric) r=>Pp (transitive) + The distinguishable relation is not an equivalence relation. + If p ond q are distinguishable and q and r are also distinguishable + Then p and r are not necessarily distinguishable. FTet hi be a BFA. (p, w) © F implies 5*(a, w) © F 57(p, w) EF implies 8*(a, w) € F * Let M be a DFA + Ifthere exists some string w e Z* such that 5*(p, w) €F and 6°(q, w) ¢F oR 5*(p, w) €F and 6*(q, w) eF + Then the states p and q are said to be distinguishable by a string w. Minimizing a DFA + To minimize a DFA, + Remove unreachable/inaccessible/useless states + States which are not reachable from the initial state(s). + oR + States which are also not connected with final states + Identify equivalence classes of indistinguishable states + Replace the equivalence class with a single state, + The problem is determining “Which DFA states are distinguishable and indistings The Minimization Algorithm Given a DFA M =(Q, 5, 5, qo, F); find the minimum DFA M’ 1, _ Remove inaccessible/unreachable/uscless states. 2. Initialize the partition; x ~ {F, QF} 3. Form=1, 2, so + Compute the equivalence class x, using + Forall sets Sex, + Forallg,,q@eS + Forallae® + 1f8(q,, a) and 8(q,, a) make a transition to the states of the same set of x, , +g, and q, are indistinguishable. + Otherwise, q, and q, are distinguishable. Then, split the set S + Repeat step 3 until, for some, T,, _ = Ty 4, Replace each equivalence class of states with a single state + The initial state is the set of states consisting of the initial state + The final state nal state isthe set of states consisting of at least one + This must eventually happen. + Why? DFA minimization: Example M=(Q, &, 5, dor F) = ( {1,2,3,4,5,6,7,8,9, 10}, {a,b}, 6 1, {10} ) Step I: Remove useless Step 2: Initialize the partition m, %) = {Q-F, F} m= {{1, 2, 3,4, 5, 6,7, 8,9}, {10}} DFA minimization-Example:Construct 1, partition Tp = (1, 2, 3, 4, 5, 6, 7, 8, 9}, (10}} ‘Apply the “actansitons” to each lass the next states are (2,6,8,5, 10, 10,2,5,4), {10}, + The a-ransitions indicate that Sand 6 are ina different class than 12,3, 4, 7,8, and 9 + The astansiions spit {1 2,3,4,5,6, 7, 8,9 } {10)) ito (1,2, 3,4, 78,9} {6} and {10) Le, (01.2,3.4,7,8.9), (5.6), (10) | + transitions ‘> Apply the “brnsitons” to each class, the next states are (7,3,9,3, 73,947, 10), {00 + The b-tranitions indicate that 9 in different cae than 1,2, 3,4, 5, 6,7, 0 8 {+The buansiions futher split {1,2,3,4, 7,8, 9}, 15,6), (10) } ino (0, 2,3, 47,8) 5,6), (9), to} ie The Th, psttion is Th ((1,2,5.4,,8), (5.6), 9) (10) ) 5,4 compute m, EXAMPLE: THE IT, PARTITION m= {{1,2,3,4, 7,8}, (5, 6}, {9}, {10} } + apply the a-transitions to the set (classes) in m, {2,6,8, 5, 2,5}, (10, 10}, {4}, {10} + the a-transitions split {1, 2, 3, 4, 7, 8} into (1, 3, 7} and (2, 4,8}. + apply the b-transitions to the set (classes) in m, {7,3,9.3,9, 7}. {7,3}, {10}, {10} + the betransitions split further into {1} , {2, 4, 8} and (3, 7}. 6S | @ la b 4, + my ={{1}, (3, 7}, (2, 4, 8}, {5, 6}, {9}, {103} + m= €(1,2,3,4, 7,8}, (5, 6}, + m,# 7m, . compute m, {9}, {10} } EXAMPLE-1: THE I, PARTITION in UAT}, 13, 7h, 42,4, 8h, (5, 6}, {9}, {10}} apply the a-transitions to these classes: {2}, {8,2}, (6,5, 5}, (10, 10}, {4}, {10}. apply the b-transitions to these classes: {7}, {9,9}, (3,3, The {7,3}, {10}, {10}. no further split + it produces no new classes. + itmeans x, =, . stop, DFA MINIMIZATION: EXAMPLE-1 my =tE1}, €2,4, 8), 3, 7), 5, 6}, (9}, (10}} + Replace each equivalence class of states with a single state + Merge states 2, 4, and 8 into one state. + Merge states 3 and 7 into one state. + Merge states 5 and 6 into one state, The initial state is the set of states consisting of the initial state, ‘The final state is the set of states consisting of at least one final state. DFA MINIMIZATION: EXAMPLE-1 My ={A1}, (2, 4, 8}, {3,7}, (5, 6}, {9}, {10}}- * initial state = {1} * final state = { {10} } + replace each of these classes with a single state. DFA Minimization: What about transitions? Are they lost? No Given DFA M M=(Q, 2, 5, ao, F) M=( {1,2,3,4,5,6,7,8,9,10}, {a,b}, 5, 1, {10} ) FIND THE MINIMUM DFA

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy