06-finiteAutomata2

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

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

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

View Full Document

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

View Full Document
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

## This note was uploaded on 01/13/2012 for the course CMSC 330 taught by Professor Staff during the Fall '08 term at Maryland.

### 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
Ask a homework question - tutors are online