A-level Computing/AQA/Problem Solving, Programming, Data Representation and Practical Exercise/Problem Solving/Finite state machines
A finite state machine consists of states, inputs and outputs. The number of states is fixed; when an input is executed, the state is changed and an output is possibly produced. Finite state machines are widely used when designing computer programs, but also have their uses in engineering, biology, linguistics and other sciences thanks to their ability to recognise sequences.
A finite state machine expressed visually is a State transition diagram. It is used to show all the states, inputs and outputs. Each state is represented with a circle, and each transition with an arrow. Transitions are labelled with an input that causes a transition and possibly an output that results from it.
A finite state machine can be with or without outputs. A Mealy Machine is an FSM with outputs. A Finite State Automaton is an FSM with no outputs.
[edit] Mealy Machines
[edit] State transition tables
A state transition table follows every state and input. Inputs are usually placed on the left, and separated from the outputs, which are on the right. The outputs will represent the next state of the machine. Here's a simple example of a state machine with two states, and two combinatorial inputs:
| A | B | Current State | Next State | Output |
|---|---|---|---|---|
| 0 | 0 | S1 | S2 | 1 |
| 0 | 0 | S2 | S1 | 0 |
| 0 | 1 | S1 | S2 | 0 |
| 0 | 1 | S2 | S2 | 1 |
| 1 | 0 | S1 | S1 | 1 |
| 1 | 0 | S2 | S1 | 1 |
| 1 | 1 | S1 | S1 | 1 |
| 1 | 1 | S2 | S2 | 0 |