GATE 2006
191 questions
MCQ 1911-mark 191
Questions 131–135 of 191
Consider the following statements about the context-free grammer
1. G is ambiguous
2. G produces all strings with equal number of a's and b's
3. G can be accepted by a deterministic PDA.
Which combination below expresses all the true statements about G?
1. G is ambiguous
2. G produces all strings with equal number of a's and b's
3. G can be accepted by a deterministic PDA.
Which combination below expresses all the true statements about G?
Answer: (B)
Let us check each statement in turn.
- I: The string "ab" has more than one parse tree. One uses directly. Another uses with the left S giving "ab" and the right S giving . A third uses with the left S giving and the right S giving "ab". So G is ambiguous. True
- II: G only builds concatenations of "ab" and "ba". So "aabb", which has equal counts, cannot be made. False
- III: is a regular language, so a DPDA accepts it. True
Answer: (B)
- I: The string "ab" has more than one parse tree. One uses directly. Another uses with the left S giving "ab" and the right S giving . A third uses with the left S giving and the right S giving "ab". So G is ambiguous. True
- II: G only builds concatenations of "ab" and "ba". So "aabb", which has equal counts, cannot be made. False
- III: is a regular language, so a DPDA accepts it. True
Answer: (B)
Consider the pushdown automaton (PDA) below which runs over the input alphabet (a, b, c). It has the stack alphabet where is the bottom-of-stack marker. The set of states of the PDA is (s, t, u, f} where s is the start state and f is the final state. The PDA accepts by final state. The transitions of the PDA given below are depicted in a standard manner. For example, the transition means that if the PDA is in state s and the symbol on the top of the stack is X, then it can read b from the input and move to state t after popping the top of stack and pushing the symbols and X (in that order) on the stack.
The language accepted by the PDA is
The language accepted by the PDA is
Answer: (C)
Follow the stack and count the symbols .
In state s, each adds two : and both add a net two. The first moves s to t and pops one . Each later , in t, pops one . So the b's come after the a's. The first moves t to u and pops one , and each later , in u, pops one . So the c's come after the b's. The input has the form .
For a non-empty string, the PDA reaches only from state u with on top, that is, when every has been popped. It pushed X's and popped , so . The X's from the a's can be used by any mix of b's and c's. It is not one a for one b and one a for one c.
Check with : . The stack gets four X's, the b pops one, and the three c's pop the other three, so the string is accepted and . Here and , so it is not in A (), B () or D ().
Answer: (C)
In state s, each adds two : and both add a net two. The first moves s to t and pops one . Each later , in t, pops one . So the b's come after the a's. The first moves t to u and pops one , and each later , in u, pops one . So the c's come after the b's. The input has the form .
For a non-empty string, the PDA reaches only from state u with on top, that is, when every has been popped. It pushed X's and popped , so . The X's from the a's can be used by any mix of b's and c's. It is not one a for one b and one a for one c.
Check with : . The stack gets four X's, the b pops one, and the three c's pop the other three, so the string is accepted and . Here and , so it is not in A (), B () or D ().
Answer: (C)
Which of the following languages is accepted by a non-deterministic pushdown automaton (PDA) but NOT by a deterministic PDA?
Answer: (B)
B can be accepted by an NPDA. The NPDA guesses which condition fails. Branch 1 checks : push the a's, pop one a for each b, and accept if a's are left over or b's run out of a's. Branch 2 checks : skip the a's, push the b's, pop one b for each c, and accept if b's are left over or c's are extra. The state keeps the order a, b, c. A DPDA cannot guess, so it cannot do both comparisons on the same input.
B cannot be accepted by a DPDA. Suppose a DPDA accepts the language L of B. The class of deterministic CFLs is closed under complement, so the complement of L is also a DCFL. Intersecting a DCFL with a regular language gives a CFL. Take the regular language . A string of this form is outside L exactly when and . So would be a CFL. It is not (pumping lemma for CFLs). So no DPDA accepts L.
The other options:
A: is not context-free, so no PDA of any kind accepts it.
C: a DPDA pushes a's and pops one per b.
D: is regular, so a DFA, and hence a DPDA, accepts it.
Answer: (B)
B cannot be accepted by a DPDA. Suppose a DPDA accepts the language L of B. The class of deterministic CFLs is closed under complement, so the complement of L is also a DCFL. Intersecting a DCFL with a regular language gives a CFL. Take the regular language . A string of this form is outside L exactly when and . So would be a CFL. It is not (pumping lemma for CFLs). So no DPDA accepts L.
The other options:
A: is not context-free, so no PDA of any kind accepts it.
C: a DPDA pushes a's and pops one per b.
D: is regular, so a DFA, and hence a DPDA, accepts it.
Answer: (B)
Let L be a context-free language and M a regular language. Then the language is
Answer: (D)
CFLs are closed under intersection with a regular language. Take a PDA for and a DFA for . Build a PDA whose states are pairs (state of , state of ). It runs both machines on the same input and keeps the stack of . It accepts when both are in accepting states. So is always context-free, which is (D).
The other options fail with examples, with :
- (A) and (C): take and . Then , which is a CFL but neither regular nor a deterministic CFL.
- (B): take . Then , which is regular.
Answer: (D)
The other options fail with examples, with :
- (A) and (C): take and . Then , which is a CFL but neither regular nor a deterministic CFL.
- (B): take . Then , which is regular.
Answer: (D)
Let
Which of these languages are NOT context free?
Which of these languages are NOT context free?
Answer: (D)
Rewrite each language.
- : . A grammar is , . So is context-free.
- : with , strings are with . It needs two comparisons at once: first 0s with 1s, and last 0s with the first block.
- : strings are for , which is the standard non-CFL.
Why is not context-free (pumping lemma): take and split it as with and .
- If does not touch the last block of 0s, pump down (). The first 0s and the 1s are reduced, and the last block still has zeros. For the string to stay in , the first 0s and the 1s would need to stay equal and at least , which cannot happen when something was removed.
- Otherwise lies within the 1s and the last 0s. Pump up (). Either the 1s increase and no longer equal the first 0s, or the last 0s increase beyond .
So and are not context-free, while is.
Answer: (D)
- : . A grammar is , . So is context-free.
- : with , strings are with . It needs two comparisons at once: first 0s with 1s, and last 0s with the first block.
- : strings are for , which is the standard non-CFL.
Why is not context-free (pumping lemma): take and split it as with and .
- If does not touch the last block of 0s, pump down (). The first 0s and the 1s are reduced, and the last block still has zeros. For the string to stay in , the first 0s and the 1s would need to stay equal and at least , which cannot happen when something was removed.
- Otherwise lies within the 1s and the last 0s. Pump up (). Either the 1s increase and no longer equal the first 0s, or the last 0s increase beyond .
So and are not context-free, while is.
Answer: (D)