GATE Computer ScienceVery hardGATE CS (PYQ pattern)
L is the set of strings over {a, b} such that in every prefix the number of a's and the number of b's differ by at most 2. How many states does the minimal complete DFA for L have (a dead state counts)?
- A. 5
- B. 7
- C. 6
- D. 4
Correct answer: C. 6
The DFA only needs the current difference #a − #b, which stays in {−2, −1, 0, 1, 2}: 5 accepting states, all distinguishable (from difference d the string a^(3−d) is accepted only for small enough d, and so on). One more step outside the band is fatal forever, so a dead state is needed: 6.
More Compiler Design questions
- A compiler generates jumping code by backpatching (each relation gives 'if r goto ' then 'goto ', numbering from 100) for: if (!(a < b) &&…
- Compute FIRST of every non-terminal of S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε, treating ε as a member of FIRST when the…
- For S → A b B | c; A → a | ε; B → c B | ε (augmented), in how many LR(0) states is there a conflict, and how many reduce entries does the…
- For S → A B | B C; A → a A | ε; B → b B | ε; C → c C | d, which statement is FALSE?
- In S → A B; A → a | ε; B → A b | c, FOLLOW(A) does not contain . Which of these productions, each added to the grammar on its own, put…
- For S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε (augmented), in how many states is there a conflict in the SLR(1) table, and in how…