93.3k views
5 votes
Construct a finite-state machine that gives an output of 1 if the number of input symbols read so far is divisible by 3 and an output of 0 otherwise.

User Columbia
by
8.2k points

1 Answer

2 votes

Answer:

Step-by-step explanation:

Here is a possible state diagram for the finite-state machine:

```

+---0---+

| |

v |

+----+0 S0 |

| | |

| +---1---+

| |

v v

| +---0---+

| | |

| v |

| S1+1 S2 |

| | |

| +---1---+

| |

v v

| +---0---+

| | |

| v |

| S2| 0 S1 |

| | |

+----+---1---+

```

The states are labeled S0, S1, and S2. The initial state is S0. The machine reads input symbols one by one, either 0 or 1, and transitions between states according to the input symbol.

Whenever the number of input symbols reads so far is divisible by 3, the machine should output 1. This happens whenever the machine is in state S0. So, we can set the output to 1 for state S0 and 0 for the other states.

Here is the transition table for the finite-state machine:

```

+-------+-------+-------+

| State | Input | Output|

+-------+-------+-------+

| S0 | 0 | 1 |

| S0 | 1 | 0 |

| S1 | 0 | 0 |

| S1 | 1 | 0 |

| S2 | 0 | 0 |

| S2 | 1 | 0 |

+-------+-------+-------+

```

In words, the machine transitions as follows:

- If in state S0 and the input is 0, stay in S0.

- If in state S0 and the input is 1, move to state S1.

- If in-state S1 and the input is 0, move to state S2.

- If in-state S1 and the input is 1, stay in S1.

- If in-state S2 and the input is 0, move to state S1.

- If in-state S2 and the input is 1, stay in S2.

We can implement this finite-state machine using a program or a circuit that updates the current state based on the current input and produces the corresponding output.

User Anku Singh
by
8.4k points