Skip to main content

Digital Logic

Finite State Machines

Decide Mealy vs Moore from where the output lives, then draw overlapping sequence detectors carefully.

~2 hrs ~0.5–1 mark · Moderate 10 samples · 10 practice · 10 cards

GATE CSE FSMs — Mealy vs Moore with diagrams, 101 sequence detectors, overlap vs non-overlap, state tables/reduction, and exam tricks.

Learning outcomes

  • Distinguish Mealy and Moore output dependency and timing
  • Draw Mealy/Moore state diagrams for short binary sequence detectors
  • Handle overlapping vs non-overlapping fallback after a match
  • Build a state table and merge equivalent states by inspection

Mealy vs Moore

  • Moore: output Z = f(present state only). Changes when the state register updates (clocked).
  • Mealy: output Z = f(present state, present input). Can change as soon as X changes — faster reaction, more glitch risk.
  • Diagram cue: Moore labels outputs in/ beside nodes; Mealy labels edges as input/output.
  • For the same external behaviour, Mealy often needs fewer or equal states (outputs on edges encode distinctions).
  • Both are still synchronous FSMs if next-state is clocked — “async output” ≠ “async state”.
MachineOutput depends onTiming cue
MooreState onlyStable between clocks
MealyState + inputMay change with input
Block diagrams of Moore output from state only and Mealy output from state plus input
Green Z path: Moore from state; Mealy also taps input X.

State diagrams & tables

  • States = memory of “what matters so far”. Reset/idle is the known start after power-on/reset.
  • Every state must define a next state for each input symbol (complete specification) unless don’t-cares are stated.
  • State table columns: present state, next state for each X, and outputs (Moore: per state; Mealy: per transition).
  • Implementation path: encode states → FF bits → next-state + output equations → excitation (Sequential lesson).

Formulas to remember

  • n FF bits ⇒ ≤ 2^n usable encodings
  • Unused codes: treat as don’t-care or force reset
Example FSM state table and rule for merging equivalent states
Same outputs + equivalent successors ⇒ merge (GATE inspection level).

Sequence detector — Mealy “101”

  • States track the longest prefix of the target pattern that is also a suffix of the input so far.
  • For “101”: idle → got 1 → got 10 → (on 1) detect.
  • Mealy: assert Z=1 on the transition that completes the pattern (edge label 1/1).
  • After detect with overlap: go to “got 1” because the last bit 1 is already a prefix of 101.

Worked example

Problem. Stream 10101 on an overlapping Mealy 101 detector — how many times is Z=1?

Solution. Twice: ending at positions 3 and 5 (…101 and …101).

Mealy state diagram for overlapping 101 sequence detector with input/output edge labels
Green ★ edge is the detection transition (Mealy output on the arc).

Sequence detector — Moore “101”

  • Moore needs a dedicated Detect state where Z=1 is attached to the state itself.
  • You enter Detect after the completing input, on the next clock — output is delayed by one state update vs Mealy’s edge assertion.
  • From Detect, transitions encode overlap/non-overlap just like Mealy fallbacks.
  • GATE ask: “when can Z rise?” → only after entering Detect (not mid-cycle from X alone).

Worked example

Problem. Why does Moore often have one more state than Mealy for the same detector?

Solution. Detection is a state (Z=1) rather than a transition attribute, so an extra node appears.

Moore state diagram for 101 detector with output labeled inside states including DETECT
Green DETECT node carries Z=1 — classic Moore picture.

Overlapping vs non-overlapping

  • Non-overlapping: after a hit, return to idle/start; ignore using match bits as a new prefix.
  • Overlapping: after a hit, keep the longest suffix of the matched string that is still a prefix of the pattern.
  • Example pattern 101 on stream 10101: overlap detects twice; non-overlap detects once then needs a fresh 101.
  • Always read the stem — “overlapping allowed” changes next-state arrows after success.

Formulas to remember

  • Overlap fallback = longest proper suffix ∩ prefixes of pattern
  • Non-overlap fallback = reset / idle
Comparison of overlapping and non-overlapping detection on input stream 10101
Same bits, different hit counts — the GATE discriminator.

