Exercises — State diagram and state table design
This page trains the "capture the behaviour" half of the recipe: reading a spec, choosing states, filling a state table, and tracing traces. It builds directly on the parent note — every term used here (state, Mealy, Moore, prefix-state) is defined there. New notation is re-anchored below on first use.
Level 1 — Recognition
L1.1 — Mealy or Moore?
A state diagram has arrows labelled 1/0, 0/1, etc., and the bubbles contain only a state name. Which machine type is this?
Recall Solution
The output appears on the arrows (input/output), not inside the bubbles. Output depends on state and current input → this is a Mealy machine.
Rule: X/Z on arrows ⇒ Mealy. Sᵢ/Z inside bubbles ⇒ Moore.
L1.2 — Count the memory
A machine must detect the pattern 110. Using the "longest matched prefix" idea, how many prefix-states (before adding any Moore accept state) do we need?
Recall Solution
The proper prefixes of 110 are: "" (nothing), 1, 11. Detecting the full 110 produces the output but does not add a resting prefix beyond those. So we need (nothing), (1), (11) → 3 prefix-states for a Mealy detector.
L1.3 — Read a single transition
A Mealy detector for 1011 is in state (meaning 101 matched). Input bit arrives. From the parent table, what are the next state and output?
Recall Solution
101 + 1 = 1011 → MATCH, so . Because overlap is allowed, the trailing 1 is a fresh prefix, so we land in .
Answer: Next , .
Level 2 — Application
L2.1 — Trace a Mealy detector
Using the parent's 1011 Mealy table, trace the input X = 1011011 starting in . List the state after each bit and every . How many matches?
Recall Solution
Start .
1→ / 00→ / 01→ / 01→ / 1 ← match #1 (1011)0→ / 01→ / 01→ / 1 ← match #2 (overlap,1011)
Two matches. The overlap works because after match #1 we sat in (holding a 1), letting 011 complete a new 1011.
L2.2 — Build a tiny table from scratch
Design a Mealy detector for the pattern 01 (overlapping). Give the full state table.
Recall Solution
Prefix-states: (nothing / matched a useless bit), (matched 0).
| Present | X=0 → Next / Z | X=1 → Next / Z | Why |
|---|---|---|---|
| / 0 | / 0 | a 0 starts a possible match; 1 alone is useless |
|
(0) |
/ 0 | / 1 | 00 still ends in one 0 (stay ); 01 = MATCH |
Overlap note: after matching 01, the trailing 1 is not a prefix of 01, so we correctly go to .
L2.3 — Complete an incomplete table
A student drew this partial Mealy table for 01. Fill the missing cell so the table is complete.
| Present | X=0 → Next / Z | X=1 → Next / Z |
|---|---|---|
| / 0 | ? | |
| / 0 | / 1 |
Recall Solution
The missing cell is on input . A lone 1 matches no prefix of 01, so we stay in with .
Answer: / 0. A state table must give a next-state entry for every (state, input) pair.
Level 3 — Analysis
L3.1 — Why go to , not ?
For the 1011 detector, prove that returning to after a match misses an overlapping match, by tracing 1011011 under the wrong rule.
Recall Solution
Wrong rule: after a match, jump to .
1→ ·0→ ·1→ ·1→ MATCH #1, then wrongly →0→ ·1→ ·1→
Ends in with only 1 match. The correct machine (parent) reports 2 matches on the same string. So resetting to discards the trailing 1 and misses the overlapping 1011.
Principle: after a match, jump to the state for the longest suffix of the pattern that is also a prefix of it — for 1011 that suffix is 1 → .
L3.2 — Longest-suffix-that-is-a-prefix
For the pattern 1010, after a full match, which state should we jump to (overlapping)? Assume states "", "1", "10", "101".
Recall Solution
After matching 1010, look at its suffixes and ask which is also a prefix of 1010:
- suffix
0→ prefix?1010starts with1, not0. No. - suffix
10→ prefix?1010starts with10. Yes. - suffix
010,1010→ longer, check biggest first:010? starts with0? no.1010full? that's the whole match, not a proper overlap.
Longest suffix that is also a prefix = 10 → jump to ====.
L3.3 — Convert Mealy → Moore
Take the L2.2 Mealy 01 detector and convert it to a Moore machine. How many states now, and what is the table?
Recall Solution
Moore must arrive in a state to show . So add accept state (01 matched, output 1).
| Present | Output | X=0 → Next | X=1 → Next |
|---|---|---|---|
| 0 | |||
(0) |
0 | ||
| (accept) | 1 |
behaves for future input exactly like after a 1 (its trailing 1 matches no prefix), but it displays output 1.
Count: Mealy = 2 states, Moore = 3 states → Moore needed one more.
Level 4 — Synthesis
L4.1 — Design a full detector, both flavours
Design an overlapping detector for 110. Give (a) the Mealy state table and (b) the Moore state table. Use "", "1", "11".
Recall Solution
(a) Mealy — reason each cell:
| Present | X=0 → Next / Z | X=1 → Next / Z | Why |
|---|---|---|---|
| / 0 | / 0 | 0 useless; 1 starts a match |
|
(1) |
/ 0 | / 0 | 10 dead → ; 11 progresses |
(11) |
/ 1 | / 0 | 110=MATCH, then longest suffix-prefix of 110 is "" → ; 111 still ends in 11 → stay |
Overlap check: after matching 110, its suffixes 0,10 are not prefixes of 110, so we go to . Correct.
(b) Moore — add accept state (), reached when sees a 0:
| Present | Output | X=0 → Next | X=1 → Next |
|---|---|---|---|
| 0 | |||
| 0 | |||
| 0 | |||
| (accept) | 1 |
L4.2 — Trace to confirm
Using your L4.1 Mealy 110 table, trace X = 1101100 from . How many matches (how many )?
Recall Solution
1→/01→/00→/1 ← match #1 (110)1→/01→/00→/1 ← match #2 (110)0→/0
Two matches. (No overlap possible here since 110 has no suffix that is also a prefix, so back-to-back 110110 gives two clean matches.)
Level 5 — Mastery
L5.1 — State-count reasoning
A pattern of length over the alphabet {0,1} is to be detected (overlapping) with a Mealy machine using the prefix-state method. What is the maximum number of states such a machine can need, and give the pattern-length-3 example that hits it? Compare to the equivalent Moore count.
Recall Solution
The prefix-states are the proper prefixes of the pattern: "", then the first 1 bit, first 2 bits, …, first bits. That is exactly states for a Mealy detector (states ), regardless of pattern. So a length-3 pattern needs 3 Mealy states (e.g. 110 from L4.1: ).
Moore adds one accept state to display the output → 4 Moore states for a length-3 detector.
General rule: Mealy needs states; Moore needs (an accept state), confirming the parent's "Moore needs ≥ as many states as Mealy" trade-off. Here Moore uses exactly one extra.
L5.2 — The tricky self-overlapping pattern
Design a Mealy overlapping detector for 1010. Give the full state table, then trace X = 1010100 and count matches. This is the pattern where the overlap state is not .
Recall Solution
States: "", "1", "10", "101".
| Present | X=0 → Next / Z | X=1 → Next / Z | Why |
|---|---|---|---|
| / 0 | / 0 | 0 useless; 1 starts |
|
(1) |
/ 0 | / 0 | 10 progresses; 11 still ends in one 1 |
(10) |
/ 0 | / 0 | 100 dead → ; 101 progresses |
(101) |
/ 1 | / 0 | 1010=MATCH; longest suffix-prefix of 1010 is 10 → ; 1011 ends in one 1 → |
Trace 1010100 from :
1→/00→/01→/00→/1 ← match #1 (1010)1→/00→/1 ← match #2 (overlapping1010, sharing the middle10)0→/0
Two matches — and the second is a genuine overlap, only possible because we jumped to (not ) after the first match. See the trace figure.

L5.3 — Diagnose a broken machine
A colleague's 1010 detector jumps to (instead of ) after a match. On input 1010100, how many matches does their (buggy) machine report, and which real match does it lose?
Recall Solution
Buggy rule: after 1010 match, go to .
1→ ·0→ ·1→ ·0→ MATCH #1, then wrongly →1→ ·0→ ·0→
Ends with only 1 match. It loses the second, overlapping 1010 (positions 3–6 of the string), because throwing away the shared middle 10 destroys the overlap. The correct machine (L5.2) finds 2.
Active recall
Recall What determines the landing state after a match (overlapping)?
The longest suffix of the pattern that is also a prefix of the pattern.
Recall Mealy vs Moore state count for a length-
overlapping detector? Mealy needs states; Moore needs (an extra accept state to display the output).
Recall What makes a state table "complete"?
Every (present-state, input) pair has a defined next-state (and output) entry.
Connections
- Sequence Detectors — the canonical application drilled here
- Finite State Machines — the model these tables encode
- State Assignment and Reduction — the next step after building the table
- Excitation Tables and Next-State Equations — turning these tables into flip-flop logic
- Flip-Flops and Latches — the memory that stores the state bits
- Combinational Circuits — the stateless contrast