Skip to content
BetterDL

Suffix rule

Also called: longest suffix rule, prefix-suffix rule, longest matching suffix

For a sequence detector, the next state after any bit is the longest ending of the bits seen so far that is also a beginning of the pattern.

Each state of a sequence detector stands for a prefix of the pattern: how much has been matched so far. Progress arrows are easy. The hard part is where to go when a bit breaks the pattern.

The suffix rule answers it:

  1. Take the prefix for the present state and append the new bit.
  2. Look at the endings (suffixes) of that string, longest first.
  3. The first one that is also a beginning of the pattern is the next state. If none is, go to "nothing".

Why it works: the only part of the history that can still become a match is an ending that already looks like the start of the pattern. Keeping the longest such ending makes sure you never throw away progress you still have.

The same rule decides the arrow after a complete match in overlapping detection. Most design mistakes in detectors are arrows that reset too far, and checking each arrow with this rule catches them.

start0/01/00/01/00/01/00/11/0ABCD

Worked example

Example

Every arrow of a 0110 detector

Overlapping Mealy detector for 0110. States: A = nothing, B = 0, C = 01, D = 011. Pattern starts: 0, 01, 011.

  1. 1.

    A: on 0 → "0" → B. On 1 → "1" starts nothing → A.

  2. 2.

    B: on 0 → "00": 00 no, 0 yes → B. On 1 → "01" → C.

  3. 3.

    C: on 0 → "010": 010 no, 10 no, 0 yes → B. On 1 → "011" → D.

  4. 4.

    D: on 0 → "0110" is a match, output 1. Endings 110, 10 no, 0 yes → B.

  5. 5.

    D: on 1 → "0111": 111, 11, 1 start nothing → A.

  6. 6.

    Check: 4 states, 2 arrows from each, matching the diagram.

Common mistakes

  • Sending every mismatch back to "nothing". In the 0110 detector, C on 0 keeps the new 0 and goes to B.

  • Taking the shortest matching ending instead of the longest, which loses progress.

  • Checking endings against the whole pattern instead of against its beginnings (prefixes).

Practice Suffix rule

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Suffix rule is taught in Finite State Machines.