State reduction (exam depth)

  • Equivalent states: identical outputs and transitions that lead to equivalent states (recursive definition).
  • Merge them to cut FF count / logic. Implication charts exist but GATE usually wants inspection on 3–5 states.
  • Don’t merge states that differ only “sometimes” — one wrong output row blocks equivalence.
  • After reduction, re-encode and rebuild the state table before writing equations.

GATE exam tricks — FSMs

  • First question: is Z on the node (Moore) or on the arc with X (Mealy)?
  • Mealy can assert Z in the same cycle the last bit arrives; Moore waits until Detect is entered.
  • Overlapping 101/1101 traps: after success, do not blindly reset — check the suffix.
  • Count states before drawing; unreachable states waste time and confuse options.
  • Completeness: every state × every input needs a next state (unless X is restricted).
  • “Minimum states” ⇒ try Mealy + overlap-aware design, then reduce equivalents.
  • Implementation numericals: k states ⇒ ≥ ⌈log₂ k⌉ FFs (same as mod-N sizing idea).
  • Reset state must be reachable from power-up; unused encodings should not lock the machine.

Formulas to remember

  • FF bits ≥ ⌈log₂ (#states)⌉
  • Mealy edge label: X / Z

Worked example

Problem. A Moore machine has 5 states. Minimum flip-flops?

Solution. ⌈log₂ 5⌉ = 3 FFs (with 3 unused codes).

Exam tips

  • Ask: is output tied to a state or to a transition/input?
  • Overlapping detectors: after success, fall back to the suffix that is still a prefix.
  • Count states before drawing — don’t invent unreachable ones.
  • Mealy Z can follow X combinationally; Moore Z waits for the Detect state.
  • Stream trace: tick state after each bit, then read Z (Mealy from edge, Moore from node).
  • Non-overlap ≠ overlap — hit counts on 10101 differ.
  • Equivalent states need matching outputs and matching successor classes.
  • Link to Sequential: next-state bits → D/T/JK excitation tables.
Exam pattern · 10 questions

GATE sample questions & answers

10 GATE-style MCQs for Finite State Machines with full explanations. Attempt each question before revealing the answer.

Q1 Moore definition

Moore outputs depend on:

  • A) Input only
  • B) State only
  • C) State and input
  • D) Clock duty only
Show answer & explanation

Answer: B

Output = f(state).

Q2 Mealy timing

Mealy outputs can change:

  • A) Only on power-up
  • B) When input changes even before next clock (combinationally)
  • C) Never more than once ever
  • D) Only in ROM
Show answer & explanation

Answer: B

Output = f(state,input).

Q3 Detector nature

Sequence detector FSMs are usually:

  • A) Combinational only
  • B) Sequential state machines
  • C) Caches
  • D) ALUs
Show answer & explanation

Answer: B

Need memory of partial matches.

Q4 Overlap

Overlapping detector for 101 after a hit may return to:

  • A) Always reset to idle only
  • B) A state reflecting the suffix that is a prefix
  • C) Random state
  • D) Halt forever
Show answer & explanation

Answer: B

Overlap reuses trailing bits.

Q5 State reduction

Equivalent states can be merged if:

  • A) They have different outputs
  • B) Same outputs and transitions to equivalent states
  • C) They are any two states
  • D) Clock differs
Show answer & explanation

Answer: B

Standard equivalence.

Q6 FSM finiteness

Finite state machine memory is finite because:

  • A) Infinite registers
  • B) Finite number of states
  • C) Analog caps
  • D) Disk
Show answer & explanation

Answer: B

Definition of FSM.

Q7 Diagram labels

State diagram edges are labeled with:

  • A) Only outputs always
  • B) Inputs (and outputs for Mealy)
  • C) Cache tags
  • D) Opcodes only
Show answer & explanation

Answer: B

Mealy puts outputs on edges; Moore on nodes.

Q8 Reset

A reset state typically:

  • A) Is unreachable
  • B) Is the known starting state after reset
  • C) Has no outgoing edges
  • D) Ignores clock
Show answer & explanation

Answer: B

Initialized by reset signal.

Q9 State count

Compared to Moore, Mealy often has:

  • A) Strictly more states always
  • B) Fewer or equal states for same I/O
  • C) No outputs
  • D) Infinite states
Show answer & explanation

Answer: B

Outputs on transitions can encode distinctions without extra states.

Q10 Non-overlap

