Design a Finite State Machine or Abstract Model for a Parity Checker

Design a Finite State Machine or Abstract Model for a Parity Checker

Verified Sources
Sep 12, 2026

A parity checker is a finite-state device that processes a bit stream and decides whether the number of 1s seen so far is even or odd. Because parity alternates each time a 1 arrives, the checker needs only two memory states: one representing “even number of 1s so far” and one representing “odd number of 1s so far.” This is a standard example of a DFA recognizing the parity language. In automata-theory terms, we maintain a state that captures the parity of the prefix; acceptance depends on the final state. 2

Key modeling choices

  • DFA / abstract automaton: no outputs during reading; “accept/reject” at the end.
  • Moore FSM (output = state): output is pinned to the current state.
  • Mealy FSM (output = transition): output can depend on current input and current state.

Mermaid view of the core two-state parity memory (abstract DFA concept):

Footnotes

  1. Finite-state machine - MTSU course notes (Parity checker description) - Explains parity checker as counting 1s in a bit-serial input stream and distinguishes odd/even parity behavior.

  2. Lecture 3 - Finite Automata (Parity using 2 states) - Provides a formal DFA construction for odd parity with two states representing parity so far.

  3. Mealy vs Moore machine explanation (output depends on state vs state+input) - Describes the distinction: Moore output depends only on present state; Mealy output depends on state and current input.

Mealy Machine and Moore Machine | What is State Diagram ?

Core keywords (mental model)

  • Parity
  • DFA
  • Moore machine
  • Mealy machine
  • Transition function

How to design a parity checker FSM

Even vs Odd

1. Specify parity goal

Decide whether you want output/acceptance for even # of 1s or odd # of 1s."

Track prefix parity

2. Choose states

Use two states: Even and Odd parity of the bits read so far."

Input 0 keeps parity; input 1 flips

3. Define transitions

On input 0, stay in the same parity state; on input 1, toggle."

Moore or Mealy output placement

4. Attach outputs (optional)

Pick Moore (output in state) or Mealy (output on transition) depending on timing needs."

Test prefixes and edge cases

5. Validate

Check empty string, and sequences like 0, 1, 10, 11, 101."

1) Abstract model as a DFA (accept at the end)

Language definition

A common parity task is: accept a binary string if it contains an odd number of 1s (odd-parity language). This can be implemented by a DFA with exactly two states tracking the parity of the number of 1s read so far.

DFA definition

Let M=(Q,Σ,δ,q0,F)M=(Q,\Sigma,\delta,q_0,F).

  • DFA
  • Q={E,O}Q=\{E,O\} where:
    • EE: “even number of 1s so far”
    • OO: “odd number of 1s so far”
  • Σ={0,1}\Sigma=\{0,1\}
  • q0=Eq_0=E (empty prefix has 0 ones → even)
  • For odd parity acceptance, F={O}F=\{O\}.

Transition function (parity flip rule)

The parity state changes only when the next input symbol is 1:

  • δ(E,0)=E\delta(E,0)=E
  • δ(E,1)=O\delta(E,1)=O
  • δ(O,0)=O\delta(O,0)=O
  • δ(O,1)=E\delta(O,1)=E

This aligns with standard parity-checker DFA construction: two states represent parity of what has been seen so far, start at even, and accept the odd-parity state. 2

DFA transition table

Present StateInputNext State
EE0EE
EE1OO
OO0OO
OO1EE

Mermaid for the DFA structure:

Footnotes

  1. Lecture 3 - Finite Automata (Parity using 2 states) - Provides a formal DFA construction for odd parity with two states representing parity so far. 2

  2. Finite State Machine Design Procedure (Parity checker example, Moore/Mealy context) - Includes an odd parity checker example and discusses Moore/Mealy forms and transition/output relationships.

Pro Tip

Parity can be computed incrementally: each new 1 toggles parity, and each 0 leaves it unchanged—so two states are sufficient.

2) Moore FSM design (output depends only on state)

When you want the machine to produce an output continuously (at clock edges) indicating whether the current prefix has even/odd parity, a Moore machine is natural: the output is a function of the current state only.

Moore specification

  • States: EE and OO
  • Output in each state:
    • For an odd-parity checker output=1 iff odd, set:
      • y(E)=0y(E)=0
      • y(O)=1y(O)=1
  • Transitions: same toggling rule as DFA.

This corresponds to the Moore convention that output is associated with the state (not the transition).

Moore state table

Present StateInputNext StateOutput (Moore)
EE0EE0
EE1OO0
OO0OO1
OO1EE1

Note: On a clock where the input causes a transition (e.g., E1OE \xrightarrow{1} O), a Moore output convention typically reflects the state after the clock edge (implementation detail), because Moore outputs are tied to state.

