Skip to content
GATEiit

GATE EC · Digital Circuits

Finite state machines

Moore and Mealy machines: state diagrams and tables, sequence detectors with and without overlap, analysis of clocked sequential circuits, state assignment, state reduction and the minimum number of flip-flops.

Before you start

  • Flip-flops and excitation tables →

    The state register is a set of flip-flops; design needs their excitation tables and analysis needs their characteristic equations.

  • Counters →

    A counter is the simplest FSM with no input; tracing a counter is the same skill as analysing any FSM.

  • Karnaugh maps →

    Next-state and output equations are minimised with K-maps using unused states as don't-cares.

This topic comes before: ALU, data-path and control unit

Concept notes

1. The FSM model: Moore and Mealy

A finite state machine (FSM) is a synchronous sequential circuit with a finite set of states. It has three parts: a state register of flip-flops that holds the present state Q, next-state logic that computes the flip-flop inputs from Q and the input x, and output logic.

Moore machine Mealy machine
Output depends on present state only present state and present input
Output written inside the state circle on the arrow, as input/output
States for a detector usually one more fewer (or equal)
Output timing changes only after a clock edge, for a full cycle can change as soon as the input changes
Glitches on input do not reach the output can pass to the output

With k flip-flops, at most 2k states are available, so a machine with N states needs at least

k=⌈log⁡2N⌉ flip-flops

Every Mealy machine has an equivalent Moore machine and vice versa. The Moore version may need more states, and its output appears one clock cycle later, because a Moore output can only change when the state changes.

Unused states: if 2k>N, some codes are unused. A safe design checks that each unused state leads back into the main sequence. A circuit that stays stuck in unused states is said to lock up.

next-statelogicstate register(flip-flops)outputlogicxzclockDpresent state Qdashed: Mealy only (input also drives the output logic)
General FSM: next-state logic feeds the flip-flops, which hold the present state Q. In a Moore machine the output logic sees only Q; in a Mealy machine it also sees the input x (dashed).

2. Sequence detectors

A sequence detector outputs 1 when the last few input bits match a given pattern. Each state remembers how much of the pattern has been matched so far.

Mealy design for a pattern of length n: states S0,S1,…,Sn−1, where Si means "the last i bits match the first i bits of the pattern". The output 1 is put on the arrow that completes the pattern. So a Mealy detector needs n states.

Moore design: add one more state Sn ("pattern seen") whose output is 1. So n+1 states.

Overlap. With overlapping detection, the end of one match can start the next. In 1011011, the pattern 1011 occurs at bits 1–4 and 4–7. After a match, go to the state for the longest suffix of what has been seen that is also a prefix of the pattern. Without overlap, go back to S0 after every match.

Wrong-input arrows. When the next bit does not extend the match, do not jump straight to S0. Find the longest suffix of the bits seen so far that is a prefix of the pattern. Example for 101: in S2 (seen 10), input 0 gives 100, whose longest useful suffix is empty, so go to S0; in S1 (seen 1), input 1 gives 11, whose suffix 1 is a prefix, so stay in S1.

Pattern length n Mealy states Moore states
3 (e.g. 101) 3 (2 flip-flops) 4 (2 flip-flops)
4 (e.g. 1011) 4 (2 flip-flops) 5 (3 flip-flops)
S0S1S20/01/01/00/01/10/0start
Mealy detector for 101 with overlap. S0: nothing matched, S1: seen 1, S2: seen 10. Labels are input/output. After 101 the machine goes to S1, because the final 1 can start the next match.

3. Analysing a clocked sequential circuit

To find what a given circuit does:

  1. Write the flip-flop input equations from the gates (for example DA=A⊕B).
  2. Convert them to next-state equations using the characteristic equations: Q+=D, Q+=T⊕Q, Q+=JQ‾+K‾Q.
  3. Build the state table: every present state (and input combination), the next state and the output.
  4. Draw the state diagram and read the behaviour: a count sequence, a detector, a divider.

All flip-flops are clocked together, so at each edge every flip-flop uses the old values of all outputs. Fill the whole row of the table from the present state before moving to the next row.

