- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Design a DFA of a string with at least two 0’s and at least two 1’s

A Deterministic Finite automaton (DFA) is a 5-tuples

**M=(Q, Σ, δ,q0,F)**

Where,

- Q : Finite set called states.
- Σ : Finite set called alphabets.
- δ : Q × Σ → Q is the transition function.
- q0 ϵ Q is the start or initial state.
- F : Final or accept state.

## Problem

Construct DFA of a string with at least two 0’s and at least two 1’s.

## Solution

The language generated based on the given condition over the alphabet Σ ={0,1) is −

L={0011,001011,0001010,0011001,010101,……}

The given language accepts at least two zero’s means it can accept two or more than two zero’s and at least two one’s means it accepts two or more than two one’s.

Suppose,

**Input**− 00010**Output**− string rejected

Because, the given input does not have at least two’s.

Even though it has at least zeros, it won’t accept the string.

To accept the string both conditions are satisfied, if one fails the string will not be accepted by the machine.

- Input − 001001001
- Output − string accepted

Now construct the DFA for given inputs −

State | Number of zero’s | Number of one's |
---|---|---|

→ 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 | > =2 | > =2 |

The DFA will be as follows −

## Explanation

If input is 1 then the number of 1 increases to 1. Move to state q1. If input is 0 then the number of 0 increases to 1. Move to state q3.

If input is 1 then the number of 1 increases to 2. Move to state q2. If input is 0 then the number of 0 increases to 1. Move to state q4.

If input is 1 then the number of 1 always increases by 1. And then remain in the same state. If input is 0 then the number of 0 increases to 1. Move to state q5.

If input is 1 then the number of 1 increases to 1. Move to state q4. If input is 0 then the number of 0 increases to 2. Move to state q6.

If input is 1 then the number of 1 increases to 2. Move to state q5. If input is 0 then number of 0 increases to 2. Move to state q7.

If input is 1 then the number of 1 always increases by 1. And then remain in the same state. If input is 0 then the number of 0 increases to 2. Move to state q8

If input is 1 then the number of 1 increase to 1. Move to state q7. If input is 0 then the number of 0 keeps increasing by 1. And then remain in the same state.

If input is 1 then the number of 1 increase to 2. Move to state q8. If input is 0 then the number of 0 keeps increasing by 1. And then remain in the same state.

If input is 1 then the number of 1 always increases by 1. And then remain in the same state. If input is 0 then the number of 0 keeps increasing by 1. And then remain in the same state.

Finally, if the string is finished, then it is ACCEPTED.

- Related Articles
- Match any string containing a sequence of at least two p's.
- Design NFA with Σ = {0, 1} and accept all string of length at least 2.
- Design a DFA that accepts at most 3 a"s
- Design a DFA machine accepting odd numbers of 0’s or even numbers of 1’s
- Construct DFA of alternate 0’s and 1’s
- Make the sample space of tossing two coins simultaneously and find the probability of:1. Exactly two heads2. At least one head3. At least one tail4. At most two tails
- Design DFA for language over {0,1} accepting strings with odd number of 1’s and even number of 0’s
- Subarray sum with at least two elements in JavaScript
- Three different coins are tossed together. Find the probability of getting: $( i)$ exactly two heads $( ii)$ at least two heads $( iii)$ at least two tails.
- Checking if decimals share at least two common 1 bits in JavaScript
- Convert inputs to arrays with at least two dimensions in Numpy
- Check If All 1's Are at Least Length K Places Away in C++
- Maximum 0’s between two immediate 1’s in binary representation in C++
- Python program to check if two lists have at least one common element
- C# program to check if two lists have at-least one element common