Skip to content

Problem Set

7.1 Regular Languages

Problem 1. Construct a DFA over Σ={0,1}\Sigma = \{0, 1\} that accepts exactly those strings whose Length is a multiple of 3. Prove your DFA is correct.

Problem 2. Let L={w{0,1}:wcontainsanevennumberof0sandendswith1}L = \{w \in \{0,1\}^* : w \mathrm{ contains} an even number of 0\mathrm{s} and \mathrm{ ends} with 1\}. Give a DFA with the minimum number of states for LL.

Problem 3. Use the Myhill-Nerode theorem to prove that L={0n12n:n0}L = \{0^n 1^{2n} : n \geq 0\} is not regular.

Problem 4. Prove or disprove: if L1L2L_1 \cdot L_2 is regular, then both L1L_1 and L2L_2 are regular.

7.2 Context-Free Languages

Problem 5. Give a CFG for L={aibjck:i+j=k}L = \{a^i b^j c^k : i + j = k\}. Prove your grammar generates Exactly this language.

Problem 6. Convert the following grammar to CNF: SaSbSεS \to aSbS \mid \varepsilon. Show all steps of the conversion.

Problem 7. Use the CFL pumping lemma to prove that L={aibjaibj:i,j1}L = \{a^i b^j a^i b^j : i, j \geq 1\} is not context-free.

Problem 8. Construct a PDA for L={anbm:n2m}L = \{a^n b^m : n \leq 2m\}. Give the formal definition Of the PDA and explain why it is correct.

7.3 Turing Machines and Decidability

Problem 9. Design a TM that decides the language L={02n:n0}L = \{0^{2^n} : n \geq 0\}. Describe the algorithm and prove it always halts.

Problem 10. Prove that the language L={M1,M2:L(M1)L(M2)}L = \{\langle M_1, M_2 \rangle : L(M_1) \cap L(M_2) \neq \emptyset\} is undecidable.

Problem 11. Use Rice”s theorem to prove that L={M:L(M)containsatleasttwostrings}L = \{\langle M \rangle : L(M) \mathrm{ contains} at least two strings\} is undecidable. Explain why Rice’s theorem applies.

Problem 12. Show that the PCP instance with α=(01,0,1)\alpha = (01, 0, 1) and β=(0,10,01)\beta = (0, 10, 01) Has a solution by finding one, or prove it has no solution.

7.4 Complexity Theory

Problem 13. Show that if P=NP\mathrm{P} = \mathrm{NP}Then NP=coNP\mathrm{NP} = \mathrm{coNP}.

Problem 14. A 3-colouring of a graph G=(V,E)G = (V, E) is a function c:V{1,2,3}c : V \to \{1, 2, 3\} Such that c(u)c(v)c(u) \neq c(v) for every edge (u,v)E(u, v) \in E. Show that 3-SAT p\leq_p 3-Colouring By describing the reduction construction.

Problem 15. Prove that CLIQUE\mathrm{CLIQUE} is self-reducible: given an oracle for CLIQUE\mathrm{CLIQUE}Describe a polynomial-time algorithm to find an actual clique of size kk (if one exists).

Problem 16. Using Savitch’s theorem, prove that NLP\mathrm{NL} \subseteq \mathrm{P}. What is the time complexity of your algorithm?

Problem 17. Define the language EXACTCLIQUE={G,k:G\mathrm{EXACT}\mathrm{-CLIQUE} = \{\langle G, k \rangle : G hasacliqueofexactlysizek}\mathrm{ has} a clique of exactly size k\}. Show that EXACTCLIQUE\mathrm{EXACT}\mathrm{-CLIQUE} is NP-complete.

Problem 18. A language LL is in DP (difference of two NP sets) if there exist L1,L2NPL_1, L_2 \in \mathrm{NP} such that L=L1L2L = L_1 \cap \overline{L_2}. Show that SATUNSAT={ϕ,ψ:ϕSATandψSAT}\mathrm{SAT}\mathrm{-UNSAT} = \{\langle \phi, \psi \rangle : \phi \in \mathrm{SAT} \mathrm{ and} \psi \notin \mathrm{SAT}\} is in DP. Is DP contained in Σ2P\Sigma_2^P? Justify.

7.5 Comprehensive

Problem 19. Consider the language L={w#w:w{0,1}}L = \{w \# w : w \in \{0,1\}^*\}. (a) Prove LL is not regular using the pumping lemma. (b) Give a CFG for LL and prove it is correct. (c) Is LL decidable? Justify.

Problem 20. For each of the following languages, state the smallest complexity class (from Regular\mathrm{Regular}, \mathrm{CFL, Decidable\mathrm{Decidable}, \mathrm{NP \mathrm{PSPACE, EXPTIME\mathrm{EXPTIME}Or “undecidable”) that is known to contain it. Justify each answer briefly.

(a) {0n1n0n:n0}\{0^n 1^n 0^n : n \geq 0\} (b) {G:GhasaHamiltoniancycle}\{\langle G \rangle : G \mathrm{ has} a Hamiltonian cycle\} (c) {G,k:Ghasavertexcoverofsizek}\{\langle G, k \rangle : G \mathrm{ has} a vertex cover of size \leq k\} (d) {M:Mrunsforatmost100stepsonε}\{\langle M \rangle : M \mathrm{ runs} for at most 100 \mathrm{ steps} on \varepsilon\} (e) {ϕ:ϕisatruequantifiedBooleanformula}\{\langle \phi \rangle : \phi \mathrm{ is} a true quantified Boolean formula\}

7.6 Selected Solutions and Hints

Problem 1. States q0,q1,q2q_0, q_1, q_2 with transitions δ(qi,a)=q(i+1)mod3\delta(q_i, a) = q_{(i+1) \bmod 3} for All a{0,1}a \in \{0, 1\}. Accept state: q0q_0. Proof by induction on the number of symbols read.

Problem 3. The strings 01,02,03,0^1, 0^2, 0^3, \ldots are pairwise distinguishable: for i<ji \lt j The suffix 12i1^{2i} distinguishes 0i0^i from 0j0^j since 0i12iL0^i 1^{2i} \in L but 0j12iL0^j 1^{2i} \notin L (because 2i2j2i \neq 2j).

Problem 4. Dis…/1-number-and-algebra/3_proof-and-logic: let L1={0n1n:n0}L_1 = \{0^n 1^n : n \geq 0\} (not regular) and L2=L_2 = \emptyset (regular). Then L1L2=L_1 \cdot L_2 = \emptyset is regular, but L1L_1 is not.

Problem 7. Let w=apbpapbpw = a^p b^p a^p b^p with pumping length pp. Since vxyp|vxy| \leq pThe Substring vxyvxy cannot span all four blocks. Case analysis shows that pumping any valid Decomposition produces a string not in LL.

Problem 10. Reduce from ETME_{\mathrm{TM}}. Given M\langle M \rangleConstruct two TMs M1M_1 (accepts ε\varepsilon only) and M2M_2 (accepts what MM accepts). Then L(M1)L(M2)L(M_1) \cap L(M_2) \neq \emptyset iff MM accepts ε\varepsilon iff METM\langle M \rangle \notin E_{\mathrm{TM}} (after adjusting for the specific reduction).

Problem 13. If P=NP\mathrm{P} = \mathrm{NP}Then for any LNPL \in \mathrm{NP}We have LPL \in \mathrm{P}. Since P\mathrm{P} is closed under complement, LPNP\overline{L} \in \mathrm{P} \subseteq \mathrm{NP}. So LNP\overline{L} \in \mathrm{NP} for every LNPL \in \mathrm{NP}, meaning NPcoNP\mathrm{NP} \subseteq \mathrm{coNP}. By symmetry, coNPNP\mathrm{coNP} \subseteq \mathrm{NP}.

Problem 19. (a) Let w=0p1p#0p1pLw = 0^p 1^p \# 0^p 1^p \in L. Since xyp|xy| \leq p, yy is in the first 0p0^p block. Pumping down gives 0pk1p#0p1pL0^{p-k}1^p\#0^p1^p \notin L. (b) S0S01S1S#SεS \to 0S0 \mid 1S1 \mid S\#S \mid \varepsilon (generate matched pairs on both sides of #\#). (c) Yes — a TM can check the #\# symbol and verify both halves are reverses of each other.

Problem 20. (a) Decidable but not CFL (pumping lemma for CFLs). (b) NP-complete (Hamiltonian cycle is NP-complete). (c) NP-complete (vertex cover is NP-complete). (d) Decidable (in fact, in P — simulate for 100 steps). (e) PSPACE-complete (TQBF is PSPACE-complete).

Common Pitfalls

  • Confusing regular and context-free languages. Regular: recognised by finite automata (no memory). Context-free: recognised by pushdown automata (stack memory). Fix: {anbn:n0}\{a^n b^n : n \geq 0\} is context-free but not regular. {anbncn}\{a^n b^n c^n\} is neither.
  • Wrong halting problem understanding. The halting problem is undecidable — no algorithm can determine for all programs whether they halt. Fix: This is a fundamental limitation; specific cases may be decidable, but the general problem is not.
  • Confusing P and NP. P: problems solvable in polynomial time (deterministic). NP: solutions verifiable in polynomial time. P \subseteq NP; P == NP is unknown. Fix: NP-complete: hardest problems in NP; if any NP-complete problem is in P, then P == NP.

Worked Examples

Example 1: DFA construction

Problem. Construct a DFA that accepts binary strings ending in “01”.

Solution. States: q0q_0 (start), q1q_1 (last symbol was 0), q2q_2 (accept, ends in 01), q3q_3 (dead state). Transitions: q0q_0—0—>q1q_1, q0q_0—1—>q3q_3; q1q_1—0—>q1q_1, q1q_1—1—>q2q_2; q2q_2—0—>q1q_1, q2q_2—1—>q3q_3; q3q_3—0/1—>q3q_3.

\blacksquare

Example 2: Pumping lemma

Problem. Prove that L={anbn:n0}L = \{a^n b^n : n \geq 0\} is not regular.

Solution. Suppose LL is regular with pumping length pp. Choose s=apbps = a^p b^p. By the pumping lemma, s=xyzs = xyz with xyp|xy| \leq p, y1|y| \geq 1, xyizLxy^iz \in L for all i0i \geq 0. Since xyp|xy| \leq p, y=aky = a^k for some k1k \geq 1. Then xy0z=apkbpLxy^0z = a^{p-k}b^p \notin L (since pkpp - k \neq p). Contradiction.

\blacksquare

Summary

  • Chomsky hierarchy: regular \subset context-free \subset context-sensitive \subset recursively enumerable.
  • Regular languages: DFAs, NFAs, regular expressions; closed under union, concatenation, Kleene star.
  • Context-free languages: CFGs, pushdown automata; pumping lemma for non-regular languages.
  • Computability: halting problem is undecidable; P vs NP is open; NP-completeness.

Cross-References

TopicSiteLink
[Theory of Computation]A-LevelView
[Theory of Computation]UniversityView