Coding‑Decoding – Advanced Study Notes
Prepared for the Cisco CCNP Reasoning Ability Module
1. Introduction
Coding‑decoding is a fundamental concept in discrete mathematics, computer science, and information theory. It involves mapping a set of messages (often binary or symbolic strings) into a set of codewords using a coding function (encoder), and retrieving the original message from a received codeword using a decoding function (decoder).
In the context of the CCNP exam, the focus is on:
| Aspect | Why it matters in CCNP |
|---|---|
| Error‑free communication | Network links are noisy; coding ensures integrity. |
| Bandwidth efficiency | Good codes compress data or reduce redundancy. |
| Security | Some codes are also cryptographic primitives. |
2. Formal Foundations
2.1. Alphabets and Strings
- Alphabet ( \Sigma ): Finite non‑empty set of symbols.
Example: ( \Sigma = {0,1} ) for binary strings. - String over ( \Sigma ): Finite sequence ( s = s_1 s_2 \dots s_n ), ( s_i \in \Sigma ).
- Language ( L \subseteq \Sigma^* ): Set of all strings over ( \Sigma ).
2.2. Codes
A code is a function:
[ C : \Sigma^k \to \Gamma^n ]
- (k) – message length.
- (n) – codeword length.
- ( \Gamma ) – code alphabet (often the same as ( \Sigma )).
Properties:
| Property | Definition | Significance |
|---|---|---|
| Injectivity | ( C(m_1) = C(m_2) \implies m_1 = m_2 ) | Ensures unique decodability. |
| Prefix‑free | No codeword is a prefix of another | Allows instantaneous decoding. |
| Linear | ( C(a + b) = C(a) + C(b) ) over a field | Simplifies encoding/decoding. |
| Hamming distance | ( d(C(m_1), C(m_2)) ) | Determines error‑correcting capability. |
2.3. Decoders
Given a received word ( r ), a decoder ( D ) satisfies:
[ D(C(m)) = m \quad \forall m \in \Sigma^k ]
In noisy environments, we use error‑correcting codes where ( D ) maps a corrupted word back to the intended message.
3. From First Principles – Building a Code
3.1. Simple Example: Binary Encoding
Let ( \Sigma = {0,1} ), ( k = 3 ).
| Message | Codeword (identity) |
|---|---|
| 000 | 000 |
| 001 | 001 |
| … | … |
| 111 | 111 |
- Injective – trivial.
- No redundancy – ( n = k ).
- Not error‑correcting – any single bit error changes the codeword to another valid message.
3.2. Adding Redundancy – Hamming(7,4)
- Message length: ( k = 4 ).
- Codeword length: ( n = 7 ).
- Parity bits positioned at indices 1, 2, 4.
3.2.1. Encoding Rule
Let the message bits be ( m = m_1 m_2 m_3 m_4 ).
Compute parity bits:
[ \begin{aligned} p_1 &= m_1 \oplus m_2 \oplus m_4, \ p_2 &= m_1 \oplus m_3 \oplus m_4, \ p_4 &= m_2 \oplus m_3 \oplus m_4. \end{aligned} ]
Codeword: ( c = p_1 p_2 m_1 p_4 m_2 m_3 m_4 ).
3.2.2. Decoding & Error Detection
Compute syndrome ( s = (s_1, s_2, s_4) ) from received word:
[ s_i = \text{parity check for } p_i. ]
- If ( s = 000 ): No error.
- If ( s \neq 000 ): The binary value of ( s ) indicates the position of a single‑bit error (e.g., ( s = 101 ) → error in bit 5). Flip that bit to recover the original codeword.
3.2.3. Hamming Distance
- Minimum Hamming distance ( d_{\min} = 3 ).
- Can detect 2 errors, correct 1 error.
3.3. Edge Cases & Generalization
| Edge Case | Issue | Remedy |
|---|---|---|
| Message length not a power of two | Parity placement tricky | Use systematic linear codes (e.g., Reed–Solomon). |
| High error rates | Hamming(7,4) insufficient | Use stronger codes (BCH, LDPC). |
| Variable‑length messages | Fixed‑size codewords waste space | Prefix‑free or variable‑length codes (Huffman). |
| Unsuitable alphabet | Non‑binary data | Map symbols to binary via symbol expansion or use codes over larger fields (e.g., GF(256)). |
4. Advanced Topics
4.1. Linear Block Codes
- Represented by a generator matrix ( G ) (size ( k \times n )).
- Encoding: ( C(m) = mG ) (row vector times matrix).
- Parity‑check matrix ( H ) (size ( (n-k) \times n )).
Decoding via syndrome ( s = rH^T ).
Example: Hamming(7,4) generator matrix
[ G = \begin{bmatrix} 1 & 0 & 0 & 0 & 1 & 1 & 0 \ 0 & 1 & 0 & 0 & 1 & 0 & 1 \ 0 & 0 & 1 & 0 & 0 & 1 & 1 \ 0 & 0 & 0 & 1 & 1 & 1 & 1 \ \end{