Context Free Grammar · Theory of Computation
33 questions · asked in 12 of 27 years (2000–2026)
MCQ 26 · MSQ 5 · NAT 21-mark 15 · 2-mark 18
2000Questions per year2026
Questions 26–30 of 33
In the context-free grammar below, S is the start symbol, a and b are terminals, and denotes the empty string
Which of the following strings is NOT generated by the grammar?
Which of the following strings is NOT generated by the grammar?
Answer: (B)
Each of the rules and puts the same letter on both ends. The centre is a, b or . So is the set of palindromes over .
Check each option:
(A) aaaa: . Palindrome, generated.
(C) abba: . Palindrome, generated.
(D) babaaabab: . Palindrome, generated.
(B) baba starts with b but ends with a, so it is not a palindrome and cannot be generated.
Answer: (B)
Check each option:
(A) aaaa: . Palindrome, generated.
(C) abba: . Palindrome, generated.
(D) babaaabab: . Palindrome, generated.
(B) baba starts with b but ends with a, so it is not a palindrome and cannot be generated.
Answer: (B)
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)
Which one of the following statements is FALSE?
Answer: (C)
(A) True: there are inherently ambiguous context-free languages, for which every context-free grammar is ambiguous.
(B) True: this is what unambiguous means; each string generated has exactly one parse tree.
(C) False: a non-deterministic PDA accepts more languages than a deterministic one. For example, is accepted by an NPDA but by no DPDA.
(D) True: a finite language is always regular.
Answer: (C)
(B) True: this is what unambiguous means; each string generated has exactly one parse tree.
(C) False: a non-deterministic PDA accepts more languages than a deterministic one. For example, is accepted by an NPDA but by no DPDA.
(D) True: a finite language is always regular.
Answer: (C)
Which of the following grammar rules violate the requirements of an operator grammar? P, Q, R are nonterminals, and r,s,t are terminals.
Answer: (B)
An operator grammar cannot have:
(i) has two adjacent non-terminals, so it violates the rule.
(ii) has the terminal s between Q and R, so it is allowed.
(iii) is an production, so it violates the rule.
(iv) has a terminal between Q and R and ends with a terminal, so it is allowed.
So (i) and (iii) violate the requirements.
Answer: (B)
- An production (a nullable right side).
- Two adjacent non-terminals on the of a production.
(i) has two adjacent non-terminals, so it violates the rule.
(ii) has the terminal s between Q and R, so it is allowed.
(iii) is an production, so it violates the rule.
(iv) has a terminal between Q and R and ends with a terminal, so it is allowed.
So (i) and (iii) violate the requirements.
Answer: (B)
Consider the grammar shown below.
S C C
C cC | d
The grammar is
S C C
C cC | d
The grammar is
Answer: (A)
For : , so this rule goes in cells [S, c] and [S, d].
For C, the two rules start with different terminals: and . They do not overlap and neither rule can give , so no FOLLOW check is needed. So goes in [C, c] and goes in [C, d].
Every cell of the parsing table has at most one rule, so the grammar is LL(1).
An -free LL(1) grammar is also SLR(1), and so LALR(1) and LR(1) as well. So (B) and (D) are wrong, because they say the grammar is not SLR(1) or not LALR(1). (C) is wrong because it says the grammar is not LL(1).
Note: for a rule to be LL(1), must be empty. If contains , then must also be empty. This test checks LL(1) without building the table.
Answer: (A)
For C, the two rules start with different terminals: and . They do not overlap and neither rule can give , so no FOLLOW check is needed. So goes in [C, c] and goes in [C, d].
Every cell of the parsing table has at most one rule, so the grammar is LL(1).
An -free LL(1) grammar is also SLR(1), and so LALR(1) and LR(1) as well. So (B) and (D) are wrong, because they say the grammar is not SLR(1) or not LALR(1). (C) is wrong because it says the grammar is not LL(1).
Note: for a rule to be LL(1), must be empty. If contains , then must also be empty. This test checks LL(1) without building the table.
Answer: (A)
Keep practising