Skip to content
Official PYQ · 2024

GATE CS 2024 Set 2 Q42 — Parsing (LL, LR)

Explain with AI

​​​​Consider a context-free grammar G\text{G} with the following 33 rules.

S→aS,S→aSbS,S→cS \rightarrow a S, S \rightarrow a S b S , S \rightarrow c Let w∈L(G)w \in L(G). Let na(w),nb(w),nc(w)n_{a}(w), n_{b}(w), n_{c}(w) denote the number of times a,b,ca, b, c occur in ww, respectively. Which of the following statements is/are TRUE?

Select all correct options
View worked solution

Answer: B;C

We can analyze the relationship between the counts of symbols by observing how the variables and terminals are generated in the grammar GG:

  1. Relation between nc(w)n_c(w) and nb(w)n_b(w) (Option C):
    • We start with a single start symbol SS.
    • The rule S→aSS \rightarrow aS maintains the number of SS variables.
    • The rule S→aSbSS \rightarrow aSbS increases the number of SS variables by 11 and introduces exactly one bb.
    • The rule S→cS \rightarrow c replaces each SS with exactly one cc.
    Thus, the total number of SS variables generated (and subsequently replaced by cc) is always nb(w)+1n_b(w) + 1. Therefore, nc(w)=nb(w)+1n_c(w) = n_b(w) + 1 is always true. This validates Option C and disproves Option D.
  2. Relation between na(w)n_a(w) and nb(w)n_b(w) (Option B):
    • Every bb is introduced only via the rule S→aSbSS \rightarrow aSbS, which also introduces an aa.
    • The rule S→aSS \rightarrow aS introduces an aa without introducing any bb.
    Therefore, na(w)≥nb(w)n_a(w) \ge n_b(w). Substituting nb(w)=nc(w)−1n_b(w) = n_c(w) - 1, we get: na(w)≥nc(w)−1>nc(w)−2n_a(w) \ge n_c(w) - 1 > n_c(w) - 2 Thus, na(w)>nc(w)−2n_a(w) > n_c(w) - 2 is always true. This validates Option B.

Counterexample for Option A: For the string w=c∈L(G)w = c \in L(G), we have na(w)=0n_a(w) = 0 and nb(w)=0n_b(w) = 0. The inequality 0>00 > 0 is false, so Option A is incorrect.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Parsing (LL, LR) questions