Example. DA=A⊕B, DB=B‾:

AB DA DB next AB
00 0 1 01
01 1 0 10
10 1 1 11
11 0 0 00

The sequence is 00→01→10→11→00: a 2-bit (mod-4) up counter. Each flip-flop output has a frequency of fclk/2 (B) and fclk/4 (A).

Always complete the table for all 2k states, including those not reached from the start state. Questions often ask what happens from an unused state: whether it joins the main cycle or locks up.

4. Design steps and state reduction

Design flow:

  1. Draw the state diagram from the word description.
  2. Reduce the number of states (below).
  3. Assign binary codes to states, using ⌈log⁡2N⌉ flip-flops. One-hot assignment uses N flip-flops with exactly one 1, trading flip-flops for simpler logic.
  4. Write the state table with present code, input, next code and output.
  5. From the flip-flop excitation table, find the flip-flop inputs for each row, and minimise them with K-maps, using unused codes as don't-cares.

State equivalence. Two states are equivalent if, for every input sequence, they produce the same output sequence. Equivalent states can be merged.

A quick test: two states with the same outputs and the same next states for every input are equivalent. The full test is partitioning:

  1. P1: group states with identical output rows.
  2. Pk+1: split a group if, for some input, its members go to states in different groups of Pk.
  3. Stop when a partition repeats. Each final group becomes one state.

Same next states alone is not enough; the outputs must also match. And same outputs alone is not enough; the next states must be equivalent too. State reduction can lower the number of flip-flops, for example from 5 states (3 flip-flops) to 3 states (2 flip-flops).

Formulas to remember

Minimum flip-flopsN states, binary encoding
k=⌈log⁡2N⌉
One-hot encodingOne flip-flop per state
k=N
Sequence detector statesPattern of length n
NMealy=n,NMoore=n+1
Moore output
z=g(Q)
Mealy output
z=g(Q,x)
Next stateThrough Q+=D, T⊕Q or JQ‾+K‾Q
Q+=f(Q,x)

Common mistakes

  • Using the number of states as the number of flip-flops. The minimum is ⌈log₂ N⌉, and only a one-hot design uses N.
  • Sending every wrong input back to the start state in a sequence detector. Go to the state for the longest suffix that is still a prefix of the pattern.
  • Mixing up overlapping and non-overlapping detection. After a match, overlap keeps the useful suffix; non-overlap returns to the start state.
  • Updating one flip-flop and then using its new value for the next flip-flop in the same clock edge. All flip-flops use the old present state.
  • Merging states that have the same next states but different outputs, or the same outputs but non-equivalent next states.
  • Ignoring unused states. A question may ask whether the circuit recovers or locks up when it starts in one.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Mealy detector for 110 with overlap

numerical

Design the state diagram of a Mealy machine that outputs 1 whenever the last three inputs are 110 (overlap allowed). How many flip-flops are needed? What is the output for the input 0110110?

  1. Step 1: Define the states by how much of 110 has been matched.

    Try it on paper first.

Example 2: Analysing two D flip-flops

numerical

A circuit has two D flip-flops with D1=Q0 and D0=Q1⊕Q0‾. Starting from Q1Q0=00, find the state sequence. What happens if the circuit powers up in 11?

  1. Step 1: Compute the next state of each state.

    Try it on paper first.

Example 3: Reducing a state table

numerical

A Mealy machine has the table below (next state/output for x=0 and x=1). A: B/0, C/0. B: D/0, E/0. C: D/0, E/0. D: A/0, E/1. E: A/0, E/1. Find the minimal number of states and flip-flops.

  1. Step 1: Group by output rows.

    Try it on paper first.

Example 4: Mealy or Moore for 1011?

conceptual

For an overlapping detector of 1011, compare the Mealy and Moore designs in number of states, flip-flops and output timing.

  1. Step 1: Count the Mealy states.

    Try it on paper first.

Previous year questions

1 official GATE EC question on this topic, newest first.

Topic test

9 questions: up to 1 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE EC syllabus; being checked by a reviewer. Updated 2026-11-29. Spotted a mistake? Use Report an issue on any question, or contact us.