You are on page 1of 7

Page | 1

Assignment: 01
Course Name: Finite Automata and computability
Course Id: cse437/csc301
Sec: 01
Group no: 04

NAME ID
Nafiz Fuad 1720542

Tasnuva Zaman 1720367

Sinthia Prome 1720157


Page | 2

Create an Finite State Automata that accepts the set of all natural numbers divisible by 4.

a) Define the Automata with all 5 Tuples < I , Q, q0 , A , F >


Answer:
Let’s consider some natural numbers divisible by 4 and some are not,

4%4=0; 5%4=1; 6%4=2; 7%4=3; 8%4=0;


12%4=0; 13%4=1; 14%4=2; 15%4=3; 16%4=0;
32%4=0; 33%4=1; 34%4=2; 35%4=3; 36%4=0;
We find in each case the remainders are 0, 1, 2, 3. So, there will be 4 states in the automata. Let’s
take the state are q1, when the remainder is 0. Similarly, for sates q2, q3, q4, the remainders will be
1, 2, 3.
We can define the five tuples are,

I= {0, 1, 2, 3, 4, 5, 6,7,8,9,…….,n} //Set of input symbols.

Q= {q0, q1, q2, q3} //Finite set of states.

q0= q0 // Initial state. q0 ε Q.

A= q0 // Final state. A ε Q.
// The goal will be achieved when the remainder will become 0. And for remainder 0, the state
will be q0 as declared earlier.

F= Mapping, QXI🡪Q

State For Input, For input, For input, For input,


Q I= {0, 4, 8,….}| 4n I= {1, 5, 9,….}| I= {2, 6, 10,….}| I= {3, 7, 11,….}|
(4n+1) (4n+2) (4n+3)

Start state, q0 q0 q1 q2 q3

q1 q2 q3 q0 q1

q2 q0 q1 q2 q3

q3 q2 q3 q0 q1

We can also write,


F(q0, 0|4|8)=q0 , F(q0, 1|5|9)=q1 , F(q0, 2|6|10)=q2 , F(q0, 3|7|11)=q3
F(q1, 0|4|8)=q2 , F(q1, 1|5|9)=q3 , F(q1, 2|6|10)=q0 , F(q1, 3|7|11)=q1
Page | 3

F(q2, 0|4|8)=q0 , F(q2, 1|5|9)=q1 , F(q2, 2|6|10)=q2 , F(q2, 3|7|11)=q3


F(q3, 0|4|8)=q2 , F(q3, 1|5|9)=q3 , F(q3, 2|6|10)=q0 , F(q3, 3|7|11)=q1

b) Draw the Transition Diagram with edges and Symbols.

Figure: State Transition diagram.


Page | 4

c) Insert 5 numbers each with minimum length of 6. Show the inputs and Transitions in Tabular
format.

1st number= 165832


Using the transition function,

Q= QXI

F (q0, 165832)

F (q1, 65832)

F (q0, 5832)

F (q1, 832)

F (q2, 32)

F (q3, 2)

F (q0, ε)

Here, q0 ε A (Final State), Input string is valid and accepted by the automata.

2nd number= 256217

Using the transition function,

Q= QXI

F (q0, 256217)

F (q2, 56217)

F (q1, 6217)

F (q0, 217)

F (q2, 17)
Page | 5

F (q1, 7)

F (q1, ε)

Here, q1 does not belong to A (Final State), Input string is invalid and not accepted by the automata.

3rd number= 356212


Using the transition function,

Q= QXI

F (q0, 356212)

F (q3, 56212)

F (q3, 6212)

F (q0, 212)

F (q2, 12)

F (q1, 2)

F (q0, ε)

Here, q0 ε A (Final State), Input string is valid and accepted by the automata.

4th number= 165921

Using the transition function,

Q= QXI

F (q0, 165921)

F (q1, 65921)

F (q0, 5921)

F (q1, 921)

F (q3, 21)

F (q0, 1)

F (q1, ε)
Page | 6

Here, q1 does not belong to A (Final State), Input string is invalid and not accepted by the automata.

5th number= 241892


Using the transition function,

Q= QXI

F (q0, 241892)

F (q2, 41892)

F (q0, 1892)

F (q1, 892)

F (q2, 92)

F (q1, 2)

F (q0, ε)

Here, q0 ε A (Final State), Input string is valid and accepted by the automata.

d) Transform the FSA into a Regular Grammar of G = (T, N, S, F)

Conversion of FSA into regular grammar:


Page | 7

T= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ……} // Terminal symbols

N= {q0, q1, q2, q3} // Non-terminal symbols

S= q0 // Starting non-terminal symbol.

F= Production rules are as following,

q0 = 0 q0 | 4 q0 | 8 q0 | 12 q0 | 1 q1 | 5 q1 | 9 q1 | 2 q2 | 6 q2 | 10 q2 | 3 q3 | 7 q3 | 11 q3

q0 = 0 | 4 | 8 | 12

q1 = 2 q0 | 6 q0 | 10 q0 | 3 q1 | 7 q1 | 11 q1 | 0 q2 | 4 q2 | 8 q2 | 1 q3 | 5 q3 | 9 q3

q1 = 2 | 6 | 10

q2 = 0 q0 | 4 q0 | 8 q0 | 12 q0 | 1 q1 | 5 q1 | 9 q1 | 2 q2 | 6 q2 | 10 q2 | 3 q3 | 7 q3 | 11 q3

q2 = 0 | 4 | 8 | 12

q3 = 2 q0 | 6 q0 | 10 q0 | 3 q1 | 7 q1 | 11 q1 | 0 q2 | 4 q2 | 8 q2 | 1 q3 | 5 q3 | 9 q3

q3 = 2 | 6 | 10

The End

You might also like