Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 262 Automata, Computability, and Complexity Fall 2016 Instructor: Aaron Roth

Similar presentations


Presentation on theme: "CIS 262 Automata, Computability, and Complexity Fall 2016 Instructor: Aaron Roth"— Presentation transcript:

1 CIS 262 Automata, Computability, and Complexity Fall 2016 http://www.seas.upenn.edu/~cse262/ Instructor: Aaron Roth aaroth@cis.upenn.edu aaroth@cis.upenn.edu Lecture: Sept 1, 2016

2 Course Logistics 2 Homework 1: Posted on Piazza/Class website Due next Thursday (11:59am) Construct DFAs using AutomataTutor. (Note – by demonstration, determining if two finite automata accept the same language must be solvable! Not so for general computer programs..)

3 Recap 3 Alphabet  : Finite set of symbols/characters used for encoding A string w over an alphabet  is a finite sequence of symbols in  A language L over an alphabet  is a subset of  * Inputs are encoded as strings and (decision) problems correspond to languages

4 Example Language 4  = All English text characters String w then corresponds to a text document L 1 = { w | each of the vowels a, e, i, o, u occurs at least once in w } = { w | count(w,a)>0 and count(w,e)>0 and count(w,i)>0 and count(w,o)>0 and count(w,u)>0 } notation: count(w,  ) = the number of times the symbol  occurs in w L 2 = { w | count(w,a) = count(w,e) }

5 Encoding Graph Problems 5 Problem: Given the graph of Facebook friends connections, find the person with the highest number of connections Decision version: Given a graph of connections among n people (numbered 1 through n) and person identifier m (between 1 and n), check if person m has the highest number of connections

