GATE 2018
65 questions
MCQ 41 · NAT 241-mark 30 · 2-mark 35
Questions 46–50 of 65
Consider the following problems. L(G) denotes the language generated by a grammar G. L(M) denotes the language accepted by a machine M.
(I) For an unrestricted grammar G and a string w, whether wL(G)
(II) Given a Turing machine M, whether L(M) is regular
(III) Given two grammars G1 and G2, whether L(G1) = L(G2)
(IV) Given an NFA N, whether there is a deterministic PDA P such that N and P accept the same language.
Which one of the following statements is correct?
(I) For an unrestricted grammar G and a string w, whether wL(G)
(II) Given a Turing machine M, whether L(M) is regular
(III) Given two grammars G1 and G2, whether L(G1) = L(G2)
(IV) Given an NFA N, whether there is a deterministic PDA P such that N and P accept the same language.
Which one of the following statements is correct?
Answer: (D)
Let us look at each statement one by one:
- I: Membership for an unrestricted grammar is the same as TM acceptance so it is undecidable.
- II: Whether L(M) is regular is a Rice theorem case so it is undecidable.
- III: Equivalence of two grammars (even CFGs) is undecidable.
- IV: The language of an NFA is regular, and every regular language has a DPDA so the answer is always yes and it is decidable.
Answer: Only I, II and III are undecidable
- I: Membership for an unrestricted grammar is the same as TM acceptance so it is undecidable.
- II: Whether L(M) is regular is a Rice theorem case so it is undecidable.
- III: Equivalence of two grammars (even CFGs) is undecidable.
- IV: The language of an NFA is regular, and every regular language has a DPDA so the answer is always yes and it is decidable.
Answer: Only I, II and III are undecidable
A lexical analyzer uses the following patterns to recognize three tokens over the alphabet {a,b,c}.
Note that 'x?' means 0 or 1 occurrence of the symbol x. Note also that the analyzer outputs the token that matches the longest possible prefix.
If the string bbaacabc is processed by the analyzer, which one of the following is the sequence of tokens it outputs?
Note that 'x?' means 0 or 1 occurrence of the symbol x. Note also that the analyzer outputs the token that matches the longest possible prefix.
If the string bbaacabc is processed by the analyzer, which one of the following is the sequence of tokens it outputs?
Answer: (D)
Use the longest-prefix rule on the string bbaacabc:
- T1 matches "bba" and T2 matches "bb". But T3 = c?(b|a)*c matches "bbaac", which is the longest. So T3
- The string left is "abc". T3 matches "abc", so T3
Answer: T3T3
- T1 matches "bba" and T2 matches "bb". But T3 = c?(b|a)*c matches "bbaac", which is the longest. So T3
- The string left is "abc". T3 matches "abc", so T3
Answer: T3T3
C onsider the following parse tree for the expression a#b$c$d#e#f, involving two binary operators $ and #.
Which one of the following is correct for the given parse tree?
Which one of the following is correct for the given parse tree?
Answer: (A)
From the tree, the expression is grouped as .
- Each sits lower in the tree than the above it, so is applied first: has higher precedence.
- is grouped as , with the left pair done first: is left associative.
- The operators nest to the right: . So is right associative.
Options (B) and (D) are wrong because they give the higher precedence, and (C) is wrong because it makes left associative.
Answer: (A)
- Each sits lower in the tree than the above it, so is applied first: has higher precedence.
- is grouped as , with the left pair done first: is left associative.
- The operators nest to the right: . So is right associative.
Options (B) and (D) are wrong because they give the higher precedence, and (C) is wrong because it makes left associative.
Answer: (A)
In a system, there are three types of resources: E, F and G. Four processes execute concurrently. At the outset, the processes have declared their maximum resource requirements using a matrix named Max as given below. For example, Max[,F] is the maximum number of instances of F that would require. The number of instances of the resources allocated to the various processes at any given state is given by a matrix named Allocation.
Consider a state of the system with the Allocation matrix as shown below, and in which 3 instances of E and 3 instances of F are the only resources available.
From the perspective of deadlock avoidance, which one of the following is true?
Consider a state of the system with the Allocation matrix as shown below, and in which 3 instances of E and 3 instances of F are the only resources available.
From the perspective of deadlock avoidance, which one of the following is true?
Answer: (A)
Need is found as Max Allocation. This gives P0 (3,3,0), P1 (1,0,2), P2 (0,3,0), P3 (3,4,1). Available is (3,3,0).
- P0 can complete first new available (4,3,1)
- Next P2 (5,3,4)
- Next P1 (6,4,6)
- Last P3 (8,4,6)
A safe sequence exists: P0, P2, P1, P3.
Answer: The system is in safe state
- P0 can complete first new available (4,3,1)
- Next P2 (5,3,4)
- Next P1 (6,4,6)
- Last P3 (8,4,6)
A safe sequence exists: P0, P2, P1, P3.
Answer: The system is in safe state
Consider the following solution to the producer-consumer synchronization problem. The shared buffer size is N. Three semaphores empty, full and mutex are defined with respective initial values of 0, N and 1. Semaphore empty denotes the number of available slots in the buffer, for the consumer to read from. Semaphore full denotes the number of available slots in the buffer, for the producer to write to. The placeholder variables, denoted by P, Q, R, and S, in the code below can be assigned either empty or full. The valid semaphore operations are: wait() and signal().
Which one of the following assignments to P, Q, R and S will yield the correct solution?
Producer: Consumer:
do{ do{
wait(P); wait(R);
wait(mutex); wait(mutex);
//Add item to buffer //Consume item from buffer
signal(mutex); signal(mutex);
signal(Q); signal(S);
}while(1); }while(1); Which one of the following assignments to P, Q, R and S will yield the correct solution?
Answer: (C)
In this question, "full" is the count of free slots, and it starts at N. "empty" is the count of filled slots, and it starts at 0.
- Producer: first wait on a free slot (P = full). Then add the item. Then signal that a filled slot exists (Q = empty).
- Consumer: first wait on a filled slot (R = empty). Then remove the item. Then signal that a free slot exists (S = full).
Answer: P: full, Q: empty, R: empty, S: full
- Producer: first wait on a free slot (P = full). Then add the item. Then signal that a filled slot exists (Q = empty).
- Consumer: first wait on a filled slot (R = empty). Then remove the item. Then signal that a free slot exists (S = full).
Answer: P: full, Q: empty, R: empty, S: full