All of my Theory Exams From 2017–2019 Good luck! 1492740742 Page 2 Coderson, Cody Question 1. [30 points (2 points each)] Answer true or false to each of the following. Put an ‘X’ in the T box if the answer is always true, and in the F box otherwise. No justification needed. (a) T F If M is a DFA with k states, then L ( M ) contains a string of length k − 1. (b) T F If L is a finite language, then L ∩ ( LL ∪ L ? ) is regular. (c) T F Let L be any regular language. Then #( L ) = { 1 | w | : w ∈ L } is regular. (d) T F Let L ⊆ { 0 , 1 } ? be the language consisting of all strings having an equal number of 01 substrings and 10 substrings. Then L is not regular. (e) T F Let L ⊆ { 0 , 1 , 2 } ? be the language consisting of all strings having an equal number of 01 substrings and 10 substrings. Then L is not regular. (f) T F The set of non-regular languages is closed under complement. (g) T F Let L i for i ≥ 0 be an infinite set of regular languages. Then ( ⋃ ∞ i =1 L i ) is regular. (h) T F Let L = { wxw : | w | ≤ 1 + | x | , w ∈ { 0 , 1 } ? , x ∈ { 0 , 1 } ? } . Then L is regular. (i) T F For a given non-empty regular language L , let k d be the smallest number of states for any DFA recognizing L , and k n be that for any NFA recognizing L . Then k n = k d (j) T F For any non-empty language L , L ? is infinite. (k) T F For a DFA D , L ( D ) is infinite if and only if it accepts some string with length at least the number of states of D (l) T F A computation in an NFA on an input with n characters is a sequence of exactly ( n + 1) states. (m) T F Every NFA has the same language as some GNFA with 2 states. (n) T F For a set of states S in an NFA, there can be an ε -transition from state s ∈ E ( S ) to state t / ∈ E ( S ). (o) T F Suppose two DFAs D 1 , D 2 have n 1 , n 2 states each, and f 1 , f 2 final states each. Now form the DFA D from the product construction for the union of their languages. Then D has f 1 × n 1 + f 2 × n 2 − f 1 × f 2 final states. 1 1492740742 Page 3 Coderson, Cody Question 2. [30 points (20+10)] Prove that L 1 = { (011) n +1 (010) n : n ≥ 0 } is not regular. Let L 2 ⊆ { 0 , 1 } ? be the language consisting of all strings that have exactly one more occurrence of 011 substrings than 010 substrings. Prove that L 2 is not regular, without using the Pumping Lemma (Hint: use L 1 ). 1 1492740742 Page 4 Coderson, Cody Question 3. [30 points (10+10+10)] Fix Σ = { 0 , 1 } . Let L 1 ⊆ Σ ? be the language of all strings having at least one 0, and L 2 ⊆ Σ ? be the language of all strings such that their binary representation is not divisible by 3. Construct two DFAs D 1 , D 2 for L 1 , L 2 respectively. Using D 1 and D 2 , give a state diagram of a DFA recognizing L 1 ∩ L 2 , using only the techniques from class. Using the DFA in the previous part, describe in English, as well as in a state diagram, how to generate a DFA recognizing the symmetric difference of L 1 , L 2 (strings that belong to exactly one of L 1 , L 2 ). 1 1492740742 Page 5 Coderson, Cody Question 4. [30 points (15 + 15)] Construct an equivalent NFA for the regular expression (01 ∪ 2) ? using only and exactly the methods described in class Convert the NFA you just created into an equivalent DFA, using only and exactly the methods described in class 1 1492740742 Page 6 Coderson, Cody Question 5. [30 points (10 + 20)] Construct an equivalent NFA for the following regular grammar, using only the techniques described in class ( S is the start variable): S → aA A → ε | bS | bA | aB B → b | aS Then convert the NFA you create into an equivalent regular expression, using only the techniques described in class Show all steps. 1 1492740742 Page 7 Coderson, Cody Question 6. [15 points (10+5)] Let Σ , Γ be alphabets. A homomorphism , h , is a function from Σ ? → Γ ? with the property that h ( xy ) = h ( x ) h ( y ) for all x, y ∈ Σ ? If w = w 1 · · · w n ∈ Σ ? and each w i ∈ Σ, then h ( w ) = h ( w 1 ) · · · h ( w n ). For any language L ⊆ Σ ? , let the homomorphism of L be: h ( L ) = { h ( w ) : w ∈ L } Prove that regular languages are closed under homomorphism. Give an example of a non-regular language L ′ and a homomorphism h such that h ( L ′ ) is regular. 1 1492740742 Page 8 Coderson, Cody Question 1. Let L = { w ∈ { 0 , 1 } ? : | w | is a power of n , and n is even } . Prove that L is not context-free. Recall the definition of homomorphism from Midterm #1: let Σ , Γ be alphabets. A homomorphism , h , is a function from Σ ? → Γ ? with the property that h ( xy ) = h ( x ) h ( y ) for all x, y ∈ Σ ? If w = w 1 · · · w n ∈ Σ ? and each w i ∈ Σ, then h ( w ) = h ( w 1 ) · · · h ( w n ). For any language L ⊆ Σ ? , let the homomorphism of L be: h ( L ) = { h ( w ) : w ∈ L } Show that context-free languages are closed under homomorphism (Hint: use a CFG, and this is easier than it looks!) 1 1492740742 Page 9 Coderson, Cody Question 2. Complete one (1) of the following two problems. Attempting both will result in a score that is the minimum of both attempts. (a) A backtracking Turing Machine (BTM) is just like a normal TM except that there is another transition that “backtracks”–when taken from state q , this transition instantly resets the tape contents and tape head location to be exactly when the machine was last in state q . If the machine was not in state q before, the tape does not change. Prove that the languages recognized by BTMs are equivalent to those recognized by “stan- dard” (deterministic, single-tape) TMs. (b) A stack Turing machine (STM) is like a normal TM except in every tape cell there is, in addition to a symbol, a stack. On each transition taken, the machine, in addition to modifying the cell’s symbol and move left or right, can push or pop from that individual cell’s stack (or both, or neither, as how a PDA can). If the STM attempts to pop from a cell’s stack that is empty, the computation terminates. Prove that the languages recognized by STMs are equivalent to those recognized by “stan- dard” (deterministic, single-tape) TMs. 1 1492740742 Page 10 Coderson, Cody Question 3. Convert the following CFG into CNF ( S is the start variable), using exactly the methods from class S → aBc | ab B → SB | ε Show all steps. 1 1492740742 Page 11 Coderson, Cody Question 4. Here is the same CFG from Question 3: S → aBc | ab B → SB | ε Convert this CFG into an equivalent PDA, using exactly the methods from class Suppose we were to convert the above PDA back into an equivalent CFG. Write 5 rules that this resulting CFG would have, using exactly the methods from class : 1 from the first rule type, and 2 from each of the second and third rule types. 1 1492740742 Page 12 Coderson, Cody Question 5. Construct a state diagram of a Turing Machine to recognize the language: { 0 n #1 2 n #2 3 n : n ≥ 0 } 1 1492740742 Page 13 Coderson, Cody Question 6. Let INFINITE DFA = {〈 M 〉 : M is a DFA and L ( M ) is an infinite language } Show that this lan- guage is decidable. (Hint: use the decider for E DFA , and the pumping lemma may also help.) Let THREE DFA = {〈 M 〉 : M is a DFA and M accepts at most 3 strings } . Show that this language is decidable (Hint: use the decider for INFINITE DFA ). 1 1492740742 Page 14 Coderson, Cody Question 1. [35 points (3 each + 2)] Using one of the descriptions empty, finite, regular, CFL, recognized by LBA, decidable, recognizable , and not recognizable to classify languages, indicate the most restrictive class to which each language belongs. No justification is needed. language Member of most restrictive class ... { w ∈ { 0 , 1 } ? : # 0 ( w ) = # 1 ( w ) } {〈 G 〉 : G is a CFG and L ( G ) 6 = ∅} { a i b j c k d ` : i + j + k + ` is a multiple of 27 } strings representing (non-reversed) accepting computation histories E DF A ∩ IN F IN IT E DF A EQ T M ALL CF G { w ∈ { 0 , 1 } ? : # 0 ( w ) ≤ 8675309 , # 1 ( w ) ≤ 10 10 101010100 } complement of a CFL L 1 L 2 where L 1 , L 2 are recognizable language of a PDA that always pops and never pushes on any transition For 2 more points, what is ∅ ? ∅ ? 1 1492740742 Page 15 Coderson, Cody Question 2. [40 points (10+15+15)] Let L 1 = { w ∈ { 0 , 1 } ? : w contains the subsequence 11 } and L 2 = { w ∈ { 0 , 1 } ? : w starts with a 0 } Construct DFAs for L 1 and L 2 Construct a DFA for the language L 1 ∩ L 2 , using exactly the methods from class. Using the DFA you made for L 1 , convert it into an equivalent regex, using exactly the methods from class 1 1492740742 Page 16 Coderson, Cody Question 3. [35 points (20+15)] Consider the following NFA: q 0 q 1 q 2 q 3 b, ε a a a, ε b b a, ε Convert this NFA into an equivalent DFA, using exactly the methods from class. Convert the original NFA into an equivalent regular grammar, using exactly the methods from class. 1 1492740742 Page 17 Coderson, Cody Question 4. [40 points (15+25)] Here is a CFG ( S is the start variable); convert it to an equivalent PDA using exactly the methods from class S → aBb B → ac | S | ε Using the same grammar above, convert it to CNF. Show all steps. 1 1492740742 Page 18 Coderson, Cody Question 5. [35 points (6 + 9 + 20)] Let Square ( L ) = { ww : w ∈ L } , and Double ( L ) = { wx : w, x ∈ L } Explain why, in general, Square ( L ) 6 = Double ( L ). Also say why if L is a CFL, Double ( L ) is also a CFL. Prove that there is a regular language L for which Square ( L ) is not a regular language. Prove that there is a CFL L for which Square ( L ) is not a CFL. 1 1492740742 Page 19 Coderson, Cody Question 6. [40 points (20 + 20)] Let N, k, v, t be positive integers with k ≥ v ≥ t . A perfect hash family (PHF) is an N × k array ( N rows, k columns) where each cell has one of v possible symbols and for any t of the k columns, at least one of the rows restricted to those columns has all distinct values. We call t the “strength” of the perfect hash family. Let L = {〈 N, k, v, t 〉 : there exists a PHF with N rows, k columns, v symbols, and strength t } Show that L is decidable. Let W EIRD N F A = {〈 M 〉 : M is an NFA, M has at most 7 states, accepts ε , and L ( M ) is infinite } Show that W EIRD N F A is decidable. 1 1492740742 Page 20 Coderson, Cody Question 7. [35 points (20+15)] Prove that SU P EROBEY T M = {〈 M 1 , M 2 〉 : M 1 , M 2 are TMs, L ( M 1 ) ⊆ L ( M 2 ), and L ( M 2 ) contains at least 1 more string than L ( M 1 ) does } is not decidable. (Hint: E TM ) Prove that IN T ERCF L T M = {〈 M 〉 : M is a TM and L ( M ) is the intersection of 2 CFLs, and L ( M ) is also a CFL } is not decidable. 1