CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 1 · Finite Automata

Lesson 1.4 · Item 28 of 91

Mealy and Moore machines

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. State the Myhill–Nerode theorem in one line.
    Stuck? Peek at 1.3.3 Myhill–Nerode theorem
    • x ≡_L y ⇔ ∀z: xz ∈ L ⇔ yz ∈ L. Right-invariant equivalence.
    • L regular ⇔ finite index; index = #states of minimal DFA (incl. dead class).
    • Infinitely many pairwise distinguishable strings ⇒ not regular. aⁿbⁿ: strings aⁱ separated by bⁱ.

    Read lesson 1.3.3

  2. Minimal DFA states for “2nd symbol from the end is 1”?
    Stuck? Peek at 1.2.3 Subset construction and the 2ⁿ blow-up
    • Subset construction: start {q₀} (or ECLOSE(q₀)); δ(S,a) = ⋃ δ(q,a) (then ECLOSE); accept iff S ∩ F ≠ ∅; ∅ = dead state.
    • ≤ 2ⁿ states; count only reachable sets.
    • ε-removal: δ'(q,a) = ECLOSE(δ(ECLOSE(q), a)); F' = {q : ECLOSE(q) ∩ F ≠ ∅}.
    • k-th from end is 1: NFA k+1, DFA 2ᵏ. k-th from start: DFA k+2.
    • DFA ≡ NFA ≡ ε-NFA in power.

    Read lesson 1.2.3

  3. How many states does a product of 3- and 4-state DFAs have at most?
    Stuck? Peek at 1.1.4 Product construction and complement
    • Product: states Q₁×Q₂, δ((p,q),a) = (δ₁(p,a), δ₂(q,a)), start (s₁,s₂).
    • ∩: F₁×F₂. ∪: F₁×Q₂ ∪ Q₁×F₂. −: F₁×(Q₂−F₂). ≤ |Q₁|·|Q₂| states.
    • Complement: complete the DFA (add dead state), swap F ↔ Q−F; same state count.
    • Regular languages closed under ∪, ∩, −, complement.

    Read lesson 1.1.4

The Hook

A traffic-light controller doesn’t answer yes or no — it outputs a colour at every moment. A serial adder outputs one bit for every pair of input bits. These are finite-state machines that translate an input string into an output string. GATE gives this topic low weight, but the two output conventions are easy marks.

Predict First

A machine prints one output symbol every time it is in a state (including the start state). For an input of length 5, how long is the output?

Core Concept

Prediction check

Answer: 6. It visits 6 states (start + one after each symbol) — the same “moments” count as the pigeonhole lesson (0.2.4). That is a Moore machine.

moment0123
input read—101
stater0r1r2r2
output0122
Moore on input 101: 3 symbols, 4 outputs (one per moment).

Moore machine

Moore machine (Q, Σ, Δ, δ, λ, q₀): Δ is the output alphabet; δ : Q × Σ → Q as in a DFA; λ : Q → Δ gives an output for each state. Output for input of length n has length n + 1.
r0
outputs 0
r1
outputs 1
r2
outputs 2
Moore: each state carries its own output.

Mealy machine

Mealy machine (Q, Σ, Δ, δ, λ, q₀) with λ : Q × Σ → Δ: output is attached to each transition. Output for input of length n has length n.

Neither machine has accepting states; they compute outputs, not yes/no.

stepstatereadsoutputnext
1A00A
2A10B
3B11B
4B11B
Mealy on 0111: output sits on each transition — 4 symbols in, 4 out.

Equivalence and conversion

A Moore and a Mealy machine are considered equivalent if their outputs agree after ignoring the Moore machine’s initial output λ(q₀).

  • Moore → Mealy: same states; λ'(q, a) = λ(δ(q, a)) (output the label of the state you enter). States: same number.
  • Mealy → Moore: split each state q into copies (q, o) for each output o of transitions entering q. At most |Q| · |Δ| states (plus possibly one extra copy for the start state).
Moore
output on states
same states: λ′(q,a) = λ(δ(q,a))
Mealy
output on edges
Mealy
split states by incoming output
Moore
≤ |Q|·|Δ| states
Conversions in both directions.

Typical machines

  • Residue mod 3 of a binary number (Moore): states r0, r1, r2 output 0, 1, 2.
  • 1’s complement (Mealy): one state, output 1 on input 0 and 0 on input 1.
  • Detect “11” (Mealy): output 1 on a transition that completes 11.
