Back to the 2021 paper

Module 1: Introduction & Regular Languages

20217m

Design a finite-state machine (FSM) for a parity checker.

Worked SolutionAI Assisted

Answer

Parity Checker FSM: Checks if number of 1s in input is even (even parity) or odd (odd parity). Common use: error detection in communication.

Assumptions

  • Input alphabet: Σ={0,1}\Sigma = \{0, 1\} (binary stream)
  • Output: Even (0) or Odd (1) parity bit after each input, or final parity at end
  • We present Moore and Mealy versions

1. Moore Machine (Output on State)

States: Q={E,O}Q = \{E, O\}

  • EE: Even number of 1's seen so far (initial, accepting for even parity)
  • OO: Odd number of 1's seen so far

Output function λ\lambda:

  • λ(E)=0\lambda(E) = 0 (even parity)
  • λ(O)=1\lambda(O) = 1 (odd parity)

Transition function δ\delta:

State Input 0 Input 1
EE EE OO
OO OO EE

State Diagram:

        0
     ┌────┐
     │    ▼
  (E)───►(O)
     ▲   │
     └───1
  • On 0: stay in same parity state
  • On 1: flip parity

Formal Moore: M=(Q,Σ,Δ,δ,λ,q0)M = (Q, \Sigma, \Delta, \delta, \lambda, q_0)

  • Q={E,O}Q = \{E, O\}, Σ={0,1}\Sigma = \{0,1\}, Δ={0,1}\Delta = \{0,1\}
  • δ(E,0)=E,δ(E,1)=O,δ(O,0)=O,δ(O,1)=E\delta(E,0)=E, \delta(E,1)=O, \delta(O,0)=O, \delta(O,1)=E
  • λ(E)=0,λ(O)=1\lambda(E)=0, \lambda(O)=1
  • q0=Eq_0 = E

2. Mealy Machine (Output on Transition)

States: Q={E,O}Q = \{E, O\} (same states, no output on states)

Output on transition:

Transition Input Next State Output
E→0EE \xrightarrow{0} E 0 EE 0
E→1OE \xrightarrow{1} O 1 OO 1
O→0OO \xrightarrow{0} O 0 OO 1
O→1EO \xrightarrow{1} E 1 EE 0

State Diagram:

      0/0
   ┌─────┐
   │     ▼
  (E)──►(O)
  │1/1   │0/1
   └─────1/0

Formal Mealy: M=(Q,Σ,Δ,δ,λ,q0)M = (Q, \Sigma, \Delta, \delta, \lambda, q_0) with λ:Q×Σ→Δ\lambda: Q\times\Sigma \to \Delta.


3. Even Parity Generator (Output at End)

If only final parity needed (not running):

  • Run Moore/Mealy above
  • After last input, output λ(q)\lambda(q) (Moore) or last transition output (Mealy)
  • Even parity = 0 if even # of 1's, 1 if odd

Test Sequence

Input Moore State Seq Moore Output Seq Mealy Output Seq
1011 E→O→O→E→OE \to O \to O \to E \to O 0,1,1,1,0 1,1,1,0
Even # 1s: 1100 → ends in E, output 0
Odd # 1s: 110 → ends in O, output 1

Final Answer

Parity Checker FSM — 2-state Moore/Mealy machine tracking even/odd count of 1's.

  • Moore: Output = state parity (E→0, O→1)
  • Mealy: Output on each transition (flip on 1, hold on 0)
  • Transitions: 0 = stay, 1 = flip
  • Minimal: 2 states (even/odd are distinguishable)

Similar questions

Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.