Assignment No 2
Assignment No 2
LAHORE
School of Computer Science
ASSIGNMENT: Theory of
Automata
Problem
Construct a FA machine accepting odd numbers of 0’s or even numbers of 1’s.
Solution
Design two separate machines for the two conditions over an alphabet Σ= {0,1} −
DFA accepting only odd number of 0’s
DFA accepting only even number of 1’s
DFA accepting only odd number of 1’s over an alphabet Σ={0,1}
The language L= {1,10,1110,1011,10101,100101,….}
Now merge two transition diagrams to generate a machine accepting odd number of 0’s
or even number of 1’s
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:
1. 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.
2. 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.
3. 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.