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 21–25 of 33
A CFG G is given with the following productions where S is the start symbol, A is a non-terminal and a and b are terminals.
For the string "aabbaab" how many steps are required to derive the string and how many parse trees are there?
For the string "aabbaab" how many steps are required to derive the string and how many parse trees are there?
Answer: (A)
Derive the string step by step:
So the derivation takes steps.
Now count the parse trees. Every string from S has the form , where is used times and comes from A. Each use of or adds 2 symbols, so has even length. The string has length 7, so is odd. It starts with "aab", so . So and . For a given , the production of A at each step is forced by the outer pair of letters: a ... b needs and b ... a needs . So there is only one derivation tree.
Answer: (A)
So the derivation takes steps.
Now count the parse trees. Every string from S has the form , where is used times and comes from A. Each use of or adds 2 symbols, so has even length. The string has length 7, so is odd. It starts with "aab", so . So and . For a given , the production of A at each step is forced by the outer pair of letters: a ... b needs and b ... a needs . So there is only one derivation tree.
Answer: (A)
A CFG G is given with the following productions where S is the start symbol, A is a non-terminal and a and b are terminals.
Which of the following strings is generated by the grammar above?
Which of the following strings is generated by the grammar above?
Answer: (D)
First step:
Use S to A:
Use A to aAb:
Use A to bAa:
Use A to bAa again:
Use A to ε:
So, (D) is the answer.
Consider a CFG with the following productions.
S is the start symbol, A and B are non-terminals and 0 and 1 are the terminals. The language generated by this grammar is:
S is the start symbol, A and B are non-terminals and 0 and 1 are the terminals. The language generated by this grammar is:
Answer: (B)
The rule uses times and then 1. So produces .
For : use times and times, then . So produces with .
puts two such strings side by side: , where can be any number . For example, . So the language is .
The other options do not match. (A) has only the second set. (C) allows only one 1, but gives strings with two 1s such as 11. (D) contains "00", but every string of G has a 1.
Answer: (B)
For : use times and times, then . So produces with .
puts two such strings side by side: , where can be any number . For example, . So the language is .
The other options do not match. (A) has only the second set. (C) allows only one 1, but gives strings with two 1s such as 11. (D) contains "00", but every string of G has a 1.
Answer: (B)
Which of the following statements are true?
I. Every left-recursive grammar can be converted to a right-recursive grammar and vice-versa
II. All -productions can be removed from any context-free grammar by suitable transformations
III. The language generated by a context-free grammar all of whose productions are of the form x w or x wY (where, w is a string of terminals and Y is a non-terminal), is always regular
IV. The derivation trees of strings generated by a context-free grammar in Chomsky Normal Form are always binary trees
I. Every left-recursive grammar can be converted to a right-recursive grammar and vice-versa
II. All -productions can be removed from any context-free grammar by suitable transformations
III. The language generated by a context-free grammar all of whose productions are of the form x w or x wY (where, w is a string of terminals and Y is a non-terminal), is always regular
IV. The derivation trees of strings generated by a context-free grammar in Chomsky Normal Form are always binary trees
Answer: (C)
I: true. The standard algorithm removes left recursion from any grammar: first substitute to remove indirect recursion, then replace each immediate recursion by , . The language stays the same and the new grammar is right-recursive. For the reverse, (language ) becomes , , which generates the same language and is left-recursive.
II: false. If is in the language, the start symbol must keep an -production. For example, cannot be generated without one. (Only -productions of a language without can all be removed.)
III: true. Productions or , with a string of terminals, form a right-linear grammar, and a right-linear grammar generates a regular language.
IV: true. In Chomsky Normal Form each production is or . So an internal node has either two children (non-terminals) or one child (a terminal leaf). No node has more than two children, so the tree is binary.
So I, III and IV are true, and II is false.
Answer: (C)
II: false. If is in the language, the start symbol must keep an -production. For example, cannot be generated without one. (Only -productions of a language without can all be removed.)
III: true. Productions or , with a string of terminals, form a right-linear grammar, and a right-linear grammar generates a regular language.
IV: true. In Chomsky Normal Form each production is or . So an internal node has either two children (non-terminals) or one child (a terminal leaf). No node has more than two children, so the tree is binary.
So I, III and IV are true, and II is false.
Answer: (C)
In the context-free grammar below, S is the start symbol, a and b are terminals, and denotes the empty string.
The grammar generates the language
The grammar generates the language
Answer: (B)
Rule for A:
Result for A:
Given rule for S:
Put in A:
Simplify:
Language of S:
Rewrite the strings:
Final form:
Hence, option B is correct.
Keep practising