Blog
Advance Theory of Computation Past Paper 2014 – MS CS 1st Term UOS (CS-5111)
University of Sargodha Advance Theory of Computation (CS-5111) paper for MS Computer Science 1st term, 2014 exam, session 2014-16 Spring (80 marks, 3 hours). The full paper is below, followed by solved answers: true/false with reasons, PDAs, DFAs, decidability proofs and the pumping lemma.
Solved answers
Q1 – True/false with reason (2 × 8)
i. The power of 2PDA is greater than 1PDA. True. A PDA with two stacks can simulate a Turing machine, so it recognizes all Turing-recognizable languages (e.g. anbncn), while a 1-stack PDA recognizes only context-free languages.
ii. L1 ∪ (L2 ∪ L3) is regular. True. Regular languages are closed under union, so L2 ∪ L3 is regular and its union with L1 is regular.
iii. D ∪ N may not be regular. False. Every NFA has an equivalent DFA, so both languages are regular and their union is regular.
iv. Every subset of a regular language is regular. False. {anbn} ⊆ a*b* (regular) but {anbn} is not regular.
v. NP is closed under union. True. If A, B ∈ NP with verifiers VA, VB, a verifier for A ∪ B accepts ⟨w, c⟩ if either verifier accepts; it still runs in polynomial time.
vi. The set of Turing-decidable languages is recursive. True (by definition): decidable languages are exactly the recursive languages – a TM halts on every input and accepts or rejects.
vii. If ATM reduces to L, then L is undecidable. True. If L were decidable, the reduction would give a decider for ATM, which is impossible.
viii. The complement of a CFL is also context-free. False. CFLs are not closed under complement; e.g. the complement of {ww} is context-free but {ww} itself is not.
Q2 (8 + 8)
a) Language: W = {⟨M, w⟩ | M is a two-tape TM that writes a non-blank symbol on its second tape when run on w}. Undecidable by reduction from ATM: given ⟨M, w⟩ build M′ that simulates M on w using only tape 1; if M accepts, M′ writes a non-blank symbol on tape 2. Then M′ writes on tape 2 ⇔ M accepts w. A decider for W would decide ATM – contradiction.
b) PDA for L = {b2iai | i > 0}: push one X for every two b’s, then pop one X for each a.
- q0 –b, ε → ε→ q1 (first b of a pair)
- q1 –b, ε → X→ q0 (second b: push X)
- q0 –a, X → ε→ q2; q2 –a, X → ε→ q2
- q2 –ε, $ → ε→ qacc (start by pushing $ on the stack; accept when it is uncovered)
q0 is entered only after an even number of b’s, so the input is accepted exactly when #b = 2·#a and i ≥ 1.
Q3 (8 + 8)
a) Let M1, M2 recognize L1, L2. Build M: on input w, run M1 and M2 alternately one step at a time (dovetailing); if either accepts, accept. If w ∈ L1 ∪ L2, one of them accepts after finitely many steps, so M accepts; otherwise M never accepts. Hence L1 ∪ L2 is Turing-recognizable. (Running them one after another would fail if M1 loops.)
b) Halting problem HALTTM = {⟨M, w⟩ | M halts on w} is undecidable. Suppose a decider H exists. Build D(⟨M⟩): run H on ⟨M, ⟨M⟩⟩; if H says “halts”, loop forever; otherwise halt. Run D on ⟨D⟩: if D halts, H said halts, so D loops; if D loops, H said loops, so D halts – contradiction. So H cannot exist.
Q4 – DFAs and regular expressions (4 × 4)
a) At least three 1s: states q0, q1, q2, q3 counting 1s (0 keeps the state, 1 moves forward, q3 loops on 0/1, q3 accepting). RE: 0*10*10*1(0+1)*.
b) Any string except 11 and 000: the DFA remembers the prefix read so far: states for ε, 0, 1, 00, 01, 10, 11, 000 and a “long” state (length ≥ 3, not 000). Every state is accepting except the ones for 11 and 000; any further symbol from 11, 000 or a length-3 prefix goes to the long accepting state, which loops on 0/1. RE: ε + 0 + 1 + 00 + 01 + 10 + 001 + 01(0+1) + 1(0+1)(0+1) + (0+1)(0+1)(0+1)(0+1)(0+1)* (all strings of length ≤ 3 except 11 and 000, plus every string of length ≥ 4).
c) Every odd position is 0: states odd (start, accept), even (accept), dead. odd –0→ even, odd –1→ dead, even –0/1→ odd. RE: (0(0+1))*(ε + 0).
d) At least two 0s and at most one 1: track (number of 0s: 0, 1, 2+) × (number of 1s: 0, 1) plus a dead state for a second 1; accepting states are (2+, 0) and (2+, 1). RE: 000* + 1000* + 0100* + 000*10* (no 1; or the single 1 before both zeros, between the first two zeros, or after at least two zeros).
Q5 (10 + 6)
a) ATM is not mapping-reducible to ETM. Suppose ATM ≤m ETM via f. Mapping reductions also give the complements: ATM ≤m ETM. But ETM is Turing-recognizable (guess a string and run M on it, dovetailing), so ATM would be Turing-recognizable. Since ATM is recognizable too, ATM would be decidable – contradiction. So no computable f exists.
b) Regular languages are closed under complement. Take a DFA M = (Q, Σ, δ, q0, F) for L (complete transition function). Build M′ = (Q, Σ, δ, q0, Q − F). M′ accepts w exactly when M ends in a non-accepting state, i.e. w ∉ L. So the complement of L is regular.
Q6 (8 + 8)
a) (Printed: A = {⟨M⟩ | M is a DFA that does not accept any string containing an odd number of 1s}.) A ⟺ L(M) ∩ Lodd = ∅, where Lodd is the regular language of strings with an odd number of 1s. Decider: build a DFA B for L(M) ∩ Lodd (product construction), run the EDFA decider on B (mark reachable states from the start; check whether any accepting state is reachable). Accept if empty. Every step halts, so A is decidable. (The same proof works for “even”.)
b) CFGs.
- More a’s than b’s: S → T a T | T a S
T → a T b T | b T a T | ε (T generates strings with equal a’s and b’s; S adds at least one extra a). - Complement of {anbn | n > 0}: S → A | B | C | ε
A → a A b | a A | a (more a’s: aibj, i > j)
B → a B b | B b | b (more b’s)
C → X b a X, X → a X | b X | ε (any string with “ba”, i.e. not of the form a*b*).
Q7 (10 + 6)
a) Regular languages are closed under DROP-OUT. Let M = (Q, Σ, δ, q0, F) be a DFA for A. Build an NFA N with two copies of the states: Q × {0, 1}. In copy 0 follow δ normally; from (q, 0) add an ε-move to (δ(q, y), 1) for every y ∈ Σ – this “skips” one symbol without reading it. In copy 1 follow δ normally. Start (q0, 0), accept states F × {1}. N accepts xz exactly when M accepts xyz for some y, so DROP-OUT(A) is regular.
b) {0n1m0n | m, n > 0} is not regular. Assume it is regular with pumping length p. Take s = 0p10p ∈ L. Any split s = xyz with |xy| ≤ p, |y| > 0 has y = 0k, k ≥ 1, inside the first block. Then xy2z = 0p+k10p has unequal outer blocks, so it is not in L – contradiction. Hence L is not regular.
