GATE 2003
107 questions
MCQ 1071-mark 107
Questions 81–85 of 107
A single tape Turing Machine M has two states q0 and q1, of which q0 is the starting state. The tape alphabet of M is {0, 1, B} and its input alphabet is {0, 1}. The symbol B is the blank symbol used to indicate end of an input string. The transition function of M is described in the following table
The table is interpreted as illustrated below. The entry (q1, 1, R) in row q0 and column 1 signifies that if M is in state q0 and reads 1 on the current tape square, then it writes 1 on the same tape square, moves its tape head one position to the right and transitions to state q1. Which of the following statements is true about M ?
The table is interpreted as illustrated below. The entry (q1, 1, R) in row q0 and column 1 signifies that if M is in state q0 and reads 1 on the current tape square, then it writes 1 on the same tape square, moves its tape head one position to the right and transitions to state q1. Which of the following statements is true about M ?
Answer: (A)
M halts only if it is in q0 and reads B. Trace any non-empty string.
Step 1: in q0 the first symbol is 0 or 1. Both entries are (q1, 1, R), so M writes 1 on it, moves right and enters q1.
In q1: on 0 it writes 1 and moves right, staying in q1 (so every 0 in the input turns into 1). On 1 it goes to q0 and moves left. On B (the cell just after the input) it writes B, goes to q0 and moves left.
So q1 always ends by moving left into q0. The cell it moves onto is an input cell, and every input cell the head has passed holds 1 by now. So q0 reads 1, writes 1, moves right and enters q1 again. The blank B is never read in q0.
Example on input 1: q0 reads 1, moves right to B in q1, goes back left to q0, reads 1 again, and repeats forever. Input 00: q0 turns the first 0 into 1 and moves right; q1 turns the second 0 into 1 and moves right to B; q1 moves left to q0 on a 1; and the loop goes on.
So M never halts on any string of . Only the empty string halts, because q0 reads B at once.
Why the others fail: includes the empty string, on which M halts, so (B) is false. Strings ending in 0 or in 1 are non-empty, so M loops on them, which makes (C) and (D) false.
Answer: (A)
Step 1: in q0 the first symbol is 0 or 1. Both entries are (q1, 1, R), so M writes 1 on it, moves right and enters q1.
In q1: on 0 it writes 1 and moves right, staying in q1 (so every 0 in the input turns into 1). On 1 it goes to q0 and moves left. On B (the cell just after the input) it writes B, goes to q0 and moves left.
So q1 always ends by moving left into q0. The cell it moves onto is an input cell, and every input cell the head has passed holds 1 by now. So q0 reads 1, writes 1, moves right and enters q1 again. The blank B is never read in q0.
Example on input 1: q0 reads 1, moves right to B in q1, goes back left to q0, reads 1 again, and repeats forever. Input 00: q0 turns the first 0 into 1 and moves right; q1 turns the second 0 into 1 and moves right to B; q1 moves left to q0 on a 1; and the loop goes on.
So M never halts on any string of . Only the empty string halts, because q0 reads B at once.
Why the others fail: includes the empty string, on which M halts, so (B) is false. Strings ending in 0 or in 1 are non-empty, so M loops on them, which makes (C) and (D) false.
Answer: (A)
Nobody knows yet if P = NP. Consider the language L defined as follows :
Which of the following statements is true ?
Which of the following statements is true ?
Answer: (A)
Correct Option: A
The language is recursive. Take the case when holds. Then equals , and this is recursive (in fact it is regular). Otherwise, we get , and this is again recursive. So whichever case is true, is recursive.
Consider two languages L1 and L2 each on the alphabet . Let be a polynomial time computable bijection such that . Further, let be also polynomial time computable. Which of the following CANNOT be true?
Answer: (C)
The condition is . Then , and both and are computable in polynomial time, so the two languages are equally hard.
(A) Possible: finite gives finite, and a finite language is in P.
(B) Possible: both can be in P, since P is inside NP.
(D) Possible: both can be recursive, since a recursive language is also recursively enumerable.
(C) Not possible. Let be decidable. On input , a Turing machine computes (it halts, as is polynomial time computable) and runs the decider of on it. It accepts if that decider accepts and rejects otherwise. This decides , so cannot be undecidable.
Answer: (C)
(A) Possible: finite gives finite, and a finite language is in P.
(B) Possible: both can be in P, since P is inside NP.
(D) Possible: both can be recursive, since a recursive language is also recursively enumerable.
(C) Not possible. Let be decidable. On input , a Turing machine computes (it halts, as is polynomial time computable) and runs the decider of on it. It accepts if that decider accepts and rejects otherwise. This decides , so cannot be undecidable.
Answer: (C)
Consider the grammar shown below
In the predictive parse table. M, of this grammar, the entries M[S',e] and M[S',$] respectively are
In the predictive parse table. M, of this grammar, the entries M[S',e] and M[S',$] respectively are
Answer: (D)
FIRST(S') = {e, }.
FOLLOW(S): in , S is followed by S', so FIRST(S') without gives e. Also is in it, as S is the start symbol.
FOLLOW(S'): S' is the last symbol of , so FOLLOW(S) FOLLOW(S'). S is the last symbol of , so FOLLOW(S') FOLLOW(S). So FOLLOW(S') = FOLLOW(S) = {e, }.
Table rule: put in M[A, t] for each t in FIRST(), and, if can be empty, for each t in FOLLOW(A).
M[S', e]: e is in FIRST(), so goes in. S' can derive and e is in FOLLOW(S'), so goes in too. This cell has two productions.
M[S', ]: only (as is in FOLLOW(S'), and eS does not start with it).
So the entries are {} and {}.
Answer: (D)
FOLLOW(S): in , S is followed by S', so FIRST(S') without gives e. Also is in it, as S is the start symbol.
FOLLOW(S'): S' is the last symbol of , so FOLLOW(S) FOLLOW(S'). S is the last symbol of , so FOLLOW(S') FOLLOW(S). So FOLLOW(S') = FOLLOW(S) = {e, }.
Table rule: put in M[A, t] for each t in FIRST(), and, if can be empty, for each t in FOLLOW(A).
M[S', e]: e is in FIRST(), so goes in. S' can derive and e is in FOLLOW(S'), so goes in too. This cell has two productions.
M[S', ]: only (as is in FOLLOW(S'), and eS does not start with it).
So the entries are {} and {}.
Answer: (D)
Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states. The relationship between n1 and n2 is
Answer: (B)
The states of an SLR parser are the sets of LR(0) items (the canonical LR(0) collection).
An LALR(1) parser is built by taking the LR(1) states and merging those that have the same core, that is the same LR(0) items. So its states are exactly the canonical LR(0) states, one for each core. LALR(1) has more precise look aheads than SLR, but the number of states is the same.
So .
Answer: (B)
An LALR(1) parser is built by taking the LR(1) states and merging those that have the same core, that is the same LR(0) items. So its states are exactly the canonical LR(0) states, one for each core. LALR(1) has more precise look aheads than SLR, but the number of states is the same.
So .
Answer: (B)