Non-overlapping detector after success:

  • A) Continues matching using the hit bits as prefix
  • B) Returns to start without using overlap
  • C) Deletes the clock
  • D) Becomes combinational
Show answer & explanation

Answer: B

Non-overlap restarts cleanly after a detection.

Topic drill · 10 questions

10 practice questions — Finite State Machines

Extra page-specific practice beyond the GATE samples. Attempt all 10, then reveal answers to check your reasoning.

P1

Output associated only with states ⇒

  • A) Mealy
  • B) Moore
  • C) Both identical
  • D) Neither
Show answer & explanation

Answer: B) Moore

Moore definition.

P2

Fastest reaction to input change typically:

  • A) Moore
  • B) Mealy
  • C) ROM
  • D) Latch without FF
Show answer & explanation

Answer: B) Mealy

Combinational dependence on input.

P3

Detector for pattern length k needs on the order of:

  • A) 1 state always
  • B) About k states (prefixes)
  • C) 2^k always exactly
  • D) Infinite
Show answer & explanation

Answer: B) About k states (prefixes)

Prefix automaton size ~k for a single pattern.

P4

State table columns usually include:

  • A) Only ROM address
  • B) Present state, input, next state, output
  • C) Cache miss only
  • D) Opcode fetch
Show answer & explanation

Answer: B) Present state, input, next state, output

Standard FSM table.

P5

Two states with different Moore outputs:

  • A) Always equivalent
  • B) Cannot be equivalent
  • C) Must merge
  • D) Illegal
Show answer & explanation

Answer: B) Cannot be equivalent

Outputs must match for equivalence.

P6

FSM implemented with FFs + combinational logic is:

  • A) Impossible
  • B) Standard hardware realization
  • C) Only software
  • D) Analog only
Show answer & explanation

Answer: B) Standard hardware realization

State register + next-state/output logic.

P7

Self-loop on a state means:

  • A) Crash
  • B) Remain in state for that input
  • C) Reset chip
  • D) DMA
Show answer & explanation

Answer: B) Remain in state for that input

Transition to same state.

P8

Binary encoding of 5 states needs at least how many FFs?

  • A) 2
  • B) 3
  • C) 5
  • D) 4
Show answer & explanation

Answer: B) 3

2^2=4<5≤8.

P9

One-hot encoding of 5 states uses:

  • A) 3 FFs
  • B) 5 FFs
  • C) 1 FF
  • D) 10 FFs
Show answer & explanation

Answer: B) 5 FFs

One FF per state.

P10

A non-overlapping sequence detector after a successful match typically:

  • A) Returns toward the start/idle path without reusing the match as an overlapping prefix
  • B) Stays in the detected state forever
  • C) Deletes the clock
  • D) Becomes combinational only
Show answer & explanation

Answer: A) Returns toward the start/idle path without reusing the match as an overlapping prefix

Non-overlapping detectors restart cleanly after detection; overlapping ones reuse a suffix prefix.

Topic FAQs

Which is “better”, Mealy or Moore?

Neither universally. Mealy can be smaller/faster reacting; Moore outputs are synchronized to state and often glitch-friendlier.

How do I spot Mealy vs Moore on a diagram?

Moore: outputs written in the state bubbles. Mealy: outputs written on the transition arrows with the inputs (X/Z).

What does overlapping mean for a sequence detector?

After a successful match, the machine reuses the trailing bits as the start of a new match if they form a prefix of the pattern.

Why does a Moore detector often have an extra state?

Detection is represented by a state that outputs 1. Mealy can flag detection on the completing transition without that extra node.

When can two states be merged?

When they produce the same outputs and their next states (for every input) are pairwise equivalent.

How many flip-flops for an FSM with k states?

At least ⌈log₂ k⌉. Unused binary codes should be handled (don’t-care or reset) so the machine cannot hang.

Quick revision · 10 cards

10 flashcards — Finite State Machines

Hover a card to reveal the answer with a 3D flip. On touch devices, tap the card or use Show answer.

Q1 Moore output?
Q2 Mealy output?
Q3 Where are Moore outputs drawn?
Q4 Where are Mealy outputs drawn?
Q5 Overlapping detector idea?
Q6 10101 on overlapping 101 detector?
Q7 When can equivalent states merge?
Q8 FF count for k states?
Q9 Mealy glitch risk?
Q10 Why Moore may need an extra state?