CS701 – Theory of Computation: Midterm Important Subjective (17 Solved Q&As)
Virtual University of Pakistan • Read every solved subjective question with its model answer directly on this page. Free, no login required.
All 664 Midterm Packs · CS701 Course Page · CS701 MCQ Pack (50 MCQs)
-
Prove that A_TM = {⟨M, w⟩ | M is a Turing machine and M accepts w} is undecidable.
Topic: Computability and Decidability
Suppose, for a contradiction, that a TM H decides A_TM: on input ⟨M, w⟩, H accepts if M accepts w and H rejects if M does not accept w. Construct a new TM D that uses H as a subroutine: D = “On input ⟨M⟩, where M is a TM: 1. Run H on input ⟨M, ⟨M⟩⟩. 2. Output the opposite of what H outputs; that is, if H accepts, reject, and if H rejects, accept.” Now consider running D on its own description ⟨D⟩. Then D accepts ⟨D⟩ if and only if H rejects ⟨D, ⟨D⟩⟩, which happens if and only if D does not accept ⟨D⟩. In other words, D accepts ⟨D⟩ exactly when it does not accept ⟨D⟩ — a contradiction. Therefore H cannot exist, and A_TM is undecidable.
-
Show that the collection of Turing-recognizable languages is closed under the operations of (i) union and (ii) concatenation.
Topic: Computability and Decidability
(i) Union. For any two Turing-recognizable languages L1 and L2, let M1 and M2 be the TMs that recognize them. We construct a TM M′ that recognizes the union of L1 and L2: M′ = “On input w: 1. Run M1 and M2 alternatively on w, step by step. If either accepts, accept. If both halt and reject, then reject.” If any of M1 and M2 accepts w, then M′ will accept w, because the accepting TM will come to its accepting state after a finite number of steps. Note that if both M1 and M2 reject and either of them does so by looping, then M′ will loop. (ii) Concatenation. For any two Turing-recognizable languages L1 and L2, let M1 and M2 be the TMs that recognize them. We construct an NTM M′ that recognizes the concatenation of L1 and L2: M′ = “On input w: 1. Nondeterministically cut w into two parts w = w1w2. 2. Run M1 on w1. If it halts and rejects, reject. If it accepts, go to stage 3. 3. Run M2 on w2. If it accepts, accept. If it halts and rejects, reject.” If there is a way to cut w into two substrings such that M1 accepts the first part and M2 accepts the second part, then w belongs to the concatenation of L1 and L2 and M′ will accept w after a finite number of steps.
-
Show that A_TM is not mapping reducible to E_TM.
Topic: Computability and Decidability
Recall that A_TM is undecidable but Turing-recognizable, so its complement Ā_TM is not Turing-recognizable. Note also that Ē_TM, the complement of E_TM, is Turing-recognizable, and since we know E_TM is undecidable, E_TM itself is also not Turing-recognizable. Proof: We give a proof by contradiction. Assume that A_TM is mapping reducible to E_TM, so A_TM ≤m E_TM via some computable function f. The same function f reduces Ā_TM to Ē_TM, because w ∈ A_TM if and only if f(w) ∈ E_TM says exactly that w ∈ Ā_TM if and only if f(w) ∈ Ē_TM. Since Ē_TM is Turing-recognizable, Ā_TM would then be Turing-recognizable as well. But this is false, hence a contradiction. Therefore A_TM is not mapping reducible to E_TM.
-
Show that if A ≤m B and B is Turing-recognizable, then A is Turing-recognizable.
Topic: Computability and Decidability
Let A ≤m B and let f be the reducibility (mapping reduction) from A to B. Furthermore, since B is Turing-recognizable, there is a TM M such that L(M) = B. Consider the TM N = “On input x: 1. Compute y = f(x). 2. Run M on y. 3. If M accepts, accept.” Because f is a mapping reduction, x ∈ A if and only if f(x) ∈ B, so N accepts x exactly when M accepts f(x), that is, exactly when x ∈ A. Then it is easy to see that L(N) = A, so A is Turing-recognizable.
-
Show that if A ≤m B and B is decidable, then A is decidable.
Topic: Computability and Decidability
Let f be the mapping reduction from A to B, and let M be a Turing machine that decides B. Construct a TM N as follows: N = “On input w: 1. Compute f(w). 2. Run M on input f(w) and output whatever M outputs.” Since w ∈ A if and only if f(w) ∈ B, the machine N accepts w exactly when w ∈ A and rejects w exactly when w ∉ A. Moreover, f is computable and M always halts, so N always halts. Therefore N decides A, and A is decidable.
-
A useless state in a Turing machine is one that is never entered on any input string. Consider the problem of determining whether a Turing machine has any useless states. Formulate this problem as a language and show that it is undecidable.
Topic: Computability and Decidability
Let USELESS_TM = {⟨M⟩ | M is a TM with one or more useless states}. We show USELESS_TM is undecidable by reducing A_TM to it. Let R be a TM that decides USELESS_TM, and construct a TM S that decides A_TM as follows: S = “On input ⟨M, w⟩: 1. First we construct a TM N that simulates M on w but ensures that all of M's original states are not useless. The TM N has input alphabet {0, 1, 2}. On input 0, N goes through each of the original states of M, except for q_accept and q_reject, until all non-halting states of M have been used, and then enters state q_accept. On input 1, N enters state q_reject. On input 2, N simulates M on w; finally, N restores the original symbol to where the new symbol had been written and branches to M's start state to simulate M. If that simulation is about to enter M's accept state, it instead enters a new state r. 2. Run R (USELESS_TM) on input ⟨N⟩. If it accepts, reject. If it rejects, accept.” The only possible useless state of N is the state r, because on inputs 0 and 1, N uses all the other states. The only way for N to use state r is if M accepts w. So, testing whether N has any useless states in effect tests whether M accepts w, and S decides A_TM. Since A_TM is undecidable, USELESS_TM is undecidable. Note that the hardest part of this problem is making sure that the machine N has no “unexpected” useless states.
-
Show that the Post correspondence problem (PCP) is decidable over a unary alphabet.
Topic: The Post Correspondence Problem
The PCP over a unary alphabet is decidable. We describe a TM M that decides unary PCP. Given a unary PCP instance { [1^a1 / 1^b1], ..., [1^an / 1^bn] }, the machine is M = “On input ⟨a1, b1, ..., an, bn⟩: 1. Check if ai = bi for some i. If so, accept. 2. Check if there exist i, j such that ai > bi and aj < bj. If so, accept. Otherwise, reject.” Over a unary alphabet only the lengths of the strings matter. If some domino has ai = bi, that domino alone is a match. If one domino has more symbols on the top than on the bottom and another domino has more on the bottom than on the top, the two dominoes can be repeated suitable numbers of times so that the excess on one side exactly cancels the excess on the other side, producing a match. If neither condition holds, all dominoes lean strictly to the same side, so the top and bottom strings can never become equal and no match exists. Hence M decides the problem, and PCP over a unary alphabet is decidable.
-
Show that the modified Post correspondence problem (MPCP) is undecidable.
Topic: The Post Correspondence Problem
Assume that MPCP is decidable. Let us say we have a decider R for MPCP. Consider the following decider S for A_TM: S = “On input ⟨M, w⟩: 1. Construct P′ as described in the seven parts of the construction, so that P′ is an MPCP instance whose match must begin with the first domino and simulates an accepting computation of M on w. 2. Run R on P′. 3. If R accepts, accept. 4. If R rejects, reject.” The instance P′ has such a match if and only if M accepts w, because a match of P′ is precisely an accepting computation history of M on w written as a sequence of configurations. Then S is a decider for A_TM, which is a contradiction to the fact that A_TM is undecidable. Hence MPCP is undecidable.
-
Write the seven parts of the construction that converts a Turing machine M and an input w into an MPCP instance P′ (the construction used in the proof that PCP is undecidable).
Topic: The Post Correspondence Problem
Let M = (Q, Σ, Γ, δ, q0, q_accept, q_reject) be the Turing machine and w = w1w2...wn its input. The MPCP instance P′ is constructed in the following seven parts: Part 1: Put [ # / #q0w1w2...wn# ] in P′ as the first domino. Part 2: For every a, b ∈ Γ and q, r ∈ Q where q ≠ q_reject, if δ(q, a) = (r, b, R), put [ qa / br ] in P′. Part 3: For every a, b, c ∈ Γ and q, r ∈ Q where q ≠ q_reject, if δ(q, a) = (r, b, L), put [ cqa / rcb ] in P′. Part 4: For every a ∈ Γ, put [ a / a ] in P′. Part 5: Put [ # / # ] and [ # / ⊔# ] in P′, where ⊔ is the blank symbol. Part 6: For every a ∈ Γ, put [ a q_accept / q_accept ] and [ q_accept a / q_accept ] in P′. Part 7: Add [ q_accept## / # ] in P′, which will allow us to complete the match.
-
In the silly Post correspondence problem, SPCP, in each pair the top string has the same length as the bottom string. Show that SPCP is decidable.
Topic: The Post Correspondence Problem
The SPCP problem is decidable. It follows from the following claim: A given SPCP instance has a match if and only if there is a domino [ ti / bi ] such that ti = bi. Proof of the claim. “⇒”: If an SPCP instance has a match, it has to start with some domino. Because the length of the top and the bottom string is the same in all dominoes, the first domino in the match must surely have the same top and bottom string — for the lengths already agree domino by domino, so if the first domino had ti ≠ bi, the two sides could never become equal. “⇐”: If there is a domino with the same top and bottom string, then this single domino forms a trivial match of SPCP. Finally, checking whether there is a domino with the same top and bottom string is easily decidable by examining the SPCP instance. Therefore SPCP is decidable.
-
Prove that every t(n)-time k-tape Turing machine has an equivalent O(t²(n))-time single-tape Turing machine.
Topic: Turing Machine Variants and Time Complexity
Given a k-tape TM M, we construct a 1-tape TM N. The tape of N stores the configurations of M one after another, separated by the symbol #. N works as follows: 1. On input x, convert input x to #q0#x#...# (the start configuration of M). This configuration says that x is on the first tape, the rest of the tapes are empty, and the machine is in q0. 2. In each pass over the tape, change the current configuration to the next one. 3. If an accepting configuration is reached, accept. 4. If a rejecting configuration is reached, reject. Now, we have to estimate how much time N requires. On any input x of length n, we make the following claims: (1) M uses at most t(n) cells of its k tapes. (2) Each configuration has length at most k·t(n) = O(t(n)). (3) Each pass of N requires at most O(t(n)) steps. (4) N makes at most t(n) passes on its tape. This shows that N runs in time O(t(n) × t(n)) = O(t²(n)). Here, we use the fact that t(n) ≥ n. The machine converts x to the initial configuration, and this takes time O(n). Thus, the total time is O(n) + O(t²(n)) = O(t²(n)). Hence every t(n)-time k-tape TM has an equivalent O(t²(n))-time single-tape TM.
-
A Turing machine with stay put instead of left is similar to an ordinary Turing machine, but the transition function has the form δ : Q × Γ → Q × Γ × {R, S}. At each point the machine can move its head right or let it stay in the same position. Show that this Turing machine variant is not equivalent to the usual version. What class of languages do these machines recognize?
Topic: Turing Machine Variants and Time Complexity
Remembering what it has written on tape cells to the left of the current head position is unnecessary, because the TM is unable to return to these cells and read them. Hence the future behaviour of the machine depends only on its current state and the symbol currently under the head. Using an NFA in the simulation is convenient because it allows ε-moves, which are useful for simulating the “stay put” TM transitions. The transition function δ′ of the NFA is constructed according to δ: the NFA's states record the current TM state together with the symbol under the head; a stay-put transition of the TM becomes an ε-move of the NFA to the state recording the newly written symbol, and a right-moving transition becomes a move that consumes the next input symbol. Transitions of the TM into q_accept and q_reject become moves into the NFA's accept and reject states. Therefore every language recognized by such a machine is regular. Conversely, every regular language is recognized by such a machine, which simply simulates a DFA while moving right at each step. Hence these machines recognize exactly the class of regular languages. Because, for example, {0^n1^n | n ≥ 0} is Turing-recognizable but not regular, this variant is strictly weaker than the ordinary Turing machine, so it is not equivalent to the usual version.
-
Let G be a digraph. Show that PATH is in class P. Or: design a polynomial-time algorithm that takes as input a graph G and two vertices s and t and decides if there is a path from s to t.
Topic: Turing Machine Variants and Time Complexity
We have to give a polynomial-time algorithm for this problem, that is: “Start BFS or DFS from s, and if t appears then there is a path from s to t.” The marking algorithm is: “On input ⟨G, s, t⟩, where G is a digraph: 1. Mark s. 2. Repeat till no additional nodes are marked. 3. Scan the edges of G. If an edge (a, b) is found going from a marked node a to an unmarked node b, mark b. 4. If t is marked, accept. Otherwise, reject.” Now, we have to compute the running time. We know that the input size is at least m, where m is the number of nodes in G. Thus, we have to show that the algorithm runs in time polynomial in m. The repeat loop can at most run m times. Each time, all the edges are scanned. Since the number of edges is at most m², this step takes at most m² time. So, the total time is at most m × m² = m³. Hence, we have shown that PATH is in P.
-
Which of the following pairs of numbers are relatively prime? Show the calculations that led to your conclusions. (a) 1274 and 10505 (b) 7289 and 8029
Topic: Turing Machine Variants and Time Complexity
(a) We can use the Euclidean algorithm to find the greatest common divisor: 10505 = 1274 × 8 + 313; 1274 = 313 × 4 + 22; 313 = 22 × 14 + 5; 22 = 5 × 4 + 2; 5 = 2 × 2 + 1; 2 = 1 × 2 + 0. The greatest common divisor of 10505 and 1274 is 1. Therefore, they are relatively prime. (b) Using the Euclidean algorithm again: 8029 = 7289 × 1 + 740; 7289 = 740 × 9 + 629; 740 = 629 × 1 + 111; 629 = 111 × 5 + 74; 111 = 74 × 1 + 37; 74 = 37 × 2 + 0. The greatest common divisor of 8029 and 7289 is 37. Therefore, they are not relatively prime.
-
Let B be the set of all infinite sequences over {0, 1}. Show that B is uncountable, using a proof by diagonalization.
Topic: Countability and Diagonalization
Suppose B is countable and a correspondence f : N → B exists. We construct x in B that is not paired with anything in N. Let x = x1x2x3..., where xi = 0 if the ith bit of f(i) is 1, and xi = 1 if the ith bit of f(i) is 0. Therefore, we ensure that x is not f(i) for any i, because it differs from f(i) in the ith symbol, and a contradiction occurs. Hence no correspondence f : N → B exists, and B is uncountable.
-
Let X be the set {1, 2, 3, 4, 5} and Y be the set {6, 7, 8, 9, 10}. We describe the functions f : X → Y and g : X → Y in the following tables: n = 1, 2, 3, 4, 5 gives f(n) = 6, 7, 6, 7, 6 and g(n) = 10, 9, 8, 7, 6. Answer each part and give a reason for each negative answer: (a) Is f one-to-one? (b) Is f onto? (c) Is f a correspondence? (d) Is g one-to-one? (e) Is g onto? (f) Is g a correspondence?
Topic: Countability and Diagonalization
The two functions are given by the tables: f(1) = 6, f(2) = 7, f(3) = 6, f(4) = 7, f(5) = 6; and g(1) = 10, g(2) = 9, g(3) = 8, g(4) = 7, g(5) = 6. (a) f is not one-to-one, because f(1) = f(3) = 6. (d) g is one-to-one, because the values g(1), ..., g(5) are all different. (b) f is not onto, because there does not exist x ∈ X such that f(x) = 10. (e) g is onto, because every element of Y = {6, 7, 8, 9, 10} is the value of g at some point. (c) f is not a correspondence, because f is not one-to-one and not onto. (f) g is a correspondence, because g is one-to-one and onto.
-
Let T = {(i, j, k) | i, j, k ∈ N}. Show that T is countable.
Topic: Countability and Diagonalization
We demonstrate a one-to-one function f : T → N. Let f((i, j, k)) = 2^i 3^j 5^k. The function f is one-to-one because if a ≠ b, then f(a) ≠ f(b): by the uniqueness of prime factorization, the exponents of 2, 3, and 5 in the value 2^i 3^j 5^k are exactly i, j, and k, so different triples are mapped to different natural numbers. Therefore, T is countable.