6 Encoding Graph Problems 6 In this graph over 4 people, does person 2 have max number of connections?  = { 0, 1, # } 12 43 1 0 0 # 1 0 # 1 # 1 0 # 1 # 1 1 # 1 # 1 0 0 # 1 0 # 1 1 # 1 1 # 1 0 0 # Number of People 4 Person identifier 2 Edge between 1 and 2 Edge between 1 and 3

7 Graph Problems as Languages 7  = { 0, 1, # } L = { w | w encodes a graph over n people such that person m has the highest number of connections } Example string in the language: Example string not in the language: We don’t need to worry about such low-level encoding of problems, but the high-level point is that it can be done! 1 0 0 # 1 0 # 1 # 1 0 # 1 # 1 1 # 1 # 1 0 0 # 1 0 # 1 1 # 1 1 # 1 0 0 # 1 0 0 # 1 1 # 1 # 1 0 # 1 # 1 1 # 1 # 1 0 0 # 1 0 # 1 1 # 1 1 # 1 0 0 #

8 Machines for Languages 8 Machine M for a language L: Given an input string w, machine M scans w from left to right, processing one symbol in each step After reading the entire string w, M should either accept or reject w, depending on whether or not w is in L

9 Finite-state Machines 9 Machine M has some fixed (finite) number of states q0q0 q1q1 q3q3 q4q4 q2q2 One of these states is the initial state Behavior specified by transitions: for each state, based on symbol being processed, what should the next state be a b Some states marked as accept/final states: after reading the entire input w, if M ends up in a final state, then accept w, else reject w

10 Designing Finite Automaton: Example 1 10 Construct machine M for L = { w | w contains an even number of a’s }, where  = { a, b } q0q0 q1q1 Start with the initial state Figure out transitions out of q 0 on a and b a b Key question: can we reuse an existing state or need a new state? Figure out transitions out of q 1 on a and b a b

11 Designing Finite Automaton: Example 1 11 Construct machine M for L = { w | w contains an even number of a’s }, where  = { a, b } q0q0 q1q1 a b a b Execution or “run” of the machine on input string w = abbab q0 q0 a q1 q1 b q1 q1 b q1 q1 a q0 q0 b q0 q0 Which states should be final/accepting ?

12 Designing Finite Automaton: Example 2 12 Construct machine M for L = { w | w ends with a }, where  = { a, b } q0q0 q1q1 a b b a After reading a string w, the machine is in state q 1 if w ends with a, and in state q 0 otherwise In particular, after reading the empty string , M is in state q 0, and thus rejects 

13 Designing Finite Automaton: Example 3 13 Construct machine M for L = { w | w contains the substring “ACC” }, where  = { A, C, G, T } q0q0 q1q1 A C, G,T G,T A q2q2 C q3q3 C A,C, G,T A G,T Precisely describe the set of strings w such that the machine is in state q 2 after reading w { w | w does not contain the substring “ACC” and ends with “AC” }

14 Designing Finite Automaton: Example 4 14 Construct machine M for L = { w | count(w,a) = count(w,b) }, where  = { a, b } q0q0 q1q1 a q2q2 a q3q3 a q4q4 a String aa leads to q 2 and aaa leads to q 3. String aabb should be accepted but aaabb should be rejected. So states q 2 and q 3 have to be distinct (otherwise M cannot possibly make the correct decision if what follows is string “bb”). By similar logic, all the states q 1, q 2, q 3, q 4, … have to be pairwise distinct. There does not exist a finite-state machine for L. Rigorous proof based on a general technique in a couple of lectures …

15 Designing Finite Automaton: Example 5 15 Construct machine M for L = { w | decimal number corresponding to w is divisible by 3 }, where  = { 0,1,2,…,9 } q0q0 q1q1 0,3,6,9 q2q2 2,5,8 1,4,7

16 Formal Definition 16 A deterministic finite automaton (DFA) M consists of  a finite set Q of states  a finite alphabet   an initial state q 0 that belongs to Q  a subset F of Q, called accepting/final states  a transition function  : Q x   Q (if M reads symbol  in state q, the resulting state is  (q,  ) )

17 Example Automaton 17 Q = { q 0, q 1 }  = { a, b } Initial state = q 0 F = { q 0 } Transition function:  (q 0,a) = q 1,  (q 0,b) = q 0,  (q 1,a) = q 0,  (q 1,b) = q 1 q0q0 q1q1 a b a b

18 Language of a DFA 18 Let M = (Q, , q 0, F,  ) be a DFA. L(M) = The set of strings w over  such that M accepts w Let us capture acceptance using a more mathematical notation that will be useful later in some proofs and constructions

19 Extended Transition Function 19 Let M = (Q, , q 0, F,  ) be a DFA.  is one-step transition function:  Maps a state and a single symbol to a state   (q,  ): if machine starting in state q reads the single symbol , where will it be  * : multi-step transition function (reflexive-transitive closure of  )  Maps a state and a string w to a state   *(q,w): if the machine starting in state q processes the entire string w, where will it be ?

20 Definition: Extended Transition Function 20 How to define  * in terms of  ? Inductive definition based on definition of strings A string w is either the empty string  or is of the form x , where x is a string (of length one shorter than w) and  is a symbol  *(q,  ) = q  *(q, x  ) =  (  * (q, x),  ) Basically, first clause says how strings of length 0 are processed and second clause says how strings of length n+1 are processed by relying on processing of strings of length n Exercise: Prove: for all q, for all strings u,v,  *(q, u.v) =  *(  *(q, u), v) q x 

21 Definition: Language of a DFA 21 Let M = (Q, , q 0, F,  ) be a DFA. Definition: M accepts w if  *(q 0, w) is in F L(M) = { w |  *(q 0, w) is in F } If F = Q, what is L(M) ? The set of all strings:  * If F is the empty set , what is L(M)? The empty set of strings:  If F = { q 0 }, what is L(M)? L(M) contains the empty string , but can’t say much more


Download ppt "CIS 262 Automata, Computability, and Complexity Fall 2016 Instructor: Aaron Roth"

Similar presentations


Ads by Google