Linear Code — Definition, Formula & Example
A linear code is an error-correcting code in which adding any two codewords, digit by digit, always produces another codeword. Because of this structure, you can describe the whole code with one small matrix instead of listing every codeword.
A linear code over the finite field is a -dimensional subspace of the vector space . Equivalently, is the row space of a generator matrix of rank , or the null space of an parity-check matrix . The minimum distance of equals the smallest Hamming weight of any nonzero codeword. Such a code is written as an code.
Key Formula
Where:
- = number of codewords in the code
- = size of the alphabet (the field), so q = 2 for binary codes
- = dimension of the code, which is the number of message symbols
- = minimum distance of the code
- = Hamming weight of c, the number of nonzero entries in c
Worked Example
Problem: Is the binary code linear? If it is, give a generator matrix, its dimension , its minimum distance , and how many bit errors it can detect and correct.
Step 1: A binary code is linear when it contains the zero word and the sum (mod 2) of any two codewords is again a codeword. Check every sum of two different nonzero codewords.
Step 2: Every sum lands back in , and , so is a subspace of . The two words and are independent and generate the other two, so they form the rows of a generator matrix. The dimension is , which matches .
Step 3: Because the code is linear, is the smallest weight of a nonzero codeword. Every nonzero codeword has exactly two 1s. A code with minimum distance detects errors and corrects errors.
Answer: is a binary linear code, the even-weight (single parity-check) code. It detects any single bit error but cannot correct it.
Why It Matters
Encoding with a linear code takes one matrix multiplication, and decoding can use a short syndrome computed with the parity-check matrix. You don't need a lookup table of every codeword. This efficiency is why Reed–Solomon codes protect data on QR codes and CDs, and why linear codes are a standard topic in abstract algebra and information theory courses.
Common Mistakes
Mistake: Adding codewords with ordinary arithmetic, which produces digits like 2 that cannot appear in a binary code.
Correction: In a binary linear code, addition happens in the field with two elements. Add each position separately and reduce mod 2, so 1 + 1 gives 0 and nothing carries into the next position.
