Finite Automata is known to finite state machine which works with transition from one state to another on every input alphabet, as per the defined rules.

In this article, strings that have number of zeros divisible by 3 are acceptable otherwise not acceptable. on the input alphabet ‘0’ and 1′.

- Determine initial state.
- Transition occurs on every input alphabets.
- Determine weather the self loop should apply or not.
- Mark final state.

**Designing DFA step by step :**

**Step-1:**

Make initial state “A”then it is the possibility that there would not be any ‘0’ but have only ‘1’ in the string which is acceptable because 0 is divisible by 3.So in this case nay number of 1’s can be present here and for this put self loop of ‘1’ on initial state “A”.

**Step-2:**

Create transition of input alphabet ‘0’ from state “A” to state “B”.

**Step-3:**

After one ‘0’ any number of 1’s can be present i.e, no ‘1’ or more than one ‘1’.For this put self loop of ‘1’ on state “B”.

**Step-4:**

Now create transition of input alphabet ‘0’ from state “B” to state “C” and after two 0’s any number of 1’s can be found in the string and for this put self loop of ‘1’ on initial state “C”.

**Step-5:**

Before transition of third ‘0’ we need to think about the logic so that after this transition the machine will accept string that have number of zeros divisible by 3.For this transit ‘o’ from state “C” to state “A”.AS third zero is reaching to state “A” so make state “A” be final state.

Transition table of above DFA:

States | Input (0) | Input (1) |
---|---|---|

—> A * | B | A |

B | C | B |

C | A | C |

In above table, —> represents initial state and * represents final state. In this article, initial and final state is same which is final state.

Transition rules of above DFA:

**Implementing :**

## Python3

`def` `checkStateA(n): ` ` ` ` ` `# check length of n ` ` ` `# is 0 then print ` ` ` `# string accepted ` ` ` `if` `(` `len` `(n)` `=` `=` `0` `): ` ` ` `print` `(` `"string accepted"` `) ` ` ` ` ` `# if 1 is found call function ` ` ` `# checkStateA otherwise if 0 ` ` ` `# is found call function stateB ` ` ` `else` `: ` ` ` `if` `(n[` `0` `]` `=` `=` `'1'` `): ` ` ` `checkStateA(n[` `1` `:]) ` ` ` `else` `: ` ` ` `stateB(n[` `1` `:]) ` ` ` ` ` `def` `stateB(n): ` ` ` ` ` `# check length of n ` ` ` `# is 0 then print ` ` ` `# string not accepted ` ` ` `if` `(` `len` `(n)` `=` `=` `0` `): ` ` ` `print` `(` `"string not accepted"` `) ` ` ` ` ` `# if 1 is found call function ` ` ` `# stateB otherwise if 0 ` ` ` `# is found call function stateC ` ` ` `else` `: ` ` ` `if` `(n[` `0` `]` `=` `=` `'1'` `): ` ` ` `stateB(n[` `1` `:]) ` ` ` `else` `: ` ` ` `stateC(n[` `1` `:]) ` ` ` ` ` `def` `stateC(n): ` ` ` ` ` `# check length of n ` ` ` `# is 0 then print ` ` ` `# string not accepted ` ` ` `if` `(` `len` `(n)` `=` `=` `0` `): ` ` ` `print` `(` `"string not accepted"` `) ` ` ` ` ` `# if 1 is found call function ` ` ` `# stateC otherwise if 0 ` ` ` `# is found call function checkStateA ` ` ` `else` `: ` ` ` `if` `(n[` `0` `]` `=` `=` `'1'` `): ` ` ` `stateC(n[` `1` `:]) ` ` ` `else` `: ` ` ` `checkStateA(n[` `1` `:]) ` ` ` `# take string input ` `n ` `=` `input` `() ` ` ` `# call checkStateA ` `# to check the inputted string ` `checkStateA(n) ` |

*chevron_right*

*filter_none*

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

## Recommended Posts:

- DFA in LEX code which accepts even number of zeros and even number of ones
- DFA machines accepting odd number of 0’s or/and even number of 1’s
- Construct DFA which interpreted as binary number is divisible by 2, 3, 4
- Conversion from NFA to DFA
- Minimization of DFA
- DFA for accepting the language L = { a
^{n}b^{m}| n+m=even } - Program to Implement NFA with epsilon move to DFA Conversion
- DFA for Strings not ending with "THE"
- DFA of a string with at least two 0’s and at least two 1’s
- Union process in DFA
- Concatenation process in DFA
- Complementation process in DFA
- DFA of a string in which 2nd symbol from RHS is 'a'
- Reversal process in DFA
- DFA for accepting the language L = {a
^{n}b^{m}| n+m=odd} - Cross Product Operation in DFA
- DFA of a string in which 3rd symbol from RHS is ‘a’
- Program to construct a DFA which accept the language L = {a
^{n}b^{m}| n mod 2=0, m≥1} - DFA for strings not containing consecutive two a's and starting with 'a'
- Construct a DFA which accept the language L = {w | w ∈ {a,b}* and Na(w) mod 3 = Nb (w) mod 3}

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.