Skip to content
← All questions

What is the definition of a prefix-free code?

A prefix-free code is a code in which no codeword appears as the initial segment (prefix) of any other codeword. For every pair of distinct codewords, neither may begin with the other as a prefix.

Conditions

  • Defined relative to concatenation of binary strings.
  • For every pair of distinct codewords cac_a, cbc_b, neither cac_a is a prefix of cbc_b nor cbc_b is a prefix of cac_a.

Reasoning, step by step

  1. List all codewords assigned to the source symbols under the code.
  2. For each pair of distinct codewords, check if one is a prefix of the other.
  3. Verify that no such prefix relation exists.
  4. Conclude that the code is prefix-free.

Example

In the displayed table, Codes 1, 2, and 4 are prefix-free. Code 3 is not prefix-free because the codeword 0 for x1x_1 is a prefix of 00 for x3x_3, and the codeword 1 for x2x_2 is a prefix of 11 for x4x_4.

Common misconceptions

  • Assuming that prefix-free codes must be fixed-length.
  • Confusing prefix-free codes with distinct codes; a code can be distinct but not prefix-free.

Watch the explanation

Explore next

Answers are generated from source material and independently checked. Consult the original video or creator if something is unclear.