DOC PREVIEW
Duke CPS 102 - Lecture

This preview shows page 1-2-16-17-18-33-34 out of 34 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Deterministic Finite AutomataCOMPSCI 102 Lecture 2Let me show you a machine so simple that you can understand it in less than two minutesSteven Rudich: www.cs.cmu.edu/~rudich rudich012345678900,1001110111 111111 The machine accepts a string if the process ends in a double circleSteven Rudich: www.cs.cmu.edu/~rudich rudich012345678900,100111 The machine accepts a string if the process ends in a double circleAnatomy of a Deterministic Finite Automatonstatesstatesq0q1q2q3start state (q0)accept states (F)Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789Anatomy of a Deterministic Finite Automaton00,100111q0q1q2q3The alphabet of a finite automaton is the set where the symbols come from:The language of a finite automaton is the set of strings that it accepts{0,1}Steven Rudich: www.cs.cmu.edu/~rudich rudich01234567890,1q0L(M) =All strings of 0s and 1sThe Language of Machine MSteven Rudich: www.cs.cmu.edu/~rudich rudich0123456789q0q10011L(M) ={ w | w has an even number of 1s}Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789An alphabet Σ is a finite set (e.g., Σ = {0,1})A string over Σ is a finite-length sequence of elements of ΣFor x a string, |x| isthe length of xThe unique string of length 0 will be denoted by ε and will be called the empty or null stringNotationA language over Σ is a set of strings over ΣSteven Rudich: www.cs.cmu.edu/~rudich rudich0123456789Q is the set of statesΣ is the alphabet : Q  Σ → Q is the transition functionq0  Q is the start stateF  Q is the set of accept statesA finite automaton is a 5-tuple M = (Q, Σ, , q0, F) L(M) = the language of machine M= set of all strings machine M acceptsSteven Rudich: www.cs.cmu.edu/~rudich rudich0123456789Q = {q0, q1, q2, q3}Σ = {0,1} : Q  Σ → Q transition function*q0  Q is start stateF = {q1, q2}  Q accept statesM = (Q, Σ, , q0, F) where0 1q0q0q1q1q2q2q2q3q2q3q0q2*q2 00,100111q0q1q3MSteven Rudich: www.cs.cmu.edu/~rudich rudich0123456789q q00101q0q0010010,1Build an automaton that accepts all and only those strings that contain 001Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789A language is regular if it is recognized by a deterministic finite automatonL = { w | w contains 001} is regularL = { w | w has an even number of 1s} is regularSteven Rudich: www.cs.cmu.edu/~rudich rudich0123456789Union TheoremGiven two languages, L1 and L2, define the union of L1 and L2 as L1  L2 = { w | w  L1 or w  L2 } Theorem: The union of two regular languages is also a regular languageSteven Rudich: www.cs.cmu.edu/~rudich rudich0123456789Theorem: The union of two regular languages is also a regular languageProof Sketch: Let M1 = (Q1, Σ, 1, q0, F1) be finite automaton for L1 and M2 = (Q2, Σ, 2, q0, F2) be finite automaton for L2We want to construct a finite automaton M = (Q, Σ, , q0, F) that recognizes L = L1  L2 12Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789Idea: Run both M1 and M2 at the same time!Q= pairs of states, one from M1 and one from M2= { (q1, q2) | q1  Q1 and q2  Q2 }= Q1  Q2Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789Theorem: The union of two regular languages is also a regular languageq0q10011p0p11100Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789q0,p0q1,p011q0,p1q1,p1110000Automaton for UnionSteven Rudich: www.cs.cmu.edu/~rudich rudich0123456789q0,p0q1,p011q0,p1q1,p1110000Automaton for IntersectionSteven Rudich: www.cs.cmu.edu/~rudich rudich0123456789Theorem: The union of two regular languages is also a regular languageCorollary: Any finite language is regularSteven Rudich: www.cs.cmu.edu/~rudich rudich0123456789The Regular OperationsUnion: A  B = { w | w  A or w  B } Intersection: A  B = { w | w  A and w  B } Negation: A = { w | w  A } Reverse: AR = { w1 …wk | wk …w1  A }Concatenation: A  B = { vw | v  A and w  B }Star: A* = { w1 …wk | k ≥ 0 and each wi  A }Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789Regular Languages Are Closed Under The Regular OperationsWe have seen part of the proof for Union. The proof for intersection is very similar. The proof for negation is easy.Input: Text T of length t, string S of length nThe “Grep” ProblemProblem: Does string S appear inside text T?a1, a2, a3, a4, a5, …, atNaïve method: Cost: Roughly nt comparisonsAutomata SolutionBuild a machine M that accepts any string with S as a consecutive substringFeed the text to MCost:As luck would have it, the Knuth, Morris, Pratt algorithm builds M quicklyt comparisons + time to build MGrepCoke MachinesThermostats (fridge)ElevatorsTrain Track SwitchesLexical Analyzers for ParsersReal-life Uses of DFAsAre all languages regular?i.e., a bunch of a’s followed by an equal number of b’sConsider the language L = { anbn | n > 0 }No finite automaton accepts this languageCan you prove this?anbn is not regular. No machine has enough states to keep track of the number of a’s it might encounterThat is a fairly weak argument Consider the following example…L = strings where the # of occurrences of the pattern ab is equal to the number of occurrences of the pattern baCan’t be regular. No machine has enough states to keep track of the number of occurrences of abM accepts only the strings with an equal number of ab’s and ba’s!bbabaaababLet me show you a professional strength proof that anbn is not regular…Pigeonhole principle:Given n boxes and m > n objects, at least one box must contain more than one objectLetterbox principle:If the average number of letters per box is x, then some box will have at least x letters (similarly, some box has at most x)Theorem: L= {anbn | n > 0 } is not regularProof (by contradiction):Assume that L is regularThen there exists a machine M with k states that accepts LFor each 0  i  k, let Si be the state M is in after reading aii,j  k such that Si = Sj, but i  jM will do the same thing on aibi and ajbi But a valid M must reject ajbi and accept aibiDeterministic Finite Automata• Definition• Testing if they accept a string• Building automataRegular Languages• Definition• Closed Under Union, Intersection, Negation• Using Pigeonhole Principle to show


View Full Document

Duke CPS 102 - Lecture

Documents in this Course
Lecture

Lecture

42 pages

Lecture

Lecture

46 pages

Lecture

Lecture

77 pages

Notes

Notes

17 pages

Notes

Notes

52 pages

Lecture 9

Lecture 9

72 pages

Lecture

Lecture

7 pages

Lecture

Lecture

11 pages

Lecture

Lecture

28 pages

Lecture

Lecture

25 pages

Forbes

Forbes

9 pages

Lecture

Lecture

53 pages

Lecture

Lecture

21 pages

Lecture 4

Lecture 4

54 pages

Lecture

Lecture

24 pages

Lecture

Lecture

46 pages

Lecture

Lecture

16 pages

Lecture

Lecture

7 pages

Lecture

Lecture

46 pages

Graphs II

Graphs II

34 pages

Lecture

Lecture

81 pages

Lecture

Lecture

46 pages

Load more
Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?