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:

- Mealy and Moore Machines
- DFA for accepting the language L = { a
^{n}b^{m}| n+m=even } - 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} - NPDA for accepting the language L = {a
^{m}b^{(m+n)}c^{n}| 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
^{2m}b^{3m}| m ≥ 1} - NPDA for accepting the language L = {a
^{n}b^{m}c^{n}| m,n>=1} - NPDA for accepting the language L = {a
^{n}b^{n}c^{m}| m,n>=1} - NPDA for accepting the language L = {a
^{m}b^{(2m+1)}| m ≥ 1} - NPDA for accepting the language L = {a
^{n}b^{n}| n>=1} - DFA in LEX code which accepts even number of zeros and even number of ones
- DBMS | Number of possible Superkeys
- TCP Sequence Number | Wrap Around Concept
- Number of possible Equivalence Relations on a finite set

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.