GateAI
Context-Free Grammars and PDAs

GATE CSE 2024 Set 2 · Q52

MSQ2 marksMedium

Time

Consider a context-free grammar GG with the following 3 rules. S→aS,  S→aSbS,  S→cS \rightarrow aS, \; S \rightarrow aSbS, \; S \rightarrow c Let w∈L(G)w \in L(G). Let na(w)n_a(w), nb(w)n_b(w), nc(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 that applyOne or more correct

Pick every correct option

Solution

Step-by-step verified solution

Official answer: B) na(w) > nc(w) - 2; C) nc(w) = nb(w) + 1

Context-Free Grammars and PDAs

Let k1,k2,k3k_1, k_2, k_3 denote the number of times the production rules S→aSS \rightarrow aS, S→aSbSS \rightarrow aSbS, and S→cS \rightarrow c are applied in the derivation of a terminal word w∈L(G)w \in L(G), respectively.

  1. Tracking the Non-terminal SS:

    • Initial count of S=1S = 1.

    • Rule S→aSS \rightarrow aS replaces 11 instance of SS with 11 instance of SS (ΔS=0Δ S = 0).

    • Rule S→aSbSS \rightarrow aSbS replaces 11 instance of SS with 22 instances of SS (ΔS=+1Δ S = +1).

    • Rule S→cS \rightarrow c replaces 11 instance of SS with 00 instances of SS (ΔS=−1Δ S = -1).

    Since the final string ww has no non-terminals (00 instances of SS):

    1+0⋅k1+1⋅k2−1⋅k3=0  ⟹  k3=k2+11 + 0 \cdot k_1 + 1 \cdot k_2 - 1 \cdot k_3 = 0 \implies k_3 = k_2 + 1
  2. Counting Terminals:

    • cc is only introduced by rule S→cS \rightarrow c, so nc(w)=k3n_c(w) = k_3.

    • bb is only introduced by rule S→aSbSS \rightarrow aSbS, so nb(w)=k2n_b(w) = k_2.

    • aa is introduced by both S→aSS \rightarrow aS and S→aSbSS \rightarrow aSbS, so na(w)=k1+k2n_a(w) = k_1 + k_2.

  3. Evaluating the Options:

    • Option C: nc(w)=k3=k2+1=nb(w)+1n_c(w) = k_3 = k_2 + 1 = n_b(w) + 1. Thus, (C) is TRUE.

    • Option D: nc(w)=nb(w)+1≠2⋅nb(w)n_c(w) = n_b(w) + 1 \neq 2 \cdot n_b(w) in general (e.g., for w=cw = c, nc=1,nb=0n_c=1, n_b=0). Thus, (D) is FALSE.

    • Option A: na(w)=k1+k2≥k2=nb(w)n_a(w) = k_1 + k_2 \ge k_2 = n_b(w). For w=cw = c, k1=k2=0k_1 = k_2 = 0, giving na(c)=0n_a(c) = 0 and nb(c)=0n_b(c) = 0. Since 0>00 > 0 is false, (A) is FALSE.

    • Option B: From na(w)≥nb(w)n_a(w) \ge n_b(w) and nb(w)=nc(w)−1n_b(w) = n_c(w) - 1, we have:

      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 holds for all w∈L(G)w \in L(G). So (B) is TRUE.

Therefore, the correct options are B and C.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Context-Free Grammars and PDAs previous year question is Q52 of the GATE CSE 2024 Set 2 paper. Find more GATE CSE PYQs on Context-Free Grammars and PDAs in Theory of Computation, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Context-Free Grammars and PDAs PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Context-Free Grammars and PDAs in GATE CSE

Context-Free Grammars and PDAs has 26 GATE CSE PYQs across 17 papers from 2011 to 2026. 4 of them are 2-mark MSQs like this one, and it is the only one in GATE CSE 2024 Set 2.

How GATE tests Context-Free Grammars and PDAs

More from GATE CSE 2024 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2024 Set 2 · Q52 · MSQ

Consider a context-free grammar G with the following 3 rules. S → aS, S → aSbS, S → c Let w ∈ L(G). Let na(w), nb(w), nc(w) denote the number of times a, b, c occur in w, respectively. Which of the following statements is/are TRUE?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.