CS 8 B&C EXAM # NAME SPRING 204 UCLA ID You have 90 minutes to complete this exam. You may assume without proof any statement proved in class. Give a simple verbal description of the language recognized by the following DFA. 0 0 0 0 0 2 Draw NFAs for the following languages, taking full advantage of nondeterminism: a. strings over alphabet f0; ; : : : ; 9g where the final digit has not appeared before; b. binary strings that begin or end with 00 or.
3 Prove that the following languages over the binary alphabet are regular: a. strings in which every is immediately followed by 00; b. strings that contain both 00 and 0 as substrings; c. strings that end with 00.
4 Let L and L 2 be languages that can be recognized by NFAs with n and n 2 states, respectively. Prove that L \ L 2 can be recognized by a DFA with at most 2 n Cn 2 states. 5 Prove that every language L f0; g can be expressed as a countable union L D S for some regular languages R ;R 2 ;R 3 ;:::. id R i
6 For a language L, define delete.l/ Dfuv W u v 2 L for some 2 g: Thus, delete.l/ is the set of all strings obtained by taking a nonempty string in L and deleting a single character from it. Prove that if L is regular, so is delete.l/. 7 For a language L; define suffix.l/ Dfv W uv 2 L for some ug: Thus, suffix.l/ is the set of all suffixes of strings in L. Show how to transform a DFA for any given regular language L into an NFA for suffix.l/:
SOLUTIONS
CS 8 B&C EXAM # NAME SPRING 204 UCLA ID You have 90 minutes to complete this exam. You may assume without proof any statement proved in class. Give a simple verbal description of the language recognized by the following DFA. 0 0 0 0 0 Solution. All binary strings that end with 000. 2 Draw NFAs for the following languages, taking full advantage of nondeterminism: a. strings over alphabet f0; ; : : : ; 9g where the final digit has not appeared before; b. binary strings that begin or end with 00 or. Solution. a. b.
3 Prove that the following languages over the binary alphabet are regular: a. strings in which every is immediately followed by 00; b. strings that contain both 00 and 0 as substrings; c. strings that end with 00. Solution. a. The language is recognized by the following NFA: b. The language of strings containing 00 is recognized by Analogously, the language of strings containing 0 is recognized by Since regular languages are closed under intersection, the language in the problem statement is regular. c. The language is recognized by the following NFA: New Section Page 2 New Section Page 2 New Section Page 2 New Section Page 2
4 Let L and L 2 be languages that can be recognized by NFAs with n and n 2 states, respectively. Prove that L \ L 2 can be recognized by a DFA with at most 2 n Cn 2 states. Solution. Using the method discussed in class, transform the NFAs for L and L 2 to DFAs with at most 2 n and 2 n 2 states, respectively. Then combine these DFAs to obtain a DFA for L \L 2 with at most 2 n 2 n 2 D 2 n Cn 2 states, using the Cartesian-product construction from class. 5 Prove that every language L f0; g can be expressed as a countable union L D S for some regular languages R ;R 2 ;R 3 ;:::. id R i Solution. For any string w 2f0; g ; the language fwg is regular because it is recognized by the NFA Now define R i to be the language whose only string is the ith string in L, in lexicographic order (with the understanding that R i D if L has fewer than i strings). Then where each R i is regular by above. L D [ R i ; id
6 For a language L, define delete.l/ Dfuv W u v 2 L for some 2 g: Thus, delete.l/ is the set of all strings obtained by taking a nonempty string in L and deleting a single character from it. Prove that if L is regular, so is delete.l/. Solution: DFA for L NFA for delete(l) q! same as original DFA, but make all states reject ε add this arrow for every q and σ δ(q, σ)! same as original DFA 7 For a language L; define suffix.l/ Dfv W uv 2 L for some ug: Thus, suffix.l/ is the set of all suffixes of strings in L. Show how to transform a DFA for any given regular language L into an NFA for suffix.l/: Solution. Add "-transitions from the initial state q 0 to every state reachable from q 0.