Examination Formal Languages and Automata Theory TDDD14 (Formella Språk och Automatateori) 2012–08–23, 14.00 – 18.00 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 31: 3: 16 p, 4: 21 p, 5: 26 p. 4. Jour (person on duty): Wlodek Drabent, tel. (013 28) 89 29, or Jonas Wallgren, tel. (013 28) 26 82 (endast telefonjour – only by phone) 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 = {1, 2, 3, 4, 5}, the input alphabet Σ = {a, b, c}, the start state and the final state is 1.) Using a standard method construct an equivalent DFA. 2. (2p) 2 1 2 4 6 5 b c → 1 F ∅ {2} {4} ∅ ∅ {3} {5} {4} 2 3 ∅ ∅ ∅ {5} {3} {5} ∅ ∅ 4 5 {1} ∅ ∅ ∅ Using a standard method, construct the minimal DFA equivalent to the DFA given by the table. (Its set of states is Q = {1, 2, 3, 4, 5, 6}, the input alphabet Σ = {a, b}, the start state is 1, and {1, 3, 5} is the set of final states.) a b →1F 2 3F 4 5F 6 a 6 5 4 3 2 5 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 A D C C C D 4. (2p) (a) Consider regular expressions ∗ α = 1(00 + 0) 1 + (01)∗ and β = 1(00 + 0) 1(00 + 0) 1. Give an example of a string in L(α)\L(β), and of a string in L(β)\L(α), if such string exists. If a required string does not exist, you should explain that this is indeed the case. Remember that \ denotes the set difference. (b) The same for ∗ γ = 1(01 + 001)∗ and δ = 10(0 + ) 1 2 5. (2p) Construct a context-free grammar for the language L = { am+n bm+j ck+n | m ≥ 0, n > 0, j ≥ 2k ≥ 0 }. Make it clear what are the sets generated by the nonterminal symbols of your grammars, and what is the role of each production. 6. (6p) For each of the following languages answer whether it is regular, context-free but not regular, or not context-free. A brief, informal explanation is sufficient. (a,b) L1 is the language generated by the context-free grammar S → ASA | d A → a | aa | and L2 is generated by S → ASB | d A→a|b B → b | cb | . In the grammars, S, A, B are nonterminal symbols, a, b, c, d are terminal symbols, and S is the start symbol. (c) L3 = x, z ∈ {a, b, c}∗ , y ∈ {d, e}∗ , xyz . #a(x) = #a(z), #b(x) = #b(z), (d) L4 is the image of L3 under the homomorphism h : {a, b, c, d, e}∗ → {0, 1, 2}∗ such that h(a) = h(b) = 01, h(c) = h(d) = h(e) = . (e) L5 = { xyy | x ∈ {a, b}∗ , y ∈ {c, d}∗ }. (f) L6 = { yxy | x ∈ {a, b}∗ , y ∈ {c, d}∗ , |y| = 2 }. 7. (3p) Prove that a language L7 = { a(bj a)l | j > l ≥ 3 } is not regular or that it is not context-free. Use the appropriate pumping lemma or employ reasoning similar to the proof of the lemma. 8. (1p) Explain briefly the notion of the language of a decision problem. Hint: The notion is used below. 3 9. (3p) Show that a problem “a Turing machine M halts on some input” is undecidable. Use the fact that it is undecidable whether a Turing machine M halts on input . In other words, show that the language of the problem, Turing machine M HSI = hM i , halts on some input is not recursive, using the fact that the language Turing machine M HES = hM i halts on input is not recursive. Hint: You may find it useful that out of any TM M one can construct a TM M which on every input behaves like M on input . The TM M first erases its input and then runs M on the empty input. 10. (4p) Which of the following statements are true, which are false? Justify your answers. (a) LL 6= { xx | x ∈ L }, for each language L. (b) There exists a context-free language which is not generated by any context-free grammar in Chomsky normal form. (c) If L is a regular language then LR LR is context-free. By LR we mean the set of the reversed strings from L: LR = { xR | x ∈ L }. (d) The language HES from problem 9 is recursively enumerable. 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). 4 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, d are terminal symbols and S, A, B are nonterminal symbols of the grammars; S is the start symbol. (a) S → • Ad { $ } B −→ −→ The productions of the grammar are S → Ad, A → Ab | Bc, B → Ac | Ba. (b) A → a • bA { $, c } A → a • bAcA { $, c } A b −→ −→ The productions of the grammar are S → A, A → abA | abAcA | B, B → d. 12. (1p) Explain whether the grammar from problem 11b is LL(1). 5