residue mod 3
Moore, 3 states
1’s complement
Mealy, 1 state: 0/1, 1/0
detect 11
Mealy, 2 states
Three typical transducers.

Putting it together

  • Moore: output per state, n + 1 symbols. Mealy: output per transition, n symbols.
  • Moore → Mealy keeps the states; Mealy → Moore may need |Q|·|Δ|.
  • Neither has accepting states — they translate rather than decide.

Visual

Moore: residue mod 3 (state/output)          input 101 (=5):
        0     1                              r0/0 ─1→ r1/1 ─0→ r2/2 ─1→ r2/2
→ r0/0  r0    r1                             output 0 1 2 2   (length 3+1 = 4)
  r1/1  r2    r0                             last output 2 = 5 mod 3 ✓
  r2/2  r1    r2

Mealy: output 1 when the last two inputs are 11
 state  on 0      on 1                       input 0111:
 A      A / 0     B / 0                      A ─0/0→ A ─1/0→ B ─1/1→ B ─1/1→ B
 B      A / 0     B / 1                      output 0 0 1 1   (length 4)

Worked Examples

Easy

A Moore machine reads 10 symbols. How many output symbols does it produce? A Mealy machine?

Show the full solution

Moore: 11. Mealy: 10.

Medium

Convert the residue-mod-3 Moore machine to Mealy.

Show the full solution

λ'(q,a) = output of δ(q,a). r0: 0 → r0/0, 1 → r1/1. r1: 0 → r2/2, 1 → r0/0. r2: 0 → r1/1, 1 → r2/2. Still 3 states. On 101: outputs 1, 2, 2 — the Moore output minus its initial 0 ✓.

GATE-level

A Mealy machine has 4 states and output alphabet {0,1}. What is the maximum number of states of an equivalent Moore machine produced by the standard conversion?

Show the full solution

Each state splits by incoming output: at most 4 × 2 = 8 (the start state may need one extra copy if it has no incoming transition with a suitable output; the usual exam answer is |Q|·|Δ| = 8).

GATE Traps

  • Moore output length n + 1 (includes the start state’s output); Mealy n.
  • Neither machine accepts or rejects — no F.
  • Moore → Mealy keeps the state count; Mealy → Moore can multiply it by |Δ|.

Memory Hook

MOore = Output On states (n+1). MEaly = output on the Edges (n).

Connect the Dots

Phase 1 complete. Finite automata in every flavour: DFA, NFA, ε-NFA, minimal DFA, and output machines. Phase 2 gives regular languages a second face: algebraic formulas called regular expressions — the thing behind search patterns in every editor.

Self-Test

  1. NAT

    A Moore machine processes an input of length 12. Output length?

    Write your answer before opening the key.

  2. MCQ

    In a Mealy machine the output function is:

    1. λ : Q → Δ
    2. λ : Q × Σ → Δ
    3. λ : Σ → Δ
    4. λ : Δ → Q
  3. MSQ

    Which are true?

    1. Moore → Mealy needs no extra states
    2. Mealy and Moore machines have accepting states
    3. Mealy → Moore may need up to |Q|·|Δ| states
    4. A Moore machine’s output depends only on the current state
  4. NAT

    Using the residue-mod-3 Moore machine, what is the last output symbol for input 1101?

    Write your answer before opening the key.

Rule Card

  • Moore: λ : Q → Δ; output length n+1. Mealy: λ : Q × Σ → Δ; output length n.
  • Moore → Mealy: same states, λ'(q,a) = λ(δ(q,a)). Mealy → Moore: ≤ |Q|·|Δ| states.
  • No accepting states; equivalence ignores Moore’s first output.

Concept Ledger

  • transducer (output machine)
  • output alphabet Δ
  • Moore machine (output on states)
  • Mealy machine (output on transitions)
  • Moore ↔ Mealy conversion

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. L is regular iff ≡_L has finite index; index = minimal DFA states.
  2. 4.
  3. 12.

Self-test answers

  1. 13 — n + 1.
  2. B — Output on transitions.
    • A: That is Moore.
    • C: Ignores state.
    • D: Backwards.
  3. ACD — Standard conversions.
    • B: They are transducers, without F.
  4. 1 — 1101 = 13; 13 mod 3 = 1.

Flashcards

  1. Moore vs Mealy output length for input length n?
    Reveal answerMoore n + 1; Mealy n.
  2. Max Moore states when converting a Mealy machine?
    Reveal answer|Q| · |Δ| (standard answer).
  3. Moore output function type?
    Reveal answerλ : Q → Δ

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.