Finite AutomataSlide 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 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41How to prove a language is not regular…Slide 43Slide 44Slide 45Slide 46Slide 47Slide 48Slide 49Slide 50Slide 51Slide 52Slide 53Slide 54Study BeeFinite AutomataGreat Theoretical Ideas In Computer ScienceVictor AdamchikDanny SleatorCS 15-251 Spring 2010Lecture 20 Mar 30, 2010 Carnegie Mellon UniversityA machine so simple that you can understand it in less than one minuteWishful thinking…Deterministic Finite Automata00,1001110111 111111 The machine accepts a string if the process ends in a double circle00,1001110111 111111 The machine accepts a string if the process ends in a double circlestatesstart state (q0)accept states (F)transitionsAnatomy of a Deterministic Finite AutomatonThe alphabet of a finite automaton is the set where the symbols come from, for example {0,1}The language of a finite automaton is the set of strings that it acceptsThe singular of automata is automaton.L(M) = All strings of 0s and 1sThe Language L(M) of Machine M0,1q0The language of a finite automaton is the set of strings that it accepts001L(M) ={ w | w has an even number of 1s}q00q111The Language L(M) of Machine MAn 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 ΣQ is the finite 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 M = (Q, Σ, , q0, F) L(M) = the language of machine M= set of all strings machine M acceptsQ = {q0, q1, q2, q3}Σ = {0,1} : Q Σ → Q transition functionq0 Q is start stateF = {q1, q2} Q accept statesM = (Q, Σ, , q0, F) where0 1q0q0q1q1q2q2q2q3q2q3q0q2q2 00,100111q0q1q3MThe finite-state automata are deterministic, if for each pair Q Σ of state and input value there is a unique next state given by the transition function.There is another type machine in which there may be several possible next states. Such machines called nondeterministic.Build an automaton that accepts all and only those strings that contain 001{0} 01{00} 01{001}10 0,1EXAMPLEBuild an automaton that accepts all binary numbers that are divisible by 3,i.e, L = 0, 11, 110, 1001, 1100, 1111, 10010, 10101… 10 011 0A 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 regularA language over Σ is a set of strings over ΣDetermine the language recognized by 010,1L(M)={1n | n = 0, 1, 2, …}Determine the language recognized byL(M)={1, 01} 0 0,10,1 1 1 0Determine the language recognized byL(M)={0n, 0n10x | n=0,1,2…, and x is any string} 1 0,10,1 1 0 0DFA Membership problemDetermine whether someword belongs to the language.Theorem: The DFA Membership Problem is solvable in linear time.Let M = (Q, Σ, , q0, F) and w = w1...wm. Algorithm for DFA M:p := q0;for i := 1 to m do p := (p,wi);if pF then return Yes else return No.Equivalence of two DFAsGiven a few equivalent machines, we are naturally interested in the smallest one with the least number of states.Definition: Two DFAs M1 and M2 over the same alphabet are equivalent if theyaccept the same language: L(M1) = L(M2).Union 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 language.Theorem: 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 12Idea: 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 Q2Theorem: The union of two regular languages is also a regular language00q00q11101p01p100Automaton for Union0p0 q01100011p0 q1p1 q0p1 q100The 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 }ReverseReverse: AR = { w1 …wk | wk …w1 A }How to construct a DFA for the reversal of a language?The direction in which we read a string should be irrelevant. If we flip transitions around we might not get a DFA.The Kleene closure: A*From the definition of the concatenation, we definite An, n =0, 1, 2, … recursivelyA0 = {ε}An+1 = An AStar: A* = { w1 …wk | k ≥ 0 and each wi A }A* is a set consisting of concatenations of arbitrary many strings from A.U0kkAA*The Kleene closure: A*What is A* of A={0,1}?All binary stringsWhat is A* of A={11}?All binary strings of an even number of 1sRegular 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.Theorem: Any finite language is regularClaim 1: Let w be a string over an alphabet. Then {w} is a regular language. Proof: By induction on the number of characters. If {a} and {b} are regular then {ab} is regularClaim 2: A language consisting of n strings is regular Proof: By induction on the number of strings. If {a} then L{a} is regularInput: Text T of length t, string S of length nPattern MatchingProblem: 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
View Full Document