1 / 32

CSE 311 Foundations of Computing I

CSE 311 Foundations of Computing I. Lecture 23 NFAs, Regular Expressions, and Equivalence with DFAs Autumn 2011. Announcements. Reading assignments 7 th Edition, Sections 13.3 and 13.4 6 th Edition, Section 12.3 and 12.4 5 th Edition, Section 11.3 and 11.4

barth
Download Presentation

CSE 311 Foundations of Computing I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 311 Foundations of Computing I Lecture 23 NFAs, Regular Expressions, and Equivalence with DFAs Autumn 2011 CSE 311

  2. Announcements • Reading assignments • 7thEdition, Sections 13.3 and 13.4 • 6th Edition, Section 12.3 and 12.4 • 5th Edition, Section 11.3 and 11.4 • New homework out later today won’t be due until Friday Dec 2. CSE 311

  3. 0 2 S0[1] S1 [0] 0 1 2 3 3 0 1 1 0 S2[1] S3 [0] 1 2 2 3 3 1 2 2 3 S4[1] S5 [0] 0 0 1 3 Last lecture highlights Finite State Machines with output at states State minimization 0 2 S0[1] S1 [0] 0 1 2 3 0 1,3 3 1,2 0 S2[1] S3 [0] 1 2 3 ⇒ CSE 311

  4. Last lecture highlights Lemma: The language recognized by a DFA is the set of strings x that label some path from its start state to one of its final states 0 0 1 1 1 s0 s1 s2 s3 0 0,1 CSE 311

  5. Nondeterministic Finite Automaton (NFA) • Graph with start state, final states, edges labeled by symbols (like DFA) but • Not required to have exactly 1 edge out of each state labeled by each symbol - can have 0 or >1 • Also can have edges labeled by empty string  • Definition: The language recognized by an NFA is the set of strings x that label some path from its start state to one of its final states 1 1 1 s0 s1 s2 s3 0,1 0,1 CSE 311

  6. Three ways of thinking about NFAs • Outside observer: Is there a path labeled by x from the start state to some final state? • Perfect guesser: The NFA has input x and whenever there is a choice of what to do it magically guesses a good one (if one exists) • Parallel exploration: The NFA computation runs all possible computations on x step-by-step at the same time in parallel CSE 311

  7. Design an NFA to recognize the set of binary strings that contain 111 or have an even # of 1’s CSE 311

  8. NFAs and Regular Expressions Theorem: For any set of strings (language) Adescribed by a regular expression, there is an NFA that recognizes A. Proof idea: Structural induction based on the recursive definition of regular expressions... Note: One can also find a regular expression to describe the language recognized by any NFA but we won’t prove that fact CSE 311

  9. Regular expressions over  • Basis: • ,  are regular expressions • a is a regular expression for any a • Recursive step: • If A and B are regular expressions then so are: • (A  B) • (AB) • A*

  10. Basis • Case : • Case : • Case a: CSE 311

  11. Basis • Case : • Case : • Case a: a CSE 311

  12. Inductive Hypothesis • Suppose that for some regular expressionsA and B there exist NFAs NA and NB such that NA recognizes the language given by A and NB recognizes the language given by B NA NB CSE 311

  13. Inductive Step • Case (A  B): NA NB CSE 311

  14. Inductive Step • Case (A  B): λ NA λ NB CSE 311

  15. Inductive Step • Case(AB): NB NA CSE 311

  16. Inductive Step • Case(AB): λ λ NB NA CSE 311

  17. Inductive Step • Case A* NA CSE 311

  18. Inductive Step • Case A* λ λ NA λ CSE 311

  19. NFAs and DFAs Every DFA is an NFA • DFAs have requirements that NFAs don’t have Can NFAs recognize more languages? No! Theorem: For every NFA there is a DFA that recognizes exactly the same language CSE 311

  20. Conversion of NFAs to a DFAs • Proof Idea: • The DFA keeps track of ALL the states that the part of the input string read so far can reach in the NFA • There will be one state in the DFA for each subset of states of the NFA that can be reached by some string CSE 311

  21. Conversion of NFAs to a DFAs • New start state for DFA • The set of all states reachable from the start state of the NFA using only edges labeled  f   a,b,e,f a b  e DFA NFA CSE 311

  22. Conversion of NFAs to a DFAs • For each state of the DFA corresponding to a set S of states of the NFA and each symbol s • Add an edge labeled s to state corresponding to T, the 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 exist f d 1   g 1 b c 1  b,e,f c,d,e,g e 1 1 CSE 311

  23. Conversion of NFAs to a DFAs • Final states for the DFA • All states whose set contain some final state of the NFA c e a,b,c,e a b DFA NFA CSE 311

  24. Example: NFA to DFA a  1 0 b c 0 0,1 NFA DFA CSE 311

  25. Example: NFA to DFA a,b a  1 0 b c 0 0,1 NFA DFA CSE 311

  26. Example: NFA to DFA 0 a,b a 1  1 c 0 b c 0 0,1 NFA DFA CSE 311

  27. Example: NFA to DFA 0 a,b a 1  1 1 b c 0 b c 0 0 0,1 b,c NFA DFA CSE 311

  28. Example: NFA to DFA 0  a,b a 1 0 1  1 1 b c 0 b c 0 0 0,1 b,c NFA DFA CSE 311

  29. Example: NFA to DFA 0,1 0  a,b a 1 0 1  1 1 b c 0 b c 0 0 0,1 b,c NFA DFA CSE 311

  30. Example: NFA to DFA 0,1 0  a,b a 1 0 1  1 1 b c 0 1 b c 0 0 0,1 b,c a,b,c 0 NFA DFA CSE 311

  31. Example: NFA to DFA 0,1 0  a,b a 1 0 1  1 1 b c 0 1 b c 0 0 0 0,1 1 b,c a,b,c 0 NFA DFA CSE 311

  32. 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 2n states • We saw an example where roughly 2n is necessary • Is the 10th 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 CSE 311

More Related