Theory of Computation · Moore and Mealy Machines
Output Function of Mealy Machine (Output Associated with Transitions)
Overview
In a Mealy machine the output is produced on the transition rather than by the state, so the output depends on the combination of the current state and the current input. This distinguishes Mealy machines from Moore machines, where each state carries a single fixed output.
Key concepts
- Mealy machine output: the output is associated with the transition, not with the state.
For a given state and a given input symbol there is some output, so the output depends on the combination of the current state and the current input. - Moore machine output: the output is associated with the state itself — every state has one output.
- Memory aid: write "Moore" as M O O R E — the two O's stand for "one output" (one output per state).
How it works
- Look at the current state.
- Look at the input symbol being read.
- The pair (current state, input symbol) determines the output produced on that transition.
Drawing the diagram…
Formulas
- Mealy: — the output is attached to the transition.
- Moore: — the output is attached to the state.
Worked examples
State Q0:
- input a → output 1
- input b → output 0
State q1:
- input b → output 0
- input a → output 1
The same state can produce different outputs depending on the input read (Q0 gives 1 on a and 0 on b), and the same input can produce different outputs in different states — the output is a function of (state, input).
Comparison
| Feature | Moore Machine | Mealy Machine |
|---|---|---|
| Output associated with | The state itself | The transition (current state + input) |
| Outputs per state | One output per state | Output depends on each (state, input) pair |
| Memory aid | M O O R A — two O's, one output | Output = combination of current state and input |
Revision summary
- Mealy output is attached to the transition; Moore output is attached to the state.
- In a Mealy machine, output .
- In a Moore machine, output .
- Same state with different inputs can give different outputs (Q0: a → 1, b → 0).
- Moore (M O O R A) → one output per state; Mealy → output on the state–input combination.
Previous-year exam insights
- Formal definitions: a Mealy machine is a 6-tuple (Q, Σ, Δ, δ, λ, q0) with δ: Q×Σ→Q and λ: Q×Σ→Δ (output on transitions); a Moore machine is a 6-tuple (Q, Σ, Δ, δ, λ, q0) with λ: Q→Δ (output on states).
Asked inGATE 2021 - In a Mealy machine the number of states can be smaller than in an equivalent Moore machine (Mealy may need fewer states), but a Moore machine generally needs more states; both can be converted into each other, and conversion Moore→Mealy is trivial while Mealy→Moore may increase the number of states.
Asked inGATE 2021 - For a Mealy machine with n states, m input symbols and k output symbols, the maximum number of transitions (edges) is n·m, and each transition is labelled input/output; the output length equals the input length (no extra output for the initial state).
Asked inGATE 2002 - In a Moore machine the output sequence has length one more than the input sequence, because the start state emits an output before any input is read; in a Mealy machine output length equals input length.
Asked inGATE 2002 - A Mealy machine's output at time t depends on the present state and present input (it can respond within the same clock cycle), whereas a Moore machine's output depends only on the present state (it is delayed by one cycle relative to the input that caused the transition).
Asked inGATE 2021GATE 2002 - To design a Mealy machine for a pattern/sequence-detection problem, define states by the relevant history (e.g., longest matching prefix seen so far) and place the output on the transition that completes the pattern; the same state may have different outputs for different inputs.
Asked inGATE 2021GATE 2002