1 / 23

Theory of Computation

Theory of Computation. Theory of Computation Peer Instruction Lecture Slides by  Dr. Cynthia Lee, UCSD  are licensed under a  Creative Commons Attribution- NonCommercial - ShareAlike 3.0 Unported License . Based on a work at  www.peerinstruction4cs.org . Extra Credit Quiz.

noreen
Download Presentation

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. Theory of Computation Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.Based on a work at www.peerinstruction4cs.org.

  2. Extra Credit Quiz • If there is somebody in your group who seems really smart, it is a good idea to just let that person do all the talking like a “mini-teacher,” so that you can learn from them. • TRUE • FALSE

  3. They’re really good guessers! Nondeterministic Finite AutomataNFA What is deterministic?

  4. DFA or NFA? DFA NFA Both DFA and NFA

  5. DFA or NFA? DFA NFA Both DFA and NFA

  6. Tracing in an NFA “100” • What are the two sequences of states on the input “100”? • (q0,q0,q1,q2[accept]), (q0,q1,q2[accept]) Final: Accept • (q0,q0,q1,q2[accept]), (q0,q1,q2[reject]) Final: Accept • (q0,q0,q1,q2[accept]), (q0,q1,q2[reject]) Final: Reject • (q0,q0,q1,q2[reject]), (q0,q1,q2[reject]) Final: Reject

  7. DFAs vs. NFAs DFAs NFAs There may be 0, 1, or many transitions leaving a single state for the same input character Transition function defined on “epsilon” in addition to alphabet characters There may be several different ways to reach an accept state for a single string—the computation may not determined by the input (“nondeterministic”) • For each character in the alphabet, exactly one transition leaving every state • Computation is “deterministic,” i.e. determined by the input, i.e., the same every time for a given input

  8. Formal Definition of an NFA • A DFA M1 is defined as a 5-tuple as follows: • M1 = (Q, Σ, δ, q0, F), where: • Q is a finite set of states • Σ is a finite set of characters, the alphabet • δ: Q x Σ -> P(Q), the transition function • q0, a member of Q, the start state • F, a subset of Q, the accept state(s) NEED TO USE THIS FOR PROOFS---CANNOT MAKE GENERAL STATEMENTS BY DRAWING SPECIFIC EXAMPLES!

  9. Nondeterminism • Because NFAs are non-deterministic, the outcome (accept/reject) of the computation may be different from run to run (i.e., isn’t determined by the input) • TRUE • FALSE NEED TO USE THIS FOR PROOFS---CANNOT MAKE GENERAL STATEMENTS BY DRAWING SPECIFIC EXAMPLES!

  10. A different (easier!) way to prove what we just proved Reg. Langs. Closed Under Union(Why NFAs are So Useful in proofs)

  11. Final form for your homework/test: Thm. The class of regular languages is closed under the union operation. • Proof: • Given: Two regular languages L1, L2. • Want to show: L1 U L2 is regular. • Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct a DFA M = (Q,Σ,δ,q0,F), s.t.: • Q = Q1x Q2 • δ((x,y),c) = (δ1(x,c),δ2 (y,c)), for c in Σ and (x,y) in Q • q0 = (q01, q02) • F = {(x,y) in Q | x in F1or y in F2} • M recognizes L1 U L2. • Correctness: ___________________________________ • A DFA recognizes L1 U L2, so L1 U L2 is regular, and the class of regular languages is closed under union. Q.E.D. Could you come up with this, and write it correctly, in a short amount of time on an exam??

  12. Final form for your homework/test: Thm. The class of regular languages is closed under the union operation. • Proof: • Given: Two regular languages L1, L2. • Want to show: L1 U L2 is regular. • Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct an NFAM = (Q,Σ,δ,q0,F), s.t.: • Q = • δ(x,c) = • q0 = • F = • M recognizes L1 U L2. • Correctness: ___________________________________ • An NFA recognizes L1 U L2, so L1 U L2 is regular, and the class of regular languages is closed under union. Q.E.D. Could you come up with this, and write it correctly, in a short amount of time on an exam??

  13. Back to our working example

  14. Another construction proof Equivalence of Finite AutomataNFA & DFA

  15. Tracing in NFA (Fig. 1.27 in your book) Run this NFA on input 010110 Fill in the missing row of states: • q2, q3, q4, q4, q4 • q1, q2, q4, q4, q4 • q1, q2, q3, q4, q4 • None of the above • I don’t understand this at all

  16. Tracing in NFA (Fig. 1.27 in your book) Run this NFA on input 010110 • Each row is a set of states that we are in at the “same time” • {q1} • {q1,q2,q3} • {q1,q3} • {q1,q2,q3,q4} • {q1,q3,q4} • Recall that when we did the union closure proof with DFAs, we were always in a pair of states at the “same time”—same concept • What are all the possible unique sets of states? (a) QxQ (b) |Q|2 (c) P(Q) (d) |Q|! (e) I don’t understand this at all

  17. Thm. 1.39: Every NFA has an equivalent DFA. Talk about sigma • Given: NFA M = (Q,Σ,δ,q0,F) • Want: DFA M’ = (Q’,Σ,δ’,q0’,F’) s.t. L(M) = L(M’). • Construction: //need to make a DFA that simulates nondeterminism within the constraints of determinism (!!) • Q’ = • Σ • δ’ • q0’ = • F’ = • A DFA recognizes L(M), then every NFA has an equivalent DFA. Q.E.D. P(Q) d’(R,a) = {q | q in d(r,a) for some r in R OR q can be reached by following 1+ epsilon edges from some r in R} q’0 = {q0} U {q in Q | q can be reached by following 1+ epsilon edges from q0} { R in Q’ | R contains at least one accept state of M}

  18. Thm. 1.39: Every NFA has an equivalent DFA. • We also know every DFA isan NFA. • Corollary of these two facts: • The class of languages recognized by DFAs and the class of languages recognized by NFAs are the same class • The Class of Regular Languages • It may be surprising that adding something as powerful and magic-seeming as instantaneous, 100% accurate guessing to the DFA model could turn out to not increase the power of the model! • This course is full of surprises!

  19. Extremely useful Regular ExpressionsPattern Matching

  20. From the Reading Quiz • Let L be the language of this regular expression: 1*0 • Which of the following is NOT in L? • 10 • 100 • 110 • They’re all in L

  21. Regular Expressions and UNIX/Linux Shell Wildcard • 1*0 = “Any number of 1’s (including no 1’s), followed by a single 0” • “100” not accepted by that RE • This may be confusing to those who are used to *’s usage in, say, UNIX/Linux shell—VERY DIFFERENT • In UNIX/Linux * means “replace with anything here” • 1*0 matches “100” and “1blahblahblah0” • Typical shell usage: “ls *.jpg” (to list all JPEG files) • This is very useful to know! • Just don’t confuse it with REs in this course

  22. Regular Expressions • Let L be the language of this regular expression: ((a U Ø)+b*)* • Which of the following is NOT true of L? • Some strings in L have equal numbers of a’s and b’s • All strings in L have more b’s than a’s • L contains “aaaaaa” • a‘s never follow b’s in any string in L • None or more than one of the above

  23. Regular Expressions • Let L be the language of this regular expression: aØb* • Which of the following is NOT true of L? • L is the empty set • L contains “a” • aaab is not in L • None or more than one of the above

More Related