CIT 596 Theory of Computation Spring 2005, 212 Moore, TR 12-1.30PM Homework Assignment 2 Due: Tuesday, February 1, 2005, by 12 PM (IN CLASS) Name: Student ID (8 digits): Email: Signature: PLEASE, READ THE FOLLOWING INSTRUCTIONS: Fill out this form with your name, student ID, email, and signature and return it as the cover page of your homework. Turn in your homework at the beginning of your class on the due date described at the top of this page. Late assignments will be penalized 25% and will not be accepted after 1:30PM of the day following the due date. Late assignments must be turned in to Janean Williams in room 308, 3rd floor, Levine Building. All writings must be neat, well-organized, and include sufficient explanations in the delineation of the solutions. Full credit will be given only in the case where the correct answer has been properly justified with complete explanations. Good luck! Question 1 2 3 4 5 6 Max 10 20 20 10 20 20 Score TOTAL:
Problem 1 [10 points] The reversal of a string w, denoted w R, is the string spelled backwards. For example, reverse R = esrever. Formally, we can define the reversal of a string by induction on the length of the string as follows: i. If w is a string of length 0 then w R = w = ɛ. ii. If w is a string of length n + 1 > 0 over Σ then w = ua for some a Σ, and w R = au R. By using the above formal definition of reversal of a string, we can compute the reversal of the string reverse as follows: reverse R = e(revers) R, revers R = s(rever) R, rever R = r(reve) R, reve R = e(rev) R, rev R = v(re) R, re R = e(r) R, r R = r(ɛ) R, and ɛ R = ɛ. So, reverse R = esreverɛ = esrever, as expected. (a) Use the inductive definition of reversal of a string to compute the reversal of the string 010010 over Σ = {0, 1}. (b) Note that item (ii) of the above definition of reversal of a string can also be defined as: If w is a string of length n + 1 > 0 over Σ then w = au for some a Σ, and w R = u R a. Using this definition for item (ii), compute the reversal of the string 010010 over Σ = {0, 1}. (a) 010010 R = 0(01001) R, 01001 R = 1(0100) R, 0100 R = 0(010) R, 010 R = 0(01) R, 01 R = 1(0) R, 0 R = 0(ɛ) R, ɛ R = ɛ. So, 010010 R = 010010. (b) 010010 R = (10010) R 0, 10010 R = (0010) R 1, 0010 R = (010) R 0, 010 R = (10) R 0, 10 R = (0) R 1, 0 R = (ɛ) R 0, ɛ R = ɛ. So, 010010 R = 010010. 2
Problem 2 [20 points] Let Σ be any alphabet. Use the inductive definition of reversal of a string given in the previous problem to prove that (w R ) R = w for any w Σ. Note that an obvious choice for your method of proof is induction on the length of the string. We prove the claim using induction on the length w of w. For the base case, we have w = 0, which means that w = ɛ. From the definition of the reversal of a string, we have that ɛ R = ɛ. So, (w R ) R = (ɛ R ) R = (ɛ) R = ɛ = w, and therefore our claim holds for w = 0. For the induction hypothesis, assume that (w R ) R = w for every string w such that w = k, where k is an integer with k 0. Now, we must prove that (w R ) R = w for every string w such that w = k + 1. Since k + 1 1, we can write w = ua, where a Σ and u Σ. From the definition of reversal of a string, we know that w R = (ua) R = au R. From item (b) in Problem (1), we also know that (w R ) R = (au R ) R = (u R ) R a. Since the length of u is k, we can use the induction hypothesis to conclude that (u R ) R = u. So, (w R ) R = (au R ) R = (u R ) R a = ua = w, and our claim also holds for w Σ such that w = k+1. From the first principle of induction, our claim holds for every w Σ. 3
Problem 3 [20 points] Let M = (Q, Σ, δ, q 0, F ) be a DFA. Under exactly what circumstances is ɛ L(M)? Specify a condition that would guarantee that L(M) = Σ? Justify your answers. Note that ɛ L(M) if and only if δ(q 0, ɛ) F. But, by definition of δ, δ(q 0, ɛ) = δ(q 0, ɛ) = q 0. So, ɛ L(M) if and only if q 0 F. Similarly, L(M) = Σ if and only if δ(q 0, w) F for all w Σ. Since δ(q 0, w) can in principle be any state of M, a condition that would guarantee that δ(q 0, w) F is F = Q. 4
Problem 4 [10 points] Draw and specify the five parts of a DFA that accepts the language of all strings w over Σ = {a, b} such that w contains at least two consecutive b s and w does not contain two consecutive a s. Let M = (Q, Σ, δ, q 0, F ) such that Q = {s 1, s 2, s 3, s 4, s 5, s 6 }, Σ = {a, b}, q 0 = s 1, F = {s 5, s 6 }, and δ is given by the following table: a b s 1 s 2 s 3 s 2 s 4 s 3 s 3 s 2 s 5 s 4 s 4 s 4 s 5 s 6 s 5 s 6 s 4 s 5 Your solution should contain the finite state diagram corresponding to the above DFA. 5
Problem 5 [20 points] Draw and specify the five parts of a DFA that accepts the language of all strings w over Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} such that the sum of the digits of w is divisible by 7. For example, w = ɛ, w = 95, w = 007 are in the aforementioned language, as 0, 9 + 5 = 14, 0 + 0 + 7 = 7 are all divisible by 7. A DFA for the language of all strings w over Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} such that the sum of the digits of w is divisible by 7 can be easily built using our knowledge on Number Theory. The idea is to build a DFA in which each state corresponds to a remainder of the division of a number x by 7. If the DFA is in the state s n, for 0 n < 7, and the current input symbol is a Σ, the DFA goes to state s (n+a) mod 7. Formally, we have M = (Q, Σ, δ, q 0, F ) such that Q = {s 0, s 1, s 2, s 3, s 4, s 5, s 6 }, Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, q 0 = s 0, F = {s 0 }, and δ is given by δ(s i, a) = s (i+a) mod 7 for all i with 0 i < 7 and for all a Σ. Your solution should contain the finite state diagram corresponding to the above DFA. 6
Problem 6 [20 points] Let M = (Q, Σ, δ, q 0, F ) be an (arbitrary) DFA that accepts the language L(M). Write down a general procedure for modifying this machine so that it will accept L(M) {ɛ}. Specify the five parts of the new machine and justify your statements. Let M = (Q, Σ, δ, s, F ) be the new DFA. If ɛ L(M), we just have to let M = M. Otherwise, we know that q 0 F, and we define M as follows: The set Q of states of M contains all states of Q and a new state s, which is the initial state of M. The transition function δ is defined such that δ (q, a) = δ(q, a) for all q Q and a Σ and δ (s, a) = δ(q 0, a) for all a Σ. That is, M is the DFA M with one more state, s, which is now the initial state of M. The state s mimics the initial state of M in the sense that δ (s, a) = δ(q 0, a) for all a Σ. Note that there is no transition from a state q Q with q s to state s, i.e., there is no state q Q such that δ (q, a) = s, for any a Σ. We now claim that L(M ) = L(M) {ɛ}. Since s F, we have that ɛ L(M ). Now, note that, for all w Σ +, we can write w = au such that a Σ and u Σ. From the definition of extended transition function, we have that δ (s, w) = δ (δ (s, a), u). From the definition of δ, we have that δ (s, a) = δ(q 0, a). So, δ (s, w) = δ (δ (s, a), u) = δ (δ(q 0, a), u). Since there is no transition from a state q Q to s in M, we have that δ (δ (s, a), u) = q if and only if δ(δ(q 0, a), u) = q, for all w Σ +, with q Q. So, w = au L(M) if and only if w = au L(M ), and therefore L(M ) is precisely L(M) {ɛ}. 7