1 / 35

CS172: “Computability & Complexity”

CS172: “Computability & Complexity”. Wim van Dam Soda 665 vandam@cs.berkeley.edu www.cs.berkeley.edu/~vandam/CS172/. Today. Chapter 0: set notation and languages Chapter 1: deterministic finite automata (DFA) nondeterministic FA (NFA) . Standard Set Theory:.

justise
Download Presentation

CS172: “Computability & Complexity”

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. CS172:“Computability & Complexity” Wim van Dam Soda 665 vandam@cs.berkeley.edu www.cs.berkeley.edu/~vandam/CS172/

  2. Today • Chapter 0: • set notation and languages • Chapter 1: • deterministic finite automata (DFA) • nondeterministic FA (NFA)

  3. Standard Set Theory: • Conditional: A = { x | x  N , f(x)=0 } • Union: AB • Intersection: AB • Complement: • Cartesian Product: AB • Power set: P(A)

  4. Some Examples L<6 = { x | x  N , x<6 } L<6  Lprime = {2,3,5}  = {0,1} = {(0,0), (0,1), (1,0), (1,1)} Formal: AB = { x | xA and xB}

  5. Powerset Formal: P(A) = { S | S A} Example: A = {x,y} P(A) = { {} , {x} , {y} , {x,y} } Note the different sizes: |P(A)| = 2|A| |AA| = |A|2

  6. Languages • Given an alphabet , we can make a word or string by concatenating the letters of . • Concatenation of “x” and “y” is “xy” • Typical example: ={0,1}, the possible words over  are the finite bit strings. • A language is a set of words.

  7. More about Languages • The empty string  is the unique string with zero length. • Concatenation of two langauges: A•B = { xy | xA and yB } • Typical examples: L = { x | x is a bit string with two zeros } L = { anbn | n  N} L = {1n | n is prime}

  8. A Word of Warning Do not confuse the concatenation of languages with the Cartesian product of sets. For example, let A = {0,00} then A•A = { 00, 000, 0000 } with |A•A|=3, AA = { (0,0), (0,00), (00,0), (00,00) } with |AA|=4

  9. Recognizing Languages • Let L be a language  S • a machine M recognizes L if “accept” if and only if xL xS M “reject” if and only if xL

  10. Finite Automaton The most simple machine that is not just a finite list of words. “Read once”, “no write” procedure. Typical is its limited memory. Think cell-phone, elevator door, etc.

  11. transition rules states 0 1 1 0 q1 q2 q3 0,1 starting state accepting state A Simple Automaton (0)

  12. 0 1 1 0 q1 q2 q3 start 0,1 accept A Simple Automaton (1) on input “0110”, the machine goes: q1  q1  q2  q2  q3 = “reject”

  13. 0 1 1 0 q1 q2 q3 0,1 on input “101”, the machine goes: A Simple Automaton (2) q1  q2  q3  q2 = “accept”

  14. 0 1 1 0 q1 q2 q3 0,1 A Simple Automaton (3) 010: reject 11: accept 010100100100100: accept 010000010010: reject : reject

  15. Finite Automaton (def.) • A deterministic finite automaton (DFA)M is defined by a 5-tuple M=(Q,,,q0,F) • Q: finite set of states • : finite alphabet • : transition function :QQ • q0Q: start state • FQ: set of accepting states

  16. 0 1 1 0 q1 q2 q3 0,1 M = (Q,,,q,F) • states Q = {q1,q2,q3} • alphabet  = {0,1} • start state q1 • accept states F={q2} • transition function:

  17. Recognizing Languages (def) A finite automaton M = (Q,,,q,F)accepts a string/word w = w1…wn if and only if there is a sequence r0…rn of states in Q such that: 1) r0 = q0 2) (ri,wi+1) = ri+1 for all i = 0,…,n–1 3) rn  F

  18. Regular Languages The language recognized by a finiteautomaton M is denoted by L(M). A regular language is a language for which there exists a recognizing finite automaton.

  19. Two DFA Questions Given the description of a finite automaton M = (Q,,,q,F), what is the language L(M) that it recognizes? In general, what kind of languages can be recognized by finite automata? (What are the regular languages?)

  20. Union of Two Languages Theorem 1.12: If A1 and A2 are regular languages, then so is A1 A2. (The regular languages are ‘closed’ underthe union operation.) Proof idea: A1 and A2 are regular, hence there are two DFA M1 and M2, with A1=L(M1) and A2=L(M2). Out of these two DFA, we will make a third automaton M3 such that L(M3) = A1 A2.

  21. Proof Union-Theorem (1) M1=(Q1,,1,q1,F1) and M2=(Q2,,2,q2,F2) • Define M3 = (Q3,,3,q3,F3) by: • Q3 = Q1Q2 = {(r1,r2) | r1Q1 and r2Q2} • 3((r1,r2),a) = (1(r1,a), 2(r2,a)) • q3 = (q1,q2) • F3 = {(r1,r2) | r1F1 or r2F2}

  22. Proof Union-Theorem (2) The automaton M3 = (Q3,,3,q3,F3) runs M1 and M2 in ‘parallel’ on a string w. In the end, the final state (r1,r2) ‘knows’if wL1 (via r1F1?) and if wL2 (via r2F2?) The accepting states F3 of M3 are such thatwL(M3) if and only if wL1 or wL2, for:F3 = {(r1,r2) | r1F1 or r2F2}.

  23. Concatenation of L1 and L2 Definition: L1•L2 = { xy | xL1 and yL2 } Example: {a,b} • {0,11} = {a0,a11,b0,b11} Theorem 1.13: If L1 and L2 are regular langues, then so is L1•L2. (The regular languages are ‘closed’ underconcatenation.)

  24. Proving Concatenation Thm. Consider the concatenation: {1,01,11,001,011,…} • {0,000,00000,…} (That is: the bit strings that end with a “1”, followed by an odd number of 0’s.) Problem is: given a string w, how does the automaton know where the L1 partstops and the L2 substring starts? We need an M with ‘lucky guesses’.

  25. q1 q2 Nondeterminism Nondeterministic machines are capable of being lucky, no matter how small the probability. A nondeterministic finite automaton has transition rules/possibilities like q2 1 q1 q3 1

  26. A Nondeterministic Automaton 0,1 0,1 0,  1 1 q1 q2 q3 q4 This automaton accepts “0110”, because there is a possible path that leads to an accepting state, namely: q1  q1  q2  q3  q4  q4

  27. A Nondeterministic Automaton 0,1 0,1 0,  1 1 q1 q2 q3 q4 The string 1 gets rejected: on “1” the automaton can only reach: {q1,q2,q3}.

  28. Nondeterminism ~ Parallelism For any (sub)string w, the nondeterministicautomaton can be in a set of possible states. If the final set contains an accepting state, then the automaton accepts the string. “The automaton processes the input in aparallel fashion. Its computational path is no longer a line, but a tree.” (Fig. 1.16)

  29. Nondeterministic FA (def.) • A nondeterministic finite automaton (NFA) M is defined by a 5-tuple M=(Q,,,q0,F), with • Q: finite set of states • : finite alphabet • : transition function :QP(Q) • q0Q: start state • FQ: set of accepting states

  30. Nondeterministic :QP(Q) The function :QP(Q) is the crucial difference. It means: “When reading symbol “a” while in state q,one can go to one of the states in (q,a)Q.” The  in  = {} takes care of the empty string transitions.

  31. Recognizing Languages (def) A nondeterministic FA M = (Q,,,q,F)accepts a string w = w1…wn if and only if we can rewrite w as y1…ym with yiandthere is a sequence r0…rm of states in Q such that: 1) r0=q0 2) ri+1  (ri,yi+1) for all i=0,…,m–1 3) rm  F

  32. Exercises (1:3) • [Sipser 0.3]: Let A = {x,y,z} and B = {x,y}, answer: • Is A a subset of B? • Is B a subset of A? • What is AB? • What is AB? • What is AB? • What is P (Q)?

  33. Exercises (2:3) • [Sipser 1.5]: Give NFAs with the specified number of states that recognize the following languages over the alphabet ={0,1}: • { w | w ends with 00}, three states • {0}; two states • { w | w contains even number of 0s, or exactly two 1s}, six states • {0n | nN }, one state

  34. Exercises (3:3) Proof the following result: “If L1 and L2 are regular languages, then is a regular language too.” Describe the language that is recognized by this nondeterministic automaton: 0,1 1 1 0,  1 q1 q2 q3 q4 

  35. Additional Practice Problems • [Sipser 0.2]: Write the formal descriptions of the sets containing • … the numbers 1,10 and 100 • … all integers greater than 5 • … all natural numbers less than 5 • … the string “aba” • … the empty string • … nothing • Give a formal description of this NFA: • Give DFA state diagrams for the following languages over ={0,1}: • { w | w begins with 1 and ends with 0} • { w | w does not contain substring 110} • {} • all strings except the empty string 1 0,  1 q1 q2 q3 

More Related