Finite state machine
In computer science, a finite-state machine (FSM) or finite-state automaton (FSA) is an abstract machine that has only a finite, constant amount of memory. The internal statess of the machine carry no further structure. This kind of model is very widely used in the study of computation and languages.
Overview
It can be conceptualised as a directed graph. There are a finitely many states, and each state has transitions to states.
There is an input string that determines which transition is followed (some transitions may be from a state to itself). Finite state machines are studied in automata theory, a subfield of theoretical computer science.
There are several types of finite state machines:
Acceptors produce a "yes" or "no" answer to the input; they either accept the input or do not. Recognizers categorise the input. Transducers are used to generate an output from a given input.
Finite automata may operate on languages of finite words (the standard case), infinite words (Rabin automata, BÃÂüchi automata), or various types of trees (tree automata), to name the most important cases.
A further distinction is between deterministic and non-deterministic automata. In deterministic automata, for each state there is at most one transition for each possible input. In non-deterministic automata, there can be more than one transition from a given state for a given possible input. Non-deterministic automata are usually implemented by converting them to deterministic automata—in the worst case, the generated deterministic automaton is exponentially bigger than the non-deterministic automaton (although it can usually be substantially optimised).
The standard acceptance condition for non-deterministic automata requires that some computation accepts the input. Alternating automata also provide a dual notion, where for acceptance all non-deterministic computations must accept.
Apart from theory, finite state machines occur also in hardware circuits, where the input, the state and the output are bit vectors of fixed size (Moore machines and Mealy machines).
Mealy machines have actions (outputs) associated with transitions and Moore machines have actions associated with states.
Formally, a deterministic finite automaton (DFA) is a 5-tuple:
(S, Σ, T, s, A)
Formally, the definition of computation of a finite automata is given.
Let M = (S, Σ, T, s, A) be a finite automata, and
X = x1x2 ... xn be a string over the alphabet Σ. M accepts the string X if a sequence of states,
r0,r1, ..., rn, exists in S with the following conditions:
A non-deterministic finite automaton (NFA) is a 5-tuple:
(S, Σ, T, s, A)
The machine starts in the start state and reads in a string of
symbols from its alphabet. It uses the transition relation T to determine
the next state(s) using the current state and the symbol just read or the empty string. If, when it has finished reading, it is in an accepting state, it is said to accept the string, otherwise it is said to reject the string. The set of strings it accepts form a language, which is the language the NFA recognises.
Every NFA has an equivalent DFA. Therefore it is possible to convert and existing NFA to DFA for the purpose of implementing a simpler machine.
A generalized non-deterministic finite automaton (GNFA) is a 5-tuple: (S, Σ, T, s, a)
A DFA or NFA can easily be converted into a GNFA and then the GNFA can be easily converted into a regular expression by reducing the number of states until S = {s, a}.
The following example explains a deterministic finite state machine (M) with a binary alphabet, which determines if the input contains an even number of 0s.
The problem of optimizing an FSM (finding the machine with the least number of states that performs the same function) is decidable, unlike the same problem for more computationally powerful machines. Furthermore, it is possible to
construct a canonical version of any FSM, in order to test for equality.
Both of these problems can be solved using a colouring algorithm.
FSMs can only recognize regular languages, and hence they are less computationally powerful than Turing machines -
there are decidable problems that are not computable using a FSM.
For each non-deterministic FSM a deterministic
FSM of equal computational power can be constructed with an algorithm.
A FSM may be represented using a state transition table or a state diagram. This is a diagram consisting of circles to represent states and directed line segments to represent transitions between those states.
Formal definitions
Deterministic finite automaton
The machine starts in the start state and reads in a string of symbols from its alphabet. It uses the transition function T to determine the next state using the current state and the symbol just read. If, when it has finished reading, it is in an accepting state, it is said to accept the string, otherwise it is said to reject the string. The set of strings it accepts form a language, which is the language the DFA recognises.
Condition 1 says that the machine starts in the start state, s. The second condition says that given each character of X, the machine will transition from state to state as ruled by the transition function, T. The last condition says that the machine accepts if the last input of X causes the machine to be in one of the accepting states.Non-deterministic finite automaton
Where P(S) is the power set of S and ε is the empty string.Generalized non-deterministic finite automaton
Where R is the collection of all regular expressions over the alphabet Σ.Examples of FSMs
Deterministic finite state machine

Simply put, the state S1 represents that there has been an even number of 0s in the input so far, while S2 signifies an odd number. A 1 in the input does not change the state of the automaton. When the input ends, the state will show whether the input contained an even number of 0s or not.Optimization and Canonicalisation
Computational power
Representation
Implementation
A finite state machine can be implemented in software with a state transition matrix.
In hardware a FSM may be built from a programmable logic device.Tools
See also
References
External links