0% found this document useful (0 votes)
41 views

Assignment-1-Renas H. Darweesh

The document contains solutions to three questions about finite state machines and regular expressions. For question 1, the document provides solutions for finite state machines that accept strings with an even number of 0s and 1s divisible by 3, strings divisible by 6, and strings of decimal numbers divisible by 6. Question 2 asks to convert NFAs to DFAs but no examples are given. Question 3 gives three regular expressions and the document lists the languages generated by each expression.

Uploaded by

Renas Dareesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Assignment-1-Renas H. Darweesh

The document contains solutions to three questions about finite state machines and regular expressions. For question 1, the document provides solutions for finite state machines that accept strings with an even number of 0s and 1s divisible by 3, strings divisible by 6, and strings of decimal numbers divisible by 6. Question 2 asks to convert NFAs to DFAs but no examples are given. Question 3 gives three regular expressions and the document lists the languages generated by each expression.

Uploaded by

Renas Dareesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment-1- Renas H.

Darweesh

Q1:
 All the strings that consist of the symbols 0 and 1 where the amount of 0’s is divisible by
2 (even amount of 0’s) and the amount of 1’s is divisible by 3.
 Solution:
1. Create machine for each one of my alphabets separately following requirements
asked in the question
2. Combine both machines.
3. Convert NFA to DFA by using algorithm that we got on the lecture.

4. Select new final state to accept string that contain even amount of 0’s and 1’s
divisible by 3.

1
Assignment-1- Renas H. Darweesh

 All the strings that consist of the symbols 0 and 1 where the given number is divisible by
6. For example, 0, 110, 1100, …
 Solution:
1. Create machine accepts strings that are divisible by 3 and making its q 0 as initial
and final state.
2. Create new transition “0” from q0 to a new state and make it as a new final state
because if we add zero to the end of any binary number that’s divisible by 3 that
number will be changed to a number that’s divisible by 6, and q 0 remain only as
an initial state.

 All the strings that consist of the decimal numbers 0 to 9 where given input is divisible by
6. For example, 0,6, 12, 18, ...
 Solution:
1. Create q0 state and set it as an initial and final with a transition of number 6 to itself
because (6%6) is equal to zero so the transition of number (6) should end at q0.
Result of Mod operation shows as the state that we should create transition between it
and current state.
2. Same operation (number%6) will be done for all numbers from 0 to 9 and following
is the results:
 0%6=0  transition with 0 from q0 to q0.
 1%6=1  transition with 1 from q0 to q1.
 2%6=2  transition with 2 from q0 to q2.
 3%6=3  transition with 3 from q0 to q3.
 4%6=4  transition with 4 from q0 to q4.
 5%6=5  transition with 5 from q0 to q5.
 6%6=0  transition with 6 from q0 to q0.

2
Assignment-1- Renas H. Darweesh

 7%6=1  transition with 7 from q0 to q1.


 8%6=2  transition with 8 from q0 to q2.
 9%6=3  transition with 9 from q0 to q3.
3. Here we can see number of states we should have for this finite machine from results
we got above that’re 6 states (q0, q1, q2, q3, q4, q5) because biggest remaining number
from (Number % 6) operation is (5), so we need states from q0 to q5.
4. Again, we need to do (Number%6) operation on all state until all state gets
transitions between each other like the following operations on q1 state:
 We had number (1,7) on state q1 so when another number comes with these
two numbers that will be put next to this numbers and the (Number%6)
operation will be done again, operations on q1 will be as following:
o When q1 had (6,0)  10%6=4, 16%6=4, 70%6=4, and 76%6=4
Transition with (6,0) from q1 to q4.
o When q1 had (3,9)  13%6=1, 19%6=1, 73%6=1, and 79%6=1
Transition with (3,9) from q1 to q1.
o When q1 had (8,2)  18%6=0, 12%6=0, 78%6=0, and 72%6=0
Transition with (8,2) from q1 to q0.
o When q1 had (1,7)  11%6=5, 17%6=5, 71%6=5, and 77%6=5
Transition with (1,7) from q1 to q5.
o When q1 had (4)  14%6=4, 74%6=4 Transition with (4) from
q1 to q2.
o When q1 had (5)  15%6=4, 75%6=4 Transition with (6,0) from
q1 to q3.
o And this same as these operations should be done for all states that
we’ve on this finite machine and after that our machine that only
accepts decimal numbers that are divisible by 6 is ready and following
is the result.

3
Assignment-1- Renas H. Darweesh

Q2:
Convert the following NFAs into DFAs:

 Solution:

4
Assignment-1- Renas H. Darweesh

Q3:
1. a (a | b) * a
 Solution:
L = {aa, aaa, aba, aaba, abba, aabaa, …}
2. (a | b) * a (a | b) (a | b)
 Solution:
L = {aaa, aaaa, babb, baab, aabb, baba, …}
3. (aa | bb) * ((ab | ba) (aa | bb) * (ab | ba) (aa | bb) *) *
 Solution:
L = {aa, abab, baba, abba, baab, aaabaaabaa, bbbabbaabaaabb, …}

You might also like