Solution to HW2 of Honors Theory

March 1, 2002

1. (0 Point)

2. (10 + 15 Points) (i) We construct a NFA M with n + 1 states that accepts L_{n}.

M = (Q, Σ, δ, q_{0}, F) Q = {q_{0}, q_{1}...q_{n}} Σ = {a_{1}, a_{2}...a_{n}} F = {q_{1}, q_{2}...q_{n}} δ(q_{0}, ϵ) = q_{i}, i ≠ 0 δ(q_{i}, a_{j}) = q_{i}, i ≠ j, i ≠ 0.

(ii) Assign to each string w a binary characteristic number f(w) = b_{n}...b_{0}, where b_{i} = 0 if a_{i} does not appear in w, and b_{i} = 1 if a_{i} appears in w. There are 2^{n} such numbers. Only the strings that have the characteristic number with all bits set to 1 are rejected. Show that every DFA that accepts L_{n} has at least 2^{n} states. Suppose not, then there is a DFA M with less than 2^{n} states that accepts L_{n}. According to Pigeonhole Principle, there are at least two strings w and w′ with different characteristic numbers x and y that reach the same state q_{1}. We have: δ(q_{0}, w) = q_{1} δ(q_{0}, w′) = q_{1}. As x ≠ y, they have at least one bit b_{k} that is different. WLOG, assume b_{k} = 1 in x, and b_{k} = 0 in y. Choose a string s = a_{1}...a_{k−1}a_{k+1}...a_{n}, then f(ws) has all bits equal to 1, and f(w′s) has all bits except b_{k} equal to 1. So ws should be rejected, while w′s should be accepted. But δ(q_{0}, ws) = δ(q_{1}, s) = δ(q_{0}, w′s). We obtain a contradiction.

3. (15+10 Points) (i) As A is context free, there is a PDA M_{1} = {Q_{1}, Σ_{1}, Γ_{1}, δ_{1}, S, F_{1}} that recognizes it. As B is regular, there is a DFA M_{2} = {Q_{2}, Σ_{2}, δ_{2}, q_{0}, F_{2}} that recognizes it. We construct a PDA M that recognizes A/B: M = {Q, Σ, Γ, δ, S, F } Q = Q_{1} ∪ (Q_{1} × Q_{2}) Σ = Σ_{1} + Σ_{2} Γ = Γ_{1} F = F_{1} × F_{2}. First copy all the states and transitions of M_{1} to M, but make all the accepting states of M_{1} nonaccepting in M. Then add a new state q_{ij} for each pair (q_{i}, q_{j}), where q_{i} ∈ Q_{1}, q_{j} ∈ Q_{2}. The accepting states are those q_{ij}’s, with q_{i} ∈ F_{1}, and q_{j} ∈ F_{2}. Add transitions between the states in Q_{1} × Q_{2}: for each symbol a such that q_{i}, a, A → q_{I}, B in M_{1}, and q_{j}, a → q_{J} in M_{2} add a transition q_{ij}, ϵ, A → q_{IJ}, B Add transitions between Q_{1} and Q_{1} × Q_{2}: for each q_{i} ∈ Q_{1} add a transition q_{i}, ϵ, ϵ → q_{i0}, ϵ. (ii) A = {0^{p}1^{n}, p is prime, n ≥ p} B = {01^{∗}} C = {0^{p−1}, p is prime }. As B is regular, if A is context free, then C = A/B is context free. But we will show that C is not context free, so A is not context free. Use the pumping lemma to show that the language C = {0^{p−1}, p is prime } is not context free. We assume that C is context free and obtain a contradiction. Let l be the pumping length for C that is guaranteed to exist by the pumping lemma. Select the string s = 0^{m−1} where m is a prime greater than l. Clearly s is a member of C and of length at least l. According to pumping lemma, we can pump s by dividing s = uvxyz, where |vxy| ≤ l and |vy| > 0. Pick i = m + 1, |uv^{i}xy^{i}z| = |uvxyz| + |vy| × (i − 1) = m − 1 + m × |vy| = m × (|vy| + 1) − 1 As m ≥ 2, |vy| ≥ 2, |uv^{i}xy^{i}z| + 1 can not be a prime. Thus s can not be pumped. So C is not a CFL.

4. (10+10+10 Points) (i) L_{1} is context free, as there is a PDA that recognizes it.

(ii) L_{2} is context free, as there is a PDA that recognizes it.

(iii)Use the pumping lemma to show that L_{3} is not context free. We assume that L_{3} is context free and obtain a contradiction. Let p be the pumping length for L_{3} that is guaranteed to exist by the pumping lemma. Select the string s = a^{p}b^{p}c^{p}. Clearly s is a member of L_{3} and of length at least p. Pumping lemma states that s can be pumped. we show that no matter how we divide s into uvxyz, one of the three conditions of the lemma is violated. As |vxy| ≤ p, vy can not contain all three types of alphabet symble. The string uv^{2}xy^{2}z can not contain equal numbers of a’s, b’s, and c’s. Therefore it can not be a member of L_{3}. That violates the lemma and is thus a contradiction.

5. (15+15 Points) (i)(see Sipser’s book p241) The algorithm M (Recall that the empty string is handeled specially in a Chomsky normal form grammar):

On input w = w_{1} ... w_{n}:

1. If w = ϵ and S → ϵ is a rule, accept.

2. For i = 1 to n,

3. For each variable A,

4. Test whether A → w_{i} is a rule.

5. If so, place A in table(i, i).

6. For l = 2 to n,

7. For i = 1 to n − l + 1,

8. Let j = i + l − 1,

9. For k = i to j − 1,

10. For each rule A → BC,

11. If table(i, k) contains B and table(k + 1, j) contains C, put A in table(i, j).

12. If S is in table(1, n), accept. Otherwise, reject.

(ii) Let v be the number of variables in G, r be the number of rules in G. m is the length of G, n is the length of the input string. Stages 4 and 5 run in O(vn) times. Stage 6 runs at most n times. Each time stage 6 runs, stage 7 runs at most n times. Each time stage 7 runs, stages 8 and 9 run at most n times. Each time stage 9 runs, stage 10 runs r times. Thus stage 11, the inner loop of the algorithm, runs O(r × n^{3}). Summing the total shows that M executes in time O(m × n^{3}).

Use the following convention: Assume the fixed alphabet Σ contains the special symbols A, a, 0, 1 (among others), with each symbol of V encoded as a string of the form A(0 + 1)^{∗}, and each symbol of T and w encoded as a string of the form a(0+1)^{∗}. After encoding G with the fixed alphabet Σ, the definition of |G| can be taken to be the number of symbols in writing down all the rules of G plus |V ∪ T |. After encoding, each symbol in V has length O(log|V |), and each symbol in T has length O(log|T |). The length of encoded V ∪ T is O(|V | × log|V | + |T | × log|T |). As each rule of G has length O(log|V | + log|T |), writng down all the rules takes O(|R| × (log|V | + log|T |)). Thus the length of G after encoding over the fixed alphabet is: O(|V | × log|V | + |T | × log|T | + |R| × (log|V | + log|T |))