GATE 2013
80 questions
MCQ 801-mark 38 · 2-mark 42
Questions 36–40 of 80
Which of the following statements is/are FALSE?
1. For every non-deterministic Turing machine, there exists an equivalent deterministic Turing machine.
2. Turing recognizable languages are closed under union and complementation.
3. Turing decidable languages are closed under intersection and complementation.
4. Turing recognizable languages are closed under union and intersection.
1. For every non-deterministic Turing machine, there exists an equivalent deterministic Turing machine.
2. Turing recognizable languages are closed under union and complementation.
3. Turing decidable languages are closed under intersection and complementation.
4. Turing recognizable languages are closed under union and intersection.
Answer: (C)
Go through each statement:
- 1: NTM and DTM have equal power True
- 2: RE languages are not closed under complement False
- 3: Decidable languages are closed under intersection and complement True
- 4: RE languages are closed under union and intersection True
Answer: 2 only
- 1: NTM and DTM have equal power True
- 2: RE languages are not closed under complement False
- 3: Decidable languages are closed under intersection and complement True
- 4: RE languages are closed under union and intersection True
Answer: 2 only
Which of the following is/are undecidable?
1. G is a CFG. Is L(G) = ?
2. G is a CFG. Is L(G) = ?
3. M is a Turing machine. Is L(M) regular?
4. A is a DFA and N is an NFA. Is L(A) = L(N)?
1. G is a CFG. Is L(G) = ?
2. G is a CFG. Is L(G) = ?
3. M is a Turing machine. Is L(M) regular?
4. A is a DFA and N is an NFA. Is L(A) = L(N)?
Answer: (D)
Let us go through each statement:
- 1: is for a CFG? Mark the variables that can produce a string of terminals, step by step. is empty exactly when the start symbol is not marked. Decidable.
- 2: is for a CFG? Undecidable. The strings that are not accepting computation histories of a TM form a context-free language, so TM acceptance reduces to this problem.
- 3: is L(M) regular for a TM? A non-trivial property of L(M) (some TM languages are regular, some are not), so it is undecidable by Rice's theorem.
- 4: is for a DFA A and an NFA N? Convert N to a DFA and compare the two DFAs. Decidable.
So 2 and 3 are undecidable.
Answer: (D)
- 1: is for a CFG? Mark the variables that can produce a string of terminals, step by step. is empty exactly when the start symbol is not marked. Decidable.
- 2: is for a CFG? Undecidable. The strings that are not accepting computation histories of a TM form a context-free language, so TM acceptance reduces to this problem.
- 3: is L(M) regular for a TM? A non-trivial property of L(M) (some TM languages are regular, some are not), so it is undecidable by Rice's theorem.
- 4: is for a DFA A and an NFA N? Convert N to a DFA and compare the two DFAs. Decidable.
So 2 and 3 are undecidable.
Answer: (D)
Consider the following two sets of LR(1) items of an LR(1) grammar.
Which of the following statements related to merging of the two sets in the corresponding LALR parser is/are FALSE?
1. Cannot be merged since look aheads are different.
2. Can be merged but will result in S-R conflict.
3. Can be merged but will result in R-R conflict.
4. Cannot be merged since goto on c will lead to two different sets.
Which of the following statements related to merging of the two sets in the corresponding LALR parser is/are FALSE?
1. Cannot be merged since look aheads are different.
2. Can be merged but will result in S-R conflict.
3. Can be merged but will result in R-R conflict.
4. Cannot be merged since goto on c will lead to two different sets.
Answer: (D)
The two sets have the same core. The items are the same and only the lookaheads differ, so LALR can merge them. The merged set has no reduce items. It only has shifts on c and d, so it gives no S-R conflict and no R-R conflict. GOTO on c from both sets leads to sets that are also merged.
So all four statements are false.
Answer: 1, 2, 3 and 4
So all four statements are false.
Answer: 1, 2, 3 and 4
What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon- and unit-production (i.e., of type and ) to parse a string with n tokens?
Answer: (B)
If the grammar has no productions and no unit productions, each reduce step swaps at least 2 symbols for 1 symbol. So every reduce cuts the symbol count on the stack by at least 1.
To go from n tokens to the one start symbol, the parser can make at most n 1 reduce moves.
Note: the paper's gloss lists A a, so it treats every rule as having at least 2 symbols on its right side. Strictly, a unit production is A B, a single variable.
Answer: n 1
To go from n tokens to the one start symbol, the parser can make at most n 1 reduce moves.
Note: the paper's gloss lists A a, so it treats every rule as having at least 2 symbols on its right side. Strictly, a unit production is A B, a single variable.
Answer: n 1
The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have atmost two source operands and one destination operand. Assume that all variables are dead after this code segment.
c = a + b;
d = c * a;
e = c + a;
x = c * c;
if (x > a) {
y = a * a;
}
else {
d = d * d;
e = e * e;
} What is the minimum number of registers needed in the instruction set architecture of the processor to compile this code segment without any spill to memory? Do not apply any optimization other than optimizing register allocationAnswer: (B)
Do not move any code. Look at the point just after e = c + a. Here a, c, d and e are all live. c is still needed for x = c * c. d and e are still needed in the else part. So 4 values are live at the same time.
After this, x takes the place of c, so at most 4 values stay live. So 4 registers are enough, and fewer will not work.
Answer: 4
After this, x takes the place of c, so at most 4 values stay live. So 4 registers are enough, and fewer will not work.
Answer: 4