**Problem –** Draw detereministic finite automata (DFA) of a string with at least two 0’s and at least two 1’s.

The first thing that come to mind after reading this question us that we count the number of 1’s and 0’s. Thereafter if they both are at least 2 the string is accepted else not accepted. But we do not have any concept of memory in a DFA so we cannot do it by this method.

Input : 1 0 1 1 0 0 Output : Accepted Input : 1 1 1 0 1 Output : Not accepted

**Approach Used –**

The first thing we observe is that both 0’s and 1’s should be at least 2. If any of these is less than 2, then string will not be accepted. In this string will be accepted in only last case where both 0’s and 1’s will be at least 2.

State | Count of 0 | Count of 1 |
---|---|---|

Q0 | 0 | 0 |

Q1 | 0 | 1 |

Q2 | 0 | >=2 |

Q3 | 1 | 0 |

Q4 | 1 | 1 |

Q5 | 1 | >=2 |

Q6 | >=2 | 0 |

Q7 | >=2 | 1 |

Q8 ACCEPTED | >=2 | >=2 |

Initially count of both 0 and 1 is zero and we are on state Q0.

**Step-1:**If input is 1 then count of 1 increases to 1. Goto state Q1

If input is 0 then count of 0 increases to 1. Goto state Q3**Step-2:**If input is 1 then count of 1 increases to 2. Goto state Q2

If input is 0 then count of 0 increases to 1. Goto state Q4**Step-3:**If input is 1 then count of 1 keeps increasing by 1. Remain in the same state

If input is 0 then count of 0 increases to 1. Goto state Q5**Step-4:**If input is 1 then count of 1 increases to 1. Goto state Q4

If input is 0 then count of 0 increases to 2. Goto state Q6**Step-5:**If input is 1 then count of 1 increases to 2. Goto state Q5

If input is 0 then count of 0 increases to 2. Goto state Q7**Step-6:**If input is 1 then count of 1 keeps increasing by 1. Remain in the same state.

If input is 0 then count of 0 increases to 2. Goto state Q8**Step-7:**If input is 1 then count of 1 increases to 1. Goto state Q7

If input is 0 then count of 0 keeps increasing by 1. Remain in the same state.**Step-8:**If input is 1 then count of 1 increases to 2. Goto state Q8

If input is 0 then count of 0 keeps increasing by 1. Remain in the same state.**Step-9:**If input is 1 then count of 1 keeps increasing by 1. Remain in the same state.

If input is 0 then count of 0 keeps increasing by 1. Remain in the same state.

If string is finished then ACCEPTED

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 for exactly one of a and at least one of b
- Design a DFA that accepts a string containing 3 a's and 3 b's
- Build a DFA to accept a binary string containing "01" i times and "1" 2j times
- DFA for strings not containing consecutive two a's and starting with 'a'
- DFA of a string in which 2nd symbol from RHS is 'a'
- DFA of a string in which 3rd symbol from RHS is ‘a’
- 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 a DFA which accept the language L = {w | w ∈ {a,b}* and Na(w) mod 3 = Nb (w) mod 3}
- Program to build a DFA to accept strings that start and end with same character
- Difference between DFA and NFA
- DFA of alternate 0's and 1's
- Program to build a DFA that accepts strings starting and ending with different character
- Program to construct DFA accepting odd number of 0s and odd number of 1s
- 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"
- Union process in DFA

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.