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.β¦
- A.
ππ(π€) > ππ(π€)
- B.
ππ(π€) > ππ (π€) β 2
- C.
ππ(π€) = ππ(π€) + 1
- 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.