06-finiteAutomata2

06-finiteAutomata2 - CMSC 330: Organization of Programming...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CMSC 330: Organization of Programming Languages Finite Automata 2 2 Last Lecture Finite automata Alphabet, states ( , Q, q , F, ) Types Deterministic (DFA) Non-deterministic (NFA) Reducing RE to NFA Concatenation Union Closure a b a a b a a b a 3 This Lecture Reducing NFA to DFA -closure Subset algorithm Minimizing DFA Hopcroft reduction Complementing DFA Implementing DFA 4 How NFA Works When NFA processes a string NFA may be in several possible states h Multiple transitions with same label h -transitions Example After processing a h NFA may be in states S1 S2 S3 a S1 S2 a S3 5 Reducing NFA to DFA NFA may be reduced to DFA By explicitly tracking the set of NFA states Intuition Build DFA where h Each DFA state represents a set of NFA states Example S1 a S1, S2, S3 a S1 S2 a NFA DFA S3 a 6 Reducing NFA to DFA (cont.) Reduction applied using the subset algorithm DFA state is a subset of set of all NFA states Algorithm Input h NFA ( , Q, q , F n , ) Output h DFA ( , R, r , F d , ) Using h -closure(p) h move(p, a) 7 -transitions and -closure We say p q If it is possible to go from state p to state q by taking only -transitions If p, p 1 , p 2 , p n , q Q such that h {p, ,p 1 } , {p 1 , ,p 2 } , , {p n , ,q} -closure(p) Set of states reachable from p using -transitions alone h Set of states q such that p q h -closure(p) = {q | p q } Note h -closure(p) always includes p h -closure( ) may be applied to set of states (take union) 8 -closure: Example 1 Following NFA contains S1 S2 S2 S3 S1 S3 -closures -closure(S1) = -closure(S2) = -closure(S3) = -closure( { S1, S2 } ) = S1 S2 S3 { S1, S2, S3 } { S2, S3 } { S3 } a { S1, S2, S3 } { S2, S3 } 9 -closure: Example 2 Following NFA contains S1 S3 S3 S2 S1 S2 -closures -closure(S1) = -closure(S2) = -closure(S3) = -closure( { S2,S3 } ) = b S1 S2 S3 a { S1, S2, S3 } { S2 } { S2, S3 } { S2 } { S2, S3 } 10 -closure: Practice Find -closures for following NFA Find -closures for the NFA you construct for The regular expression (0|1*)111(0*|1) 11 Calculating move(p,a) move(p,a) Set of states reachable from p using exactly one transition on a h Set of states q such that {p, a, q} h move(p,a) = {q | {p, a, q} } Note move(p,a) may be empty h If no transition from p with label a 12 move(a,p) : Example 1 Following NFA = { a, b } Move move(S1, a) = move(S1, b) = move(S2, a) = move(S2, b) = move(S3, a) = move(S3, b) = b S1 S2 S3 a { S2, S3 } { S3 } a 13 move(a,p) : Example 2 Following NFA = { a, b } Move move(S1, a) = move(S1, b) = move(S2, a) = move(S2, b) =...
View Full Document

Page1 / 7

06-finiteAutomata2 - CMSC 330: Organization of Programming...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online