DFA construction - How to construct an automaton that contains either 0 or 1 occurrences of 010?

42 Views Asked by At

I can't seem to make it work. I think I managed to produce a solution when it's exactly one occurrence of 010 but not when it's at most one occurrence. Check out my automaton.

1

There are 1 best solutions below

1
On BEST ANSWER

I suggest the following states:

  • $A$: initial
  • $B$: have not seen $010$ yet, just saw $0$
  • $C$: have not seen $010$ yet, just saw $01$
  • $D$: have seen $010$ already
  • $E$: have seen $010$ already, just saw $0$
  • $F$: have seen $010$ already, just saw $01$

with transitions $A\stackrel 0\to B$, $A\stackrel 1\to A$, $B\stackrel 0\to B$, $B\stackrel 1\to C$, $C\stackrel 0\to E$, $C\stackrel 1\to A$, $D\stackrel 0\to E$, $D\stackrel 1\to D$, $E\stackrel 0\to E$, $E\stackrel 1\to F$, $F\stackrel 0\to $☠, $F\stackrel 1\to D$ and all states (except ☠) accepting.

(According to the comment added that $01010$ should only count one occurance of $010$, we need the transition $C\stackrel 0\to D$ instead of $C\stackrel 0\to E$)