1 / 18

Intro to Theory of Computation

Intro to Theory of Computation. L ECTURE 4 Theory of Computation Equivalence of NFAs, DFAs and regular expressions. CS 464. Sofya Raskhodnikova. The class of regular languages is closed under. Regular operations. Union: A  B = { w | w  A or w  B }.

Download Presentation

Intro to Theory of Computation

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. Intro to Theory of Computation • LECTURE 4 • Theory of Computation • Equivalence of NFAs, DFAs and regular expressions CS 464 Sofya Raskhodnikova SofyaRaskhodnikova; based on slides by Nick Hopper

  2. The class of regular languages is closed under Regular operations Union: A  B = { w | w  A or w  B } Union: A  B = { w | w  A or w  B } Concatenation: A  B = { vw | v  A and w  B } Star: A* = { w1 …wk | k ≥ 0 and each wi A } Other operations Complement: A = { w | w  A } Intersection: A  B = { w | w  A and w  B } Reverse: AR = { w1 …wk | wk …w1 A } Sofya Raskhodnikova; based on slides by Nick Hopper

  3. Nondeterminism Deterministic Computation Nondeterministic Computation reject accept accept or reject SofyaRaskhodnikova; based on slides by Nick Hopper Ways to think about nondeterminism parallel computation tree of possible computations guessing and verifying the “right” choice

  4. Equivalence of NFAs & DFAs Theorem.Every NFA has an equivalent DFA. Corollary: A language is regular iff it is recognized by an NFA. Sofya Raskhodnikova; based on slides by Nick Hopper

  5. From NFA to DFA Input: N = (Q, Σ, , q0, F) Output: M = (Q, Σ, , q0, F) Intuition: Do the computation in parallel, maintaining the set of states where all threads are reject Idea: Q = P(Q) accept Sofya Raskhodnikova; based on slides by Nick Hopper

  6. From NFA to DFA Input: N = (Q, Σ, , q0, F) Output: M = (Q, Σ, , q0, F) For RQ, let E(R) be the set of states reachable by ε-transitions from the states in R. Q = P(Q)  : Q Σ→ Q (R,) =  E( (r,) ) for all RQ and Σ. rR q0 = E({q0}) F = { R  Q | f  R for some f  F } Sofya Raskhodnikova; based on slides by Nick Hopper

  7. Examples: NFA to DFA 1 a b 0,1 ε 0 3 1 2 1 Sofya Raskhodnikova; based on slides by Nick Hopper 1) 2)

  8. Regular expressions • In a regular expression, we can use • Constants: ε ,  , a setΣ, members of Σ. • Regular operations:*,  , • Examples: • 0*1* • (01)* • 0*1*(ε 0) • L(R) = the language regular expression R describes = { w | w has a run of 0s followed by a run of 1s} • = the set of all strings over the alphabet Σ={0,1} Sofya Raskhodnikova; based on slides by Nick Hopper

  9. Precedence *  EXAMPLE ( ( R1* ) R2 )  R3 R1*R2 R3 = Sofya Raskhodnikova; based on slides by Nick Hopper

  10. Regular expressions: examples 1) 2) 3) { w | w has exactly one character 1 } 0*10* { w | w has length ≥ 3 and its 3rd symbol is 0 } (01)(01) 0 (01)* { w | every odd position of w is a 1 } (1(01))* (ε 1) Sofya Raskhodnikova; based on slides by Nick Hopper

  11. Regular expressions to NFAs Theorem.Every regular expression has an equivalent NFA. Proof: Induction on the length of regular expression R. Base case: length 1 Induction hypothesis: follows from closure of the class of regular languages under the regular operations. R = ε R =  R =  Sofya Raskhodnikova; based on slides by Nick Hopper

  12. Regular expression to NFA Transform (1(0  1))* to an NFA ε 1 1,0 ε Sofya Raskhodnikova; based on slides by Nick Hopper

  13. 01*0 0 0 1 NFAs to regular expressions Theorem.Every NFA has an equivalent regular expression. Proof idea: Transform NFA to a regular expression by removing states and relabeling the arrows with regular expressions. Sofya Raskhodnikova; based on slides by Nick Hopper

  14. Generalized NFAs Sofya Raskhodnikova; based on slides by Nick Hopper Each transition is labeled with a regular expression Unique and distinct start and accept states No transitions to the start state No transitions from the accept state

  15. Generalized NFAs a[b a*b a qs q2 qa G accepts w if it finds q0q1…qk, w1…wk: wi2 R(qi,qi+1) w = w1w2…wk q0=qs, qk=qa R(qs,q2) = a*b R(qa,q) = Ø R(q,qs) = Ø

  16. NFA to GNFA ε ε ε NFA ε ε Add unique and distinct start and accept states Sofya Raskhodnikova; based on slides by Nick Hopper

  17. GNF to regular expression ε ε ε NFA ε While machine has more than 2 states: Pick an internal state, rip it out and relabelthe arrows with regular expressions to account for the missing state Sofya Raskhodnikova; based on slides by Nick Hopper

  18. a a,b (a*b)(ab)* ε b ε a*b q1 q2 q3 q0 R(q0,q3) = (a*b)(ab)*

More Related