Footnotes

  1. Mealy vs Moore machine explanation (output depends on state vs state+input) - Describes the distinction: Moore output depends only on present state; Mealy output depends on state and current input. 2 3

3) Mealy FSM design (output depends on state + input)

If you want the output to respond as soon as the input symbol is applied (potentially one-cycle earlier in synchronous implementations), a Mealy machine can be used: output depends on both current state and current input.

Mealy specification

Define output y=g(S,x)y=g(S, x). For an odd-parity checker output=1 iff odd after consuming the current input symbol, you can set:

  • From EE:
    • input 0 keeps even → output 0
    • input 1 makes odd → output 1
  • From OO:
    • input 0 keeps odd → output 1
    • input 1 makes even → output 0

So the Mealy output mapping is:

  • y(E,0)=0y(E,0)=0, y(E,1)=1y(E,1)=1
  • y(O,0)=1y(O,0)=1, y(O,1)=0y(O,1)=0

And the next-state mapping remains:

  • δ(E,0)=E, δ(E,1)=O\delta(E,0)=E,\ \delta(E,1)=O
  • δ(O,0)=O, δ(O,1)=E\delta(O,0)=O,\ \delta(O,1)=E

This matches the defining distinction: Moore output depends only on state, while Mealy output depends on state and input.

Mealy state-transition/output table

Present StateInputNext StateOutput (Mealy)
EE0EE0
EE1OO1
OO0OO1
OO1EE0

Footnotes

  1. Mealy vs Moore machine explanation (output depends on state vs state+input) - Describes the distinction: Moore output depends only on present state; Mealy output depends on state and current input. 2

Step-by-step: Build an FSM parity checker (even or odd)

  1. 1
    Step 1

    Decide whether the checker should assert/accept when the number of 1s is even or odd.

  2. 2
    Step 2

    Name them EE (even so far) and OO (odd so far). Initialize start state to EE for empty input.

  3. 3
    Step 3

    For input 00: stay in the same state. For input 11: toggle parity (EOE\leftrightarrow O).

  4. 4
    Step 4

    Moore: set output by state only (y(E)y(E), y(O)y(O)). Mealy: set output by state+input (y(E,0)y(E,0), y(E,1)y(E,1), etc.).

  5. 5
    Step 5

    Test: empty string, '0', '1', '10', '11', '101'. Parity should match the expected even/odd count.

Example behavior of a parity checker

Odd-parity acceptance/output=1 iff the number of 1s in the prefix is odd.

FAQs and design edge cases

Knowledge Check

Question 1 of 4
Q1Single choice

In a parity checker that tracks the number of 1s seen so far, what should the next state do on input 1 from state E (even)?

Explore Related Topics

1

Semaphore and the Dining-Philosophers Solution Using Monitors

The content contrasts low‑level semaphores with high‑level monitors and shows how a monitor‑based solution avoids deadlock in the Dining Philosophers problem.

  • A semaphore offers atomic waitwait/signalsignal on a counter, but misordered calls can cause deadlock or race conditions.
  • A monitor bundles shared state with procedures and uses condition variables (x.wait()x.wait(), x.signal()x.signal()) to wait for logical predicates rather than resource counts.
  • The monitor algorithm maintains an array state[i]{THINKING,HUNGRY,EATING}state[i]\in\{THINKING, HUNGRY, EATING\} and a condition variable self[i]self[i] per philosopher; test(i)test(i) grants EATINGEATING only if both neighbors are not eating.
  • Because monitor entry is mutually exclusive and testtest is invoked on neighbours after putdown(i)putdown(i), the solution guarantees safety (no adjacent eaters) and deadlock freedom, while starvation freedom depends on fairness of signaling.
2

Minimization of Automata

3

Banker's Algorithm Safe-State Analysis for Processes $P_0$ Through $P_4$

The course walks through a full Banker's‑algorithm safety analysis for processes P0P_0P4P_4, computing the Need matrix and using the work‑vector test to verify a safe state and a valid completion order.

  • Need matrix: P0  (0,0,0,0)P_0\;(0,0,0,0), P1  (0,7,5,0)P_1\;(0,7,5,0), P2  (1,0,0,2)P_2\;(1,0,0,2), P3  (0,0,2,0)P_3\;(0,0,2,0), P4  (0,6,4,2)P_4\;(0,6,4,2).
  • Starting work Work=Available=(1,5,2,0)Work = Available = (1,5,2,0); each step selects a process with NeedWorkNeed \le Work, releases its allocation, and updates WorkWork.
  • All processes finish, yielding a safe sequence P0,P2,P1,P3,P4\langle P_0, P_2, P_1, P_3, P_4\rangle.
  • A safe state requires only one such sequence; it does not mean every immediate allocation is safe.
  • Exam tip: test processes with minimal or zero Need first to unlock the rest.