Design a Finite State Machine or Abstract Model for a Parity Checker
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
-
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. ↩
-
Lecture 3 - Finite Automata (Parity using 2 states) - Provides a formal DFA construction for odd parity with two states representing parity so far. ↩
-
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 goalDecide whether you want output/acceptance for even # of 1s or odd # of 1s."
Track prefix parity
2. Choose statesUse two states: Even and Odd parity of the bits read so far."
Input 0 keeps parity; input 1 flips
3. Define transitionsOn 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. ValidateCheck 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 .
- DFA
- where:
- : “even number of 1s so far”
- : “odd number of 1s so far”
- (empty prefix has 0 ones → even)
- For odd parity acceptance, .
Transition function (parity flip rule)
The parity state changes only when the next input symbol is 1:
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 State | Input | Next State |
|---|---|---|
| 0 | ||
| 1 | ||
| 0 | ||
| 1 |
Mermaid for the DFA structure:
Footnotes
-
Lecture 3 - Finite Automata (Parity using 2 states) - Provides a formal DFA construction for odd parity with two states representing parity so far. ↩ ↩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: and
- Output in each state:
- For an odd-parity checker output=1 iff odd, set:
- For an odd-parity checker output=1 iff odd, set:
- 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 State | Input | Next State | Output (Moore) |
|---|---|---|---|
| 0 | 0 | ||
| 1 | 0 | ||
| 0 | 1 | ||
| 1 | 1 |
Note: On a clock where the input causes a transition (e.g., ), a Moore output convention typically reflects the state after the clock edge (implementation detail), because Moore outputs are tied to state.
Footnotes
-
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 . For an odd-parity checker output=1 iff odd after consuming the current input symbol, you can set:
- From :
- input
0keeps even → output 0 - input
1makes odd → output 1
- input
- From :
- input
0keeps odd → output 1 - input
1makes even → output 0
- input
So the Mealy output mapping is:
- ,
- ,
And the next-state mapping remains:
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 State | Input | Next State | Output (Mealy) |
|---|---|---|---|
| 0 | 0 | ||
| 1 | 1 | ||
| 0 | 1 | ||
| 1 | 0 |
Footnotes
-
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)
- 1Step 1
Decide whether the checker should assert/accept when the number of 1s is even or odd.
- 2Step 2
Name them (even so far) and (odd so far). Initialize start state to for empty input.
- 3Step 3
For input : stay in the same state. For input : toggle parity ().
- 4Step 4
Moore: set output by state only (, ). Mealy: set output by state+input (, , etc.).
- 5Step 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
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
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 / on a counter, but misordered calls can cause deadlock or race conditions.
- A monitor bundles shared state with procedures and uses condition variables (, ) to wait for logical predicates rather than resource counts.
- The monitor algorithm maintains an array and a condition variable per philosopher; grants only if both neighbors are not eating.
- Because monitor entry is mutually exclusive and is invoked on neighbours after , the solution guarantees safety (no adjacent eaters) and deadlock freedom, while starvation freedom depends on fairness of signaling.
Minimization of Automata
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 –, computing the Need matrix and using the work‑vector test to verify a safe state and a valid completion order.
- Need matrix: , , , , .
- Starting work ; each step selects a process with , releases its allocation, and updates .
- All processes finish, yielding a safe sequence .
- 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.