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?

Answer: B. π‘›π‘Ž(𝑀) > 𝑛𝑐 (𝑀) βˆ’ 2; C. 𝑛𝑐(𝑀) = 𝑛𝑏(𝑀) + 1 β€” 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.…

  1. A.

    π‘›π‘Ž(𝑀) > 𝑛𝑏(𝑀)

  2. B.

    π‘›π‘Ž(𝑀) > 𝑛𝑐 (𝑀) βˆ’ 2

  3. C.

    𝑛𝑐(𝑀) = 𝑛𝑏(𝑀) + 1

  4. D.

    𝑛𝑐(𝑀) = 𝑛𝑏(𝑀) βˆ— 2

Attempted by 94 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

Loading lesson…