Examination Formal Languages and Automata Theory TDDD14 & TDDA89 (Formella Språk och Automatateori) 2009–06–03, 14.00 – 18.00 With a minor error in 9c corrected. 1. Allowed help materials • A sheet of notes - 2 sided A5 or 1 sided A4. The contents is up to you. The notes should be signed in the same way as the exam sheets and returned together with the exam. • English dictionary Tillåtna hjälpmedel: • Ett papper med valfria anteckningar - 2 sidor A5 eller 1 sida A4. Anteckningarna ska signeras på samma sätt som tentamensarken och bifogas tentamen vid inlämnandet. • Engelsk ordbok 2. You may answer in Swedish or English. 3. Total number of credits is 30: 3: 15 p, 4: 20 p, 5: 25 p. G: 15 p, VG: 23 p. 4. Jour (person on duty): Wlodek Drabent, tel. 28 89 29 GOOD LUCK !! 1 Make sure that you justify your answers! Unexplained answers will be granted 0 points. (For example, assume that you are writing a grammar for a given language. Then you should also explain that the grammar indeed generates the language). 1. (2p) Consider the NFA whose transition function is given by the table. (Its set of states is Q = {A, B, C, D, E, F }, the input alphabet Σ = {0, 1}, the start state and the final state is A.) Using a standard method construct an equivalent DFA. 2. (2p) →AF B C D EF F G H 0 1 B D D D F H A D E F C E A F G A →AF ∅ ∅ B C ∅ ∅ D E {A} {B} F 0 1 {B} {D} {C} {E} ∅ {F } {E} ∅ {F } ∅ ∅ ∅ Using a standard method, construct the minimal DFA equivalent to the DFA given by the table. (Its set of states is Q = {A, B, C, D, E, F, G, H}, the input alphabet Σ = {0, 1}, the start state is A, and {A, E} is the set of final states.) 3. (2p) Using a standard method, construct a regular expression defining the same language as the given DFA. (Its set of states is Q = {A, B, C, D}, the input alphabet Σ = {0, 1}, the start state and the final state is A.) →AF B C D 0 1 B D D C D C B A 4. (2p) Find out a method of finding out whether a given DFA M and a given regular expression α define the same language (in other words, whether L(M ) = L(α).) 5. (6p) For each of the following languages answer whether it is regular, context-free but not regular, or not context-free. (Here a brief explanation is sufficient.) (a) L1 = ai bj ck di |i − k| = 1, j ≥ 0 , (b) L2 = ai bj ck dj |i − k| = 1, j ≥ 0 , 2 ai bj cj+i+k dk i, j, k ≥ 0 , (d) L4 = ai bj cj+i+k dk i is even, j is odd, k ≡ 1 mod 3 (c) L3 = (e) L5 is the image of L4 under the homomorphism h : {a, b, c, d}∗ → {0, 1, 2}∗ such that h(a) = 2, h(b) = 11, h(c) = , h(d) = 000. 6. (3p) Prove that the language L6 generated by the grammar S → ASb | a A → a | aA is not regular, or that L7 = { xm bj xR | x ∈ {a, c}∗ , j > |x|, m > 0 }. is not context-free. Use the appropriate pumping lemma or employ reasoning similar to the proof of the lemma. In the grammar, S is the start symbol, A is a nonterminal, a, b are terminal symbols. Remember that xR denotes the string x reversed. 7. (2p) Explain briefly the notion of a universal Turing machine (UTM). What is the language accepted by it? To which class of languages does it belong? 8. (3p) Let A be a symbol from the tape alphabet of a Turing machine M . We say that M on some input writes A, when M writes A on the tape at some step of the computation started with some string on the tape. (Assume that this includes writing A into a cell already containing A.) Show that the problem “a Turing machine M on some input writes A” is undecidable. In other words, show that the language of the problem, Turing machine M WP = hM, Ai , on some input writes A is not recursive. Use the fact that it is undecidable whether a given Turing machine loops on all inputs. The language of this problem is Turing machine M LP = hM i loops on every input (and is not recursive). Brackets h i denote the encoding of a string, a TM, etc. as a string over alphabet {0, 1}. 3 9. (4p) Which of the following statements are true, which are false? Justify your answers. (a) The empty language ∅ is not regular. (b) If L is a regular language containing strings uw, uvw, uv 2 w then it also contains uv 7 w. (c) Let L be a language and h a homomorphism. If h(L)L is not a context-free language then L is not context-free. (d) The language accepted by a non total Turing machine is not a recursive language. (A TM is non total if it loops on some inputs.) 10. (1p) Consider a grammar S → Ac A → aSc | bScc | (S, A are nonterminal symbols, S is the start symbol, a, b, c are terminal symbols.) Is the grammar LL(1)? 11. (3p) In an attempt to construct LR parsers for certain grammars, we applied the standard method of constructing a DFA for the viable prefixes of a grammar. Some fragments of the obtained DFA’s are given below. Complete the missing items in the given states, the missing lookahead sets and the missing symbols labelling the arrows. In each case answer the following questions. Justify your answers. • Does the fragment of a DFA satisfy the conditions for the grammar to be LR(0)? • The same question about the conditions for LR(1). You may skip adding missing items or lookahead sets if they are not needed to answer the questions. For instance if you find the items in some state to violate the LR(1) conditions then you do not need to complete the other states. a, b, c are terminal symbols and S, A, B are nonterminal symbols of the grammars; S is the start symbol. 4 (a) y y A → b • Acc {c} a −→ ←− c −→ The productions of the grammar beginning with A are A → bAcc | aAc | c. (b) A → b • Aa {$} B → b • bBa {$} b B −→ −→ The productions of the grammar beginning with A or B are A → bAa | B, B → bbBa | . 5