Sardinas–Patterson Decodability
Follow suffix states to distinguish prefix-free codes from uniquely decodable ones.
By Riano · Published · Updated · Report a correction
Sardinas–Patterson Decodability
An algorithm to test whether a given set of codewords is uniquely decodable by computing sequence of suffix residuals.
Concept Overview
A code (a set of words) is uniquely decodable if every concatenation of its words can be decoded in only one way. Prefix-free codes are uniquely decodable, but they are not the only ones. The Sardinas-Patterson algorithm is a finite-state method to determine whether a given variable-length code has the unique decodability property. It does so by looking for a sequence of overlapping codewords that could result in an ambiguous decoding.
Algorithm Definition
Let C be a set of codewords. The algorithm constructs a sequence of sets of words S0, S1, S2, ...
- S0 = C
- Sn+1 = (C-1 · Sn) ∪ (Sn-1 · C)
Where A-1 · B is the left quotient of B by A. It contains the suffix x such that a ∈ A and ax ∈ B.
The code is not uniquely decodable if the empty word (ε) appears in any Sn for n ≥ 1. The code is uniquely decodable if a set Sn is empty, or if the sequence of sets becomes periodic (a set repeats) without ever containing the empty word.
Worked Example
Consider the ambiguous code C = {"0", "01", "10"}. We trace the Sardinas-Patterson algorithm:
- S0 = C = {"0", "01", "10"}
- S1: We look for a codeword that is a prefix of another. "0" is a prefix of "01". The suffix is "1". So S1 = {"1"}.
- S2: We check S1 against C, and C against S1. "1" (from S1) is a prefix of "10" (from C). The suffix is "0". So S2 = {"0"}.
- S3: "0" (from S2) is equal to "0" (from C), so the suffix is the empty word ε. So S3 = {ε, "1"}.
Since the empty word appears in S3, the code is not uniquely decodable. We can construct the ambiguity witness: 010 = 0 | 10 = 01 | 0.
Experiment
Use the interactive module to explore different codeword sets:
- Select a Code such as "Nonprefix UD" to see a code that is uniquely decodable despite not being prefix-free.
- Select "Ambiguous" to trace the generation of Sn sets until the empty word is found.
- Select "Residual cycle" to observe how the sequence of sets can loop indefinitely without containing the empty string, proving unique decodability.
For the full interactive tool, view the Sardinas-Patterson Decodability Module.
Limitations
The Sardinas-Patterson algorithm applies to finite codes or regular languages. The time complexity can be high in the worst case (exponential in relation to codeword lengths), and the number of states generated can be large. However, since the length of any suffix generated is strictly less than the longest codeword in C, the set of possible suffixes is finite, guaranteeing termination.
The algorithm and prefix code foundations are based on the original 1953 Sardinas-Patterson paper and standard academic notes on information theory.
References
- https://courses.grainger.illinois.edu/ece563/fa2024/hw3sol-F24.pdf
- Sardinas, A. A., & Patterson, G. W. (1953). A necessary and sufficient condition for the unique decodability of coded messages.
Experience it interactively
Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Sardinas–Patterson Decodability module.
Try Sardinas–Patterson Decodability on Riano →