GATE CS 2024 Set 2 — Question 52
MSQ+2 / -0MediumContext-Free GrammarsContext-Free LanguagesTheory of Computation
Theory of Computation → Context-Free Languages → Context-Free Grammars
Last updated
Question
Consider a context-free grammar with the following 3 rules.Let . Let , , denote the number of times occur in , respectively. Which of the following statements is/are TRUE?
A.
B.
C.
D.
Correct answer
(B) nₐ(w) n_c(w) - 2; (C) n_c(w) = n_b(w) + 1
Solution
Let be the number of times the rules , , and are applied in the derivation of a string , respectively.We track the number of non-terminals and the terminals generated:
Substituting the counts: . This matches our derived constraint exactly. Thus, this statement is TRUE.(B)
Substitute :Since and , this becomes:Since is a count of rule applications, . Therefore, is always true. Thus, this statement is TRUE.(A) This is not always true. For example, the derivation has . Thus, this statement is FALSE.(D) This is not always true. For example, has , so . Thus, this statement is FALSE.Correct options are (B) and (C).
1.Start: We begin with 1 .
2.Rule 1 (): Replaces 1 with 1 . Net change in is . Adds 1 .
3.Rule 2 (): Replaces 1 with 2 's. Net change in is . Adds 1 and 1 .
4.Rule 3 (): Replaces 1 with 0 's. Net change in is . Adds 1 .
For a derivation to terminate and produce a string , the final number of 's must be 0. Starting from 1 , the total change must be .The number of terminals in are:- (since rules 1 and 2 produce 'a')
- (only rule 2 produces 'b')
- (only rule 3 produces 'c')
Substituting the counts: . This matches our derived constraint exactly. Thus, this statement is TRUE.(B)
Substitute :Since and , this becomes:Since is a count of rule applications, . Therefore, is always true. Thus, this statement is TRUE.(A) This is not always true. For example, the derivation has . Thus, this statement is FALSE.(D) This is not always true. For example, has , so . Thus, this statement is FALSE.Correct options are (B) and (C).
More questions on Context-Free Languages
2024 Set 2 Q22Which one of the following regular expressions is equivalent to the language accepted by the DFA…2024 Set 1 Q23Let be two regular languages and a language which is not regular. Which of the…2024 Set 2 Q41Let be the 5-state NFA with -transitions shown in the diagram below. [figure] Which…2024 Set 1 Q50Consider the 5-state DFA accepting the language shown below. For any…2024 Set 1 Q59Let be a context-free grammar in Chomsky Normal Form with…
Practice GATE CS PYQs with adaptive difficulty
Timed practice, skill tracking, and AI explanations — free to start.
Start practicing free