Skip to content
GATEiit

GATE CSE 2024 Session 2 Q52: Symbol-count relations for S → aS | aSbS | c

Question

Consider a context-free grammar GG with the following 3 rules.

S→aS,S→aSbS,S→cS \to aS, \quad S \to aSbS, \quad S \to 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?

Try it: multiple select: one or more correct options

Select one or more options
Select all correct options. No negative marking, no partial marks.
Show answer and explanation

Answer: B, C (official GATE 2024 final answer key)

Concept used: Track how each rule changes the counts of aa, bb, cc and the number of pending SS.

First step: Each aSbSaSbS adds one aa, one bb and one extra SS; each SS finally becomes one cc. Check (A) on w=cw = c.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2024 Session 2 CS question paper and final answer key, organised by IISc Bangalore. Question paper · Answer key