Consider a context-free grammar ๐บ with the following 3 rules. ๐‘† โ†’ ๐‘Ž๐‘†, ๐‘† โ†’โ€ฆ

2024

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.

    ๐‘›๐‘Ž(๐‘ค) > ๐‘›๐‘ (๐‘ค) โˆ’ 2

  3. C.

    ๐‘›๐‘(๐‘ค) = ๐‘›๐‘(๐‘ค) + 1

  4. D.

    ๐‘›๐‘(๐‘ค) = ๐‘›๐‘(๐‘ค) โˆ— 2

Attempted by 88 students.

Show answer & explanation

Correct answer: B, C

Key insight: count how many times each production is used.

  • Let k be the number of times the rule aSbS is applied. Each such use contributes one b, so n_b = k. Each use of aSbS also increases the number of S nonterminals by 1; starting from one S there are k+1 final S's that must each produce a c, so n_c = k + 1.

  • Let x be the number of times the rule aS is applied. Each aS adds one a without changing the number of S's, so n_a = x + k.

  • From these counts we get n_c = n_b + 1, so the statement n_c(w) = n_b(w) + 1 holds for every w.

  • Also n_a = x + k. Plugging into n_a(w) > n_c(w) โˆ’ 2 gives x + k > (k + 1) โˆ’ 2 โ‡’ x > โˆ’1, which is always true since x โ‰ฅ 0. Hence n_a(w) > n_c(w) โˆ’ 2 holds for every w.

  • The statement n_a(w) > n_b(w) need not hold: n_a โˆ’ n_b = x โ‰ฅ 0, so equality can occur (for example w = c or w = acbc). The statement n_c(w) = 2ยทn_b(w) is also not generally true (it would force k + 1 = 2k, i.e. k = 1 only).

A video solution is available for this question โ€” log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir