Time: 3 hours. Aids: One double-sided A4 handwritten cheatsheet. No calculator.
Assume P ≠ NP and NP ≠ EXP. Karp reductions denoted ≤P. Mapping reductions denoted ≤m. 0 ∈ ℕ.
Irrelevant information may cost points. Use scrap paper first.
| Question | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Total |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Points | 5 | 3 | 2 | 3 | 5 | 4 | 7 | 3 | 7 | 6 | 45 |
Consider DFA D = (Q, {a, b}, δ, q0, F) with states q0 (start), q1, q2 and transition function:
| δ | a | b |
|---|---|---|
| q0 (start) | q1 | q0 |
| q1 | q2 | q0 |
| q2 | q2 | q2 |
The accept states are F = {q0}.
(a) (1 pt) Describe L(D) in plain English.
(b) (4 pts) Consider DFA D′ = ({p0, p1}, {a, b}, δ′, p0, {p0}) with:
| δ′ | a | b |
|---|---|---|
| p0 (start, accept) | p1 | p0 |
| p1 | p0 | p1 |
Construct DFA D′′ such that L(D′′) = L(D) ∩ L(D′) using the product construction. Leave out unreachable states.
(a) L(D) = the set of all strings over {a, b} that do not contain "aa" as a substring.
Reasoning: q0 is the only accept state. Reading one ‘a’ goes to q1 (not accepting — need to “return” via b). Reading two consecutive a’s goes to q2, which is a trap (all transitions go to q2, never accepting). So D accepts iff the input never has two a’s in a row.
(b) L(D′) = strings with an even number of a’s (p0 counts even, p1 counts odd; b’s don’t change state).
Product construction D′′ = (Q′′, {a, b}, δ′′, (q0, p0), F′′) where F′′ = F × F′ = {(q0, p0)}.
Starting from (q0, p0), explore reachable states:
| State | a | b | Accept? |
|---|---|---|---|
| (q0, p0) | (q1, p1) | (q0, p0) | Yes |
| (q1, p1) | (q2, p0) | (q0, p1) | No |
| (q2, p0) | (q2, p1) | (q2, p0) | No |
| (q0, p1) | (q1, p0) | (q0, p1) | No |
| (q2, p1) | (q2, p0) | (q2, p1) | No |
| (q1, p0) | (q2, p1) | (q0, p0) | No |
6 reachable states. L(D′′) = strings with no “aa” AND an even number of a’s.
Consider NFA N = ({q0, q1, q2}, {0, 1}, δ, q0, {q2}) with transition function:
| δ | 0 | 1 |
|---|---|---|
| q0 (start) | {q0, q1} | {q0} |
| q1 | ∅ | {q2} |
| q2 (accept) | ∅ | ∅ |
Apply the subset construction to obtain a DFA D with L(D) = L(N). Leave out unreachable states.
Start state: {q0}. Build all reachable subsets:
| DFA State | 0 | 1 | Accept? |
|---|---|---|---|
| {q0} | {q0, q1} | {q0} | No |
| {q0, q1} | {q0, q1} | {q0, q2} | No |
| {q0, q2} | {q0, q1} | {q0} | Yes |
3 reachable states. A DFA state is accepting if it contains q2.
L(N) = strings over {0, 1} that contain the substring “01” — reading a 0 “loads” q1, and then a 1 reaches q2.
Give a regular expression R such that:
L(R) = { w ∈ {a, b}* | w contains at least one ‘a’ and ends with ‘b’ }
We need: (1) at least one ‘a’ somewhere, and (2) the last character is ‘b’.
Strategy: get to the first ‘a’ (skip b’s), then anything, then end with ‘b’.
Equivalent shorter forms: b*a(a | b)*b. The first (a | b)* also works — it already subsumes b*.
Let L = { anbn | n ≥ 0 } over Σ = {a, b}.
A student begins the following proof:
“Suppose L is regular. Let p be the pumping length guaranteed by the pumping lemma. Choose w = apbp. Then |w| = 2p ≥ p. By the pumping lemma, w = xyz with |xy| ≤ p and |y| ≥ 1.”
Is it possible to complete this proof to show L is not regular? If so, finish it.
Yes, the proof can be completed.
Since |xy| ≤ p and w starts with ap, the prefix xy lies entirely within the a-block. So y = ak for some k ≥ 1.
Pump with i = 2:
xy2z = ap+kbp
Since k ≥ 1, we have p + k > p, so the number of a’s exceeds the number of b’s.
Therefore xy2z ∉ L, contradicting the pumping lemma.
Consider the context-free grammar G = ({S, X}, {a, b}, R, S) with rules:
S → XX
X → aXb | ε
(a) (2 pts) Prove that G is ambiguous.
(b) (3 pts) Give a PDA P with at most 5 states such that L(P) = { anbm | n ≥ 0, m ≥ 1 }. Give your answer as a transition diagram with transitions in the format “input, pop → push”.
(a) We show that w = “ab” has two distinct leftmost derivations.
Derivation 1:
S ⇒ XX ⇒ aXbX ⇒ abX ⇒ ab
(Expand left X → aXb, then X → ε, then right X → ε.)
Derivation 2:
S ⇒ XX ⇒ X ⇒ aXb ⇒ ab
(Expand left X → ε, then remaining X → aXb, then X → ε.)
Two different leftmost derivations for “ab”, so G is ambiguous. □
(b) PDA for L = { anbm | n ≥ 0, m ≥ 1 }:
3 states suffice: q0 (start), q1 (reading b’s), qacc (accept).
Transitions:
Since we don’t need to match counts, the stack is not used for counting. We only need to ensure at least one b is read, which the state structure handles.
Consider TM M = (Q, {a, b}, {a, b, ⊔}, δ, q0, qacc, qrej) with transition function:
| State | Read | Write | Move | Next |
|---|---|---|---|---|
| q0 | a | a | R | q1 |
| q0 | b | b | R | qrej |
| q0 | ⊔ | ⊔ | R | qrej |
| q1 | a | a | R | q1 |
| q1 | b | b | R | qacc |
| q1 | ⊔ | ⊔ | R | qrej |
(a) (2 pts) Give a word w of length 3 such that w ∈ L(M). Show the full sequence of configurations.
(b) (2 pts) Is L(M) decidable? Justify your answer.
(a) w = “aab”.
Configurations (underlined = head position):
q0 aab
⊢ a q1 ab
⊢ aa q1 b
⊢ aab qacc
M accepts “aab”. ✓
(b) Yes, L(M) is decidable.
L(M) = { anb | n ≥ 1 } — strings of one or more a’s followed by exactly one b.
Two arguments:
Consider the language:
Lε = { 〈M〉 | M is a TM and ε ∈ L(M) }
(a) (2 pts) Prove that Lε is Turing-recognizable.
(b) (4 pts) Prove that Lε is undecidable. Hint: reduce from ATM.
(c) (1 pt) Prove that Lε is not co-Turing-recognizable.
(a) Lε is Turing-recognizable.
Build TM R = “On input 〈M〉:
If 〈M〉 ∈ Lε, then M accepts ε, so R accepts. If M does not accept ε (rejects or loops), R either rejects or loops — which is fine for a recognizer. So R recognizes Lε. □
(b) Lε is undecidable.
Reduction: ATM ≤m Lε.
Assume for contradiction that some TM D decides Lε. Build TM S that decides ATM:
S = “On input 〈M, w〉:
Correctness:
S decides ATM. But ATM is undecidable. Contradiction. □
(c) Lε is not co-Turing-recognizable.
From (a), Lε is TR. From (b), Lε is undecidable.
If Lε were also co-TR, then Lε would be both TR and co-TR, which implies Lε is decidable (a language is decidable iff both it and its complement are recognizable). But (b) shows Lε is undecidable. Contradiction.
Consider the language:
LNE = { 〈M〉 | M is a TM and L(M) ≠ ∅ }
Consider the following mapping reduction from ATM to LNE, computed by TM F:
F = “On input 〈M, w〉:
(a) (1 pt) Fill in the body of M′ so that the reduction is correct. Specifically: what should M′ do, and what is L(M′) in each case?
(b) (2 pts) What does this reduction prove about LNE? State what it shows about decidability, Turing-recognizability, and co-Turing-recognizability.
(a) M′ = “On input x:
Two cases:
So 〈M, w〉 ∈ ATM ⇔ F(〈M, w〉) ∈ LNE. The reduction is correct.
(b) The reduction ATM ≤m LNE proves:
Consider the following problem:
TEAM FORMATION
Instance: A set of players P, a set of required skills K, a function skill : P → 2K mapping each player to their set of skills, and an integer t.
Question: Is there a subset T ⊆ P with |T| ≤ t such that ∪p ∈ T skill(p) = K?
(a) (2 pts) Prove that TEAM FORMATION ∈ NP.
(b) (1 pt) To prove NP-hardness, we reduce from VERTEX COVER. Give a yes-instance of VERTEX COVER with |V| = 4, |E| = 3, and k = 2.
(c) (2 pts) Consider the following reduction from VERTEX COVER to TEAM FORMATION. Given instance (G = (V, E), k):
Apply this reduction to your VERTEX COVER instance from (b).
(d) (1 pt) Is the resulting instance a yes-instance of TEAM FORMATION? Explain.
(e) (1 pt) The reduction has a flaw. Identify it and explain how to fix it.
(a) TEAM FORMATION ∈ NP.
Certificate: a subset T ⊆ P.
Verifier:
All steps polynomial in input size. □
(b) VERTEX COVER yes-instance.
V = {v1, v2, v3, v4}, E = {e1={v1,v2}, e2={v2,v3}, e3={v3,v4}}, k = 2.
Cover: {v2, v3} — v2 covers e1, e2 and v3 covers e2, e3. All edges covered. ✓
(c) Apply the reduction.
(d) Yes-instance?
T = {v2, v3}, |T| = 2 ≤ 2 = t. skill(v2) ∪ skill(v3) = {e1,e2} ∪ {e2,e3} = {e1,e2,e3} = K. ✓
Yes, it is a yes-instance of TEAM FORMATION.
(e) The flaw.
The reduction sets t = |V| − k, but it should be t = k. VERTEX COVER asks for a cover of size ≤ k, and the reduction maps vertices to players and edges to skills. A vertex cover of size k corresponds to a team of size k that covers all edges/skills. Using |V| − k inverts the bound.
Counterexample: Take the same graph with k = 1. The VC instance is a no-instance (can’t cover 3 edges with 1 vertex). But the reduction gives t = 4 − 1 = 3, and T = {v1, v2, v3} covers all edges — so TEAM FORMATION says yes. The reduction maps No → Yes, which is incorrect.
For each claim, state whether it is True or False and give a proof or counterexample.
(a) (1 pt) Every NFA can be converted to a DFA with at most the same number of states.
(b) (2 pts) If L is decidable, then L is Turing-recognizable.
(c) (1 pt) The language { anbn | n ≥ 0 } is regular.
(d) (2 pts) If A ≤m B and A is undecidable, then B is not Turing-recognizable.
(a) FALSE.
Counterexample: The language “the n-th symbol from the end is ‘a’” over {a, b} can be recognized by an NFA with n + 1 states (guess the position), but any equivalent DFA requires at least 2n states (subset construction can produce exponentially many reachable states).
More concretely: an NFA for “second-to-last symbol is ‘a’” needs 3 states; the minimal DFA needs 4 states.
(b) TRUE.
Proof: Every decider is also a recognizer. A decider for L halts on all inputs, accepting if w ∈ L and rejecting if w ∉ L. The accept behavior already satisfies the definition of a recognizer (accepts exactly the strings in L). Since decidable means “there exists a decider,” and every decider is a recognizer, decidable ⊆ Turing-recognizable. □
(c) FALSE.
Proof by pumping lemma: Suppose L = { anbn | n ≥ 0 } is regular. Let p be the pumping length. Take w = apbp ∈ L. Then w = xyz with |xy| ≤ p, |y| ≥ 1, so y = ak (k ≥ 1). Pumping: xy2z = ap+kbp ∉ L since p + k ≠ p. Contradiction. □
(d) FALSE.
Counterexample: ATM ≤m ATM via the identity function (f(x) = x). ATM is undecidable, but ATM is Turing-recognizable.
The reduction A ≤m B with A undecidable proves that B is undecidable, not that B is unrecognizable. Undecidable and not-TR are different properties.
| Question | Topic | Max | Your Score |
|---|---|---|---|
| Q1a | DFA — identify language | 1 | |
| Q1b | DFA — product construction | 4 | |
| Q2 | Subset construction | 3 | |
| Q3 | Regular expression | 2 | |
| Q4 | Pumping lemma | 3 | |
| Q5a | CFG ambiguity | 2 | |
| Q5b | PDA construction | 3 | |
| Q6a | TM configurations | 2 | |
| Q6b | Decidability of L(M) | 2 | |
| Q7a | Prove TR | 2 | |
| Q7b | Prove undecidable | 4 | |
| Q7c | Prove not co-TR | 1 | |
| Q8a | Fill in M′ | 1 | |
| Q8b | What does it prove | 2 | |
| Q9a | Prove NP | 2 | |
| Q9b | VC instance | 1 | |
| Q9c | Apply reduction | 2 | |
| Q9d | Check yes/no | 1 | |
| Q9e | Find & fix flaw | 1 | |
| Q10a | NFA → DFA states | 1 | |
| Q10b | Decidable ⇒ TR | 2 | |
| Q10c | anbn regular? | 1 | |
| Q10d | Reduction ⇒ not TR? | 2 | |
| Total | 45 | ||