Give a context-free grammar for the following language. You must specify what language is generated by each non-terminal and briefly explain why.
Binary strings that have a remainder of 2 when divided by 5 (e.g., 111, 10, 10001).
As we know, mod N problems requires N number of states sn DFA. Here, 0 is the starting state and 2 is ending state. We kept 2 as final state because we need remainder as 2. Now, the interesting part about this DFA is that it can be converted to solve following problems also :-
N mod 5 = 0 if 0 is final state
N mod 5 = 1 if 1 is final state
N mod 5 = 2 if 2 is final state
N mod 5 = 3 if 3 is final state
N mod 5 = 4 if 4 is final state
Get Answers For Free
Most questions answered within 1 hours.