CSE 311: Foundations of Computing highlights Fall 2013 • FSMs with output at states Lecture 24: NFAs, regular expressions, and NFA → DFA • State minimization 0 2 0 S0 S1 [1] [0] 1 2 3 2 0 3 S0 0 S1 0 1 1 [1] [0] 1 0 2 S2 S3 3 0 1 1,3 [1] [0] 3 1,2 2 0 2 3 3 S2 S3 1 [1] 1 [0] 2 2 2 3 3 S4 S5 0 0 [1] [0] 1 3 highlights nondeterministic finite automaton (NFA) • Graph with start state, final states, edges labeled Lemma: The language recognized by a DFA is the set of by symbols (like DFA) but strings x that label some path from its start state to one – Not required to have exactly 1 edge out of each state of its final states labeled by each symbol--- can have 0 or >1 – Also can have edges labeled by empty string λ λ λ λ 0 0 • Definition: Definition: x is in the language recognized by an Definition: Definition: 1 1 1 NFA if and only if x labels a path from the start s 3 s 0 s 1 s 2 state to some final state 0 0,1 1 1 1 s 3 s 0 s 1 s 2 0,1 0,1
three ways of thinking about NFAs NFAs and regular expressions Theorem: For any set of strings (language) � Theorem: Theorem: Theorem: • Outside observer: Is there a path labeled by x from the start state to some final state? described by a regular expression, there is an NFA that recognizes � . • Perfect guesser: The NFA has input x and whenever there is a choice of what to do it magically guesses a Proof idea: Structural induction based on the good one (if one exists) recursive definition of regular expressions... • Parallel exploration: The NFA computation runs all possible computations on x step-by-step at the same Note: One can also find a regular expression to describe the time in parallel language recognized by any NFA but we won’t prove that fact regular expressions over Σ basis • Basis: • Case ∅ ∅ : ∅ ∅ ∅ , λ λ are regular expressions – ∅ ∅ ∅ λ λ – a a a a is a regular expression for any a ∈ Σ • Recursive step: • Case λ λ : λ λ – If A A and B B are regular expressions then so are: A A B B ( A ∪ B ) • Case a a a : a ( AB ) A*
basis inductive hypothesis • Case ∅ ∅ : • Suppose that for some regular expressions ∅ ∅ � and � there exist NFAs � � and � � such that � � recognizes the language given by � and � � recognizes the language given by � • Case λ λ : λ λ • Case a a : a a a � � � � inductive step inductive step Case ( A ∪ B ): Case ( A ∪ B ): λ λ λ λ � � � � λ λ λ λ � � � �
inductive step inductive step Case ( AB ): Case ( AB ): λ λ λ λ λ λ λ λ � � � � � � � � inductive step inductive step Case A* Case A* λ λ λ λ λ λ λ λ � � N A λ λ λ λ
build an NFA for (01 ∪ 1)*0 solution (01 ∪ ∪ ∪ ∪ 1)*0 0 λ λ λ λ 1 λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ 0 λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ 1 NFAs and DFAs NFAs and DFAs Every DFA is is is an NFA is Every DFA is is an NFA is is – DFAs have requirements that NFAs don’t have – DFAs have requirements that NFAs don’t have Can NFAs recognize more languages? Can NFAs recognize more languages? No! Theorem: Theorem: Theorem: Theorem: For every NFA there is a DFA that recognizes exactly the same language
conversion of NFAs to a DFAs conversion of NFAs to a DFAs • Proof Idea: New start state for DFA – The DFA keeps track of ALL the states that the – The set of all states reachable from the start part of the input string read so far can reach in state of the NFA using only edges labeled λ λ λ λ the NFA – There will be one state in the DFA for each f λ λ λ λ subset of states of the NFA that can be reached λ λ λ λ a,b,e,f a b by some string λ λ λ λ e DFA NFA conversion of NFAs to a DFAs conversion of NFAs to a DFAs For each state of the DFA corresponding to a set S of Final states for the DFA states of the NFA and each symbol s s s s – All states whose set contain some final state of – Add an edge labeled s s s s to state corresponding to T, the the NFA set of states of the NFA reached by starting from some state in S, then following one edge labeled by s , and then following some number of edges labeled by λ – T will be ∅ ∅ if no edges from S labeled s s s s exist ∅ ∅ c e a,b,c,e a 1 b f d λ λ λ λ λ λ λ λ 1 g DFA 1 b b,e,f c,d,e,g NFA c λ λ λ λ 1 e 1
example: NFA to DFA example: NFA to DFA a,b a a λ λ λ λ λ λ λ λ 1 1 0 0 b b c c 0 0 0,1 0,1 NFA NFA DFA DFA example: NFA to DFA example: NFA to DFA 0 0 a,b a,b a a 1 1 λ λ λ λ λ λ λ λ 1 1 1 b c c 0 0 b b c c 0 0 0 0,1 0,1 b,c NFA NFA DFA DFA
example: NFA to DFA example: NFA to DFA 0,1 0 0 ∅ ∅ ∅ ∅ ∅ ∅ ∅ ∅ a,b a,b a a 1 1 0 0 1 1 λ λ λ λ λ λ λ λ 1 1 1 1 b b c c 0 0 b b c c 0 0 0 0 0,1 0,1 b,c b,c NFA NFA DFA DFA example: NFA to DFA example: NFA to DFA 0,1 0,1 0 0 ∅ ∅ ∅ ∅ ∅ ∅ ∅ ∅ a,b a,b a a 1 1 0 0 1 1 λ λ λ λ λ λ λ λ 1 1 1 1 b b c c 0 0 1 1 b b c c 0 0 0 0 0 0,1 0,1 1 b,c a,b,c b,c a,b,c 0 0 NFA NFA DFA DFA
exponential blow-up in simulating nondeterminism • In general the DFA might need a state for every subset of states of the NFA – Power set of the set of states of the NFA – n-state NFA yields DFA with at most 2 n states – We saw an example where roughly 2 n is necessary Is the n th char from the end a 1? • The famous “P=NP?” question asks whether a similar blow-up is always necessary to get rid of nondeterminism for polynomial-time algorithms
Recommend
More recommend