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?
- A.
๐๐(๐ค) > ๐๐(๐ค)
- B.
๐๐(๐ค) > ๐๐ (๐ค) โ 2
- C.
๐๐(๐ค) = ๐๐(๐ค) + 1
- 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.