1 / 17

Introduction to CS Theory

Introduction to CS Theory. Lecture 5 – Nondeterministic Finite Automata Piotr Faliszewski pf@cs.rit.edu. Finite automata Formal definition of a formal automata δ * function, acceptance by a finite automaton Closure properties Union Intersection Completement

Download Presentation

Introduction to CS Theory

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. Introduction to CS Theory Lecture 5 – Nondeterministic Finite Automata Piotr Faliszewski pf@cs.rit.edu

  2. Finite automata Formal definition of a formal automata δ* function, acceptance by a finite automaton Closure properties Union Intersection Completement the “cartesian product” construction A nonregular language Quiz Statistics Min: 3 / 20 Med: 14 / 20 Max: 26 / 20 Not bad, but lightly graded! Next quiz: Wednesday! Regular languages Drawing diagrams for finite automatons accepting particular languages Reading and writing regular expressions Etc. Previous Class

  3. Finite automata diagrams are somewhat constrained A transition for each state and each alphabet symbol For each state q and symbol a at most one transition from q labeled a Consequence In each transition we have to make sure we make the right move This can be challenging… Example L = (11+110)*0 Can we somehow defer our decisions? Yet Another Regular Language

  4. Nondeterministic finite automata (NFA) We allow states to not have transitions for all alphabet symbols We allow states to have multiple transitions labeled with the same symbol Examples L’ = (11 + 110)*0 L’’ is a language of strings that contain aaba as a substring What does it mean for an NFA to accept a string? An NFA accepts a string x if starting from the initial state we can choose the transitions for consecutive symbols of x so that we end up in an accepting state. Nondeterministic Finite Automata

  5. Def. NFA M is a quintuple M = (Q, Σ, q0, A, δ) where: Q – set of states Σ – input alphabet q0 – initial state (q0 Q) A – set of accepting states (A  Q) δ – transition function δ: Q  Σ 2Q δ(q,a) = set of states that M can go to from state q upon seeing symbol a δ*(q,x) = set of states that M can reach if it starts from state q and sees string x Define δ*(q,x) formally. NFA – Formal Definition Def.We say that an NFA M = (Q, Σ, q0, A, δ) accepts a string x  Σ* iff δ*(q0, x) A ≠ . L(M) = set of strings accepted by M

  6. Using δ* • Example • Compute δ*(q0,x) for: • x = ε • x = 0 • x = 00 • x = 001 • x = 0011 0 0,1 0,1 1 q1 q2 q0

  7. NFAs are no less powerful than FAs Let M1= (Q1, Σ1, q1, A1, δ1) be an FA There is an NFA M2= (Q2, Σ2, q2, A2, δ2) such that L(M1) = L(M2) Exercise Given an FA M1 above, provide the appropriate NFA M2 This is almost immediate! Are there algorithms for languages of NFA? Can we simulate an NFA on an FA? Can we simulate an NFA in polynomial time? Are NFAs More Powerful than FAs?

  8. NFAs vs FAs • What is the difference between NFAs and FAs? • An NFA can “be in several states” at the same time after reading some string x • An FA is always in one state • However… • Each NFA only has a finite number of states • Thus, an FA can keep track of those subsets!

  9. Formal Proof (The Subset Construction) Let M1= (Q1, Σ1, q1, A1, δ1) be an NFA We build an FAM2= (Q2, Σ2, q2, A2, δ2) such that • Q2 = 2Q1 • Σ2 = Σ1 • q2 = {q1} • A2 = {q  Q1 | q  A1 ≠  } • For each q  Q1 and each a Σ1, δ2(q,a) = Up  q δ1(p,a) Now… we need to prove L(M1) = L(M2) • We will use structural induction • But what statement to prove exactly? • We can try to show that for each string x we have thatx  L1 if and only if x  L2 – but we would get stuck! • We show: For each string x, it holds thatδ1*(q1,x) = δ2*(q2,x)This implies what we need a b a q1 q3 b a a q2

  10. NFAs • Are NFAs missing something? • Consider • L’ = 01* • L’’ = 0*1 • We can get NFAs for L’ and L’’ • Can we get an NFA for L’L’’ = 01*0*1? • An NFA for L’  L’’

  11. NFA We allow multiple transitions with the same label We allow missing transitions… NFA-ε We additionally allow transitions labeled with ε We can follow an ε-transition at any time, without consuming another symbol of input Consider the NFA-ε below. Does it accept aba abab aaabbb Exercise: Give NFA-ε’s for the following languages a*b*c* 0*(01)*0* Can we get NFAs for them as well? NFA’s With ε-Transitions a b a a,b ε a ε b

  12. Def. NFA-ε M is a quintuble M = (Q, Σ, q0, A, δ) where: Q – set of states Σ – input alphabet q0 – initial state (q0 Q) A – set of accepting states (A  Q) δ – transition function δ: Q  (Σ  {ε})  2Q We want: δ*(q,x) = set of states that M can reach if it starts from state q and sees string x But we need to handle ε-transitions first. S – set of states ε(S) – the ε closure of S (i.e., all states reachable from S via ε-transitions). Define ε(S) properly. Now define δ*(q,x) properly. NFA-ε – Formal Definition Def.We say that a finite automaton M = (Q, Σ, q0, A, δ) accepts a string x  Σ* iff δ*(q0, x) A. L(M) = set of strings accepted by M

  13. NFA-ε’s are no weaker than NFAs Almost immediate! NFA “is” an NFA-ε with no ε-transitions Can we use NFA-ε’s instead of NFAs for free? How can we simulate the ε-transitions. NFAs versus NFA-ε’s Yes! Show how! Conclusion: NFAs, NFA-ε, and FAs are all equvialent!

  14. Example: Conversions • Conversion to an NFA • Start state? • Transitions? • Convert • To NFA • Then to FA C 0 0 0 1 ε ε B A D

  15. Kleene’s Theorem • Theorem • A language L is regular if and only if there is finite automaton M such that L = L(M) • Proof • Two parts • For each regular expression r there is an FA M such that L(M) = L(r) (L(r) – the set of strings described by the regular expression) • For each FA M, L(M) is regular • Proof: Mostly on the board

  16. Kleene’s Theorem: Part 1 • Theorem • For each regular expression r there is an FA M such that L(M) = L(r) (L(r) – the set of strings described by the regular expression) • Proof • Given: Regular expression r, r is either • ε, , aΣ, or • r1r2 • r1+r2 • (r1)* • where r1 and r2 are two (smaller) regular expressions (structural induction) • In each case we can convert! • Example • Convert r = (00+1)*(10)*

  17. Kleene’s Theorem: Part 2 • Theorem • For each FA M, L(M) is regular • Proof • Wow, this is nontrivial! Need some insight! • We will focus on the construction • Correctness: Implicit and natural. M = (Q, Σ, q0, δ, A) be an FA L(p,q) = {x | δ*(p,x) = q } L(p,q,k) = {x | δ*(p,x) = q without ever going through state with a number > k} L(p,q,||Q||) = L(p,q) How to use these definitions in an inductive proof? (Board!)

More Related