Context Free Grammar · Theory of Computation
33 questions · asked in 12 of 27 years (2000–2026)
MCQ 26 · MSQ 5 · NAT 21-mark 15 · 2-mark 18
2000Questions per year2026
Questions 6–10 of 33
Let be a context-free grammar in Chomsky Normal Form with and containing 10 variable symbols including the start symbol . The string is derivable from . The number of steps (application of rules) in the derivation is _____
Answer: 179
A CNF rule has the form or .
- A rule adds 1 symbol each time. Going from 1 symbol (S) to symbols takes steps.
- Then each of the variables becomes a terminal using . That takes steps.
Total: . Here , so .
Answer: 179
- A rule adds 1 symbol each time. Going from 1 symbol (S) to symbols takes steps.
- Then each of the variables becomes a terminal using . That takes steps.
Total: . Here , so .
Answer: 179
Consider the following context-free grammar where the start symbol is and the set of terminals is .
The following is a partially-filled LL(1) parsing table.
Which one of the following options represents the CORRECT combination for the numbered cells in the parsing table?
Note: In the options, "blank" denotes that the corresponding cell is empty.
The following is a partially-filled LL(1) parsing table.
Which one of the following options represents the CORRECT combination for the numbered cells in the parsing table?
Note: In the options, "blank" denotes that the corresponding cell is empty.
Answer: (A)
Fill the LL(1) table with the help of FIRST and FOLLOW sets:
- (A is c or ) So cell (1) [S, c] = .
- So cell (2) [S, d] = .
- goes in the columns of FOLLOW(A). A comes before a and before b, so So cell (3) [A, b] = .
- In the same way, So cell (4) [B, a] = .
Answer: (1) (2) (3) (4)
- (A is c or ) So cell (1) [S, c] = .
- So cell (2) [S, d] = .
- goes in the columns of FOLLOW(A). A comes before a and before b, so So cell (3) [A, b] = .
- In the same way, So cell (4) [B, a] = .
Answer: (1) (2) (3) (4)
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?
Let . Let denote the number of times occur in , respectively. Which of the following statements is/are TRUE?
One or more options are correct.
Answer: (B), (C)
Count the symbols each rule gives:
- Each S in the end turns into one c. The rule adds one b and one extra S. The rule adds no extra S. Start with one S: is TRUE (so is FALSE, for example w = c).
- Every b comes with an a, so is TRUE.
- does not hold for w = acbc () is FALSE.
Answer: and
- Each S in the end turns into one c. The rule adds one b and one extra S. The rule adds no extra S. Start with one S: is TRUE (so is FALSE, for example w = c).
- Every b comes with an a, so is TRUE.
- does not hold for w = acbc () is FALSE.
Answer: and
Consider the following augmented grammar, which is to be parsed with a SLR parser. The set of terminals is
Let . The number of items in the set is ____
Let . The number of items in the set is ____
Answer: 9
Look at the items of that have the dot just before S. These are and . Now move the dot over S:
1.
2.
The dot is before S in item 2, so take its closure. This adds all the S-productions:
3-7.
8. (coming from )
9. (coming from )
Answer: 9
1.
2.
The dot is before S in item 2, so take its closure. This adds all the S-productions:
3-7.
8. (coming from )
9. (coming from )
Answer: 9
Consider the context-free grammar below
where and are non-terminals, and and are terminal symbols. The starting non-terminal is .
Which one of the following statements is CORRECT?
where and are non-terminals, and and are terminal symbols. The starting non-terminal is .
Which one of the following statements is CORRECT?
Answer: (B)
Look at X first: the rule puts a's on the left, and the rule puts b's on the right. The string ends with a single a or b in the middle. So .
The rule only puts more a's on the left and more b's on the right of X. So the strings stay inside , and they cover all of it (take directly). So .
(A) is wrong: "ba" is in but not in , and the empty string is not in either.
(C) is wrong: contains "ba" (take and the last symbol a), but "ba" cannot be derived, since an a can never come after a b in .
(D) is wrong: is regular, as it is given by the regular expression above.
Answer: (B)
The rule only puts more a's on the left and more b's on the right of X. So the strings stay inside , and they cover all of it (take directly). So .
(A) is wrong: "ba" is in but not in , and the empty string is not in either.
(C) is wrong: contains "ba" (take and the last symbol a), but "ba" cannot be derived, since an a can never come after a b in .
(D) is wrong: is regular, as it is given by the regular expression above.
Answer: (B)
Keep practising