I'm trying to construct a DFA (binary only) that contains "11" or ends with "10".
I tried to do the following:
$q2$ and $q3$ are accepting states
State | 0 | 1 |
---|---|---|
$q0$ | $q0$ | $q1$ |
$q1$ | $q3$ | $q2$ |
$q2$ | $q3$ | $q2$ |
$q3$ | ??? | ??? |
I would first clarify exactly what the states were, then it should become clear what each input value does. The count
item is the number of characters we have previously processed (starting at zero), so we can combine states in the initial stages:
State | Explanation) | 0 | 1 |
---|---|---|---|
$q0$ | count = 0 or previous is 0 | $q0$ | $q1$ |
$q1$ | (count = 1 and previous is 1) or (previous two are 01) | $q3$ | $q2$ |
$q2$ | have encountered 11 | $q2$ | $q2$ |
$q3$ | previous two are 10 | $q0$ | $q1$ |
In other words, if you end up in state $q2$
or $q3$
, you have satisfied the DFA end conditions (either 11
was found or it ends with 10
).
Once you enter state $qq2$
, any further input is irrelevant since you've just encountered 11
. So, in that case, you simply stay in that state while "draining" the remaining digits (or you could ignore any future digits and just "exit" the DFA).
If you find yourself in state $qq3
, it means the previous two digits were 10
and there may or may not be more digits. In that case:
$qq0$
or $qq1$
depending on the digit.$qq2$
.A diagram to display this is shown below for those more graphically minded: