GATE 2008
185 questions
MCQ 1851-mark 52 · 2-mark 133
Questions 126–130 of 185
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)
Consider the following languages.
Which of the following is true?
Which of the following is true?
Answer: (B)
Every string of ends with at least one (). No string of contains a . So .
is not regular. If it were, = would be regular too, but pumping the a's of gives more a's than b's, which leaves the language. So option (B) is true.
Why the others are false:
- (A): is a CFL. A PDA pushes for each , pops for each , then reads one or more s.
- (C): is a CFL, since CFLs are closed under union (add a new start state that moves by to the machine for or the one for ).
- (D): has a DPDA. It pushes two symbols for each and pops one for each .
Answer: (B)
is not regular. If it were, = would be regular too, but pumping the a's of gives more a's than b's, which leaves the language. So option (B) is true.
Why the others are false:
- (A): is a CFL. A PDA pushes for each , pops for each , then reads one or more s.
- (C): is a CFL, since CFLs are closed under union (add a new start state that moves by to the machine for or the one for ).
- (D): has a DPDA. It pushes two symbols for each and pops one for each .
Answer: (B)
Which of the following is true for the language{ |p is a prime} ?
Answer: (D)
A Turing machine can test whether a given number is prime (try all divisors from 2 to ). So it accepts , and the language is recursive, which rules out (A).
It is not regular. Suppose it were, with pumping length . Take a prime and write with . Then has length , which is composite because and . So the pumped string is not in the language.
It is not context-free either. Every context-free language over a one-letter alphabet is regular (Parikh's theorem). Since this language is not regular, it cannot be context-free. This rules out (B) and (C).
Answer: (D)
It is not regular. Suppose it were, with pumping length . Take a prime and write with . Then has length , which is composite because and . So the pumped string is not in the language.
It is not context-free either. Every context-free language over a one-letter alphabet is regular (Parikh's theorem). Since this language is not regular, it cannot be context-free. This rules out (B) and (C).
Answer: (D)
If L and are recursively enumerable then L is
Answer: (D)
Take an input w and run the recognizers for L and side by side. One and only one of them accepts, so the procedure always stops with the correct result L is recursive.
Answer: recursive
Answer: recursive