IAE Academy

GATE 2024 CS2 Q.52: solution and answer

GATE 2024 · CS2Q.52 · 2 marks · MSQ

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?

  1. (A)

  2. (B)

  3. (C)

  4. (D)

See the question in the paper

Answer and solution

ANSWER

The true statements are (B) and (C).

Official answer: B, CSource: Official answer key, GATE 2024 CS2 (IISc Bengaluru)

  1. Track how each production changes the counts. adds one and keeps the number of symbols the same. adds one and one and raises the number of symbols by 1. adds one and lowers the number of symbols by 1.

  2. A derivation starts with one and ends with none. Let be the number of uses of , the number of uses of , and the number of uses of . The number of symbols changes by , so , which gives .

  3. Only produces a , so . Only produces a , so . Option (C) is TRUE.

  4. Both and produce one each, so .

  5. (A): take , which is in . Then and , so fails. FALSE.

  6. (B): from (C), . Since , we get for every . TRUE.

  7. (D): for , but . FALSE. Since always holds, could only happen when , and it fails for anyway.

  8. Hence the TRUE statements are (B) and (C).

KEY IDEA

Count the symbols during the derivation. Each adds one , each removes one, and the derivation goes from one to none. So , and since every is paired with an , .

WATCH OUT FOR

Judging (A) by cases that have at least one and forgetting that is in the language, where . Another slip is to read as strict, or to treat (D) as true from the single case .

From the GATE 2024 CS2 paper. Every question of this paper · Download the full paper · All 9 CFG & PDA questions, with notes

More CFG & PDA questions