# DFA machines accepting odd number of 0’s or/and even number of 1’s

Prerequisite – Designing finite automata

**Problem –** Contruct a DFA machine over input alphabet = {0, 1}, that accepts:

- Odd number of 0’s or even number of 1’s
- Odd number of 0’s and even number of 1’s
- Either odd number of 0’s or even number of 1’s but not the both together

**Solution –** Let first design two separate machines for the two conditions:

- Accepting only odd number of 0’s
- Accepting only even number of 1’s

Then, merge these two and find the required final states.

To merge these two machines, we will take the Cartesian product of the states of these two machines:

Initial state of these DFA will be the state which contains the initial states of those two separate machines. As, q0 and q2 are the initial states thus, q0q2 is the initial state of the final DFA.

Now start designing all the DFAs one by one:

**Odd number of 0’s or even number of 1’s:**This machine accept that languages which contains either odd no. of 0’s or even no. of 1’s. As we know that q1 indicates odd no. of 0’s and q2 indicates even no. of 1’s. So, the final states of the required DFA will contain either q1 or q2.

.’. Final states = {(q0q2), (q1q2), (q1q3)}This is our required DFA which accept the languages containing odd no. of 0’s or even no. of 1’s.

**Odd number of 0’s and even number of 1’s:**This machine accept that languages which contains odd no. of 0’s and even no. of 1’s. As we know that q1 indicates odd no. of 0’s and q2 indicates even no. of 1’s. So, the final states of the required DFA will contain both q1 and q2.

.’. Final state = {(q1q2)}

This is our required DFA which accept the languages containing odd no. and 0’s or even no. of 1’s.

**Either odd number of 0’s or even number of 1’s but not the both together:**This machine accept that languages which contains either odd no. of 0’s or even no. of 1’s but not that languages which contains both odd no. of 0’s and even no. of 1’s. As we know that q1 indicates odd no. of 0’s and q2 indicates even no. of 1’s. So, the final states of the required DFA will contain exactly one among q1 and q2.

.’. Final states = {(q0q2), (q1q3)}This is our required DFA which accept the languages containing odd no. of 0’s or even no. of 1’s but not the both together.

## Recommended Posts:

- NFA machines accepting all strings that ends or not ends with substring 'ab'
- TOC | Moore and Mealy machines to count number of substring ‘ab’
- Mealy and Moore Machines
- TOC | Construction of the machines that produce 'A', 'B', or 'C' if input ends with '1', '0', or nothing
- TOC | Moore and Mealy machines to produce 'A', 'B', 'C' depends on inputs that end with ’10’ or with ’11’ else other
- TOC | Construction of finite machines to prints ‘1’ as the output for every occurrence of ‘a’ as a substring
- TOC | Construction of the machines to produce residue modulo ‘2’ of binary numbers
- DFA for accepting the language L = { a
^{n}b^{m}| n+m=even } - DFA for accepting the language L = {a
^{n}b^{m}| n+m=odd} - NPDA for accepting the language L = {a
^{n}b^{n}c^{m}| m,n>=1} - NPDA for accepting the language L = {a
^{m}b^{n}c^{(m+n)}| m,n ≥ 1} - NPDA for accepting the language L = {a
^{m}b^{(m+n)}c^{n}| m,n ≥ 1} - NPDA for accepting the language L = {a
^{i}b^{j}c^{k}d^{l}| i==k or j==l,i>=1,j>=1} - NPDA for accepting the language L = {a
^{m}b^{n}c^{p}d^{q}| m+n=p+q ; m,n,p,q>=1} - NPDA for accepting the language L = {a
^{m}b^{(2m)}| m>=1}

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.