Mathematics · Article
Information theory, coding and complexity
Derive information and coding bounds, calculate real code distances and verify reductions and description-length limits in their precise models.
Back to MathematicsAfter reading, you can
- Derive finite entropy, divergence and mutual information comparisons with their support conditions.
- Construct and compare prefix, uniquely decodable and fixed-length almost-lossless codes.
- Compute two binary channel capacities and use the Fano and random coding arguments.
- Verify Hamming and polynomial evaluation codes, distance bounds and correction limits.
- Build polynomial reductions and check certificates, graph thresholds and the decision-to-search step.
- Prove comparison and description-length limits using exact counting models.
What a bit budget can determine
A finite source assigns probabilities to its outcomes. Their expected information helps determine how many bits a description usually needs. Exact bounds depend on the source model, the permitted codewords and the required decoding rule.
Noise changes the question to which input words a receiver can recover from an altered output. Analyze two binary channels, then calculate the distance and correction guarantees of explicit codes over finite fields.
Computational complexity asks about the cost of finding or checking an answer. Study reductions between concrete graph problems, count the information revealed by comparisons and prove a limit on recovering the shortest universal description.
Derive self-information from independent events
Let I(p) be the information assigned to an event of probability p with 0<p≤1. Demand additivity for independent events, so I(pq)=I(p)+I(q). Take the information to increase as probability decreases, and set I(1/2)=1 bit. Taking q=1 in the additivity rule forces I(1)=0.
For t≥0 define g(t)=I(2^(−t)). The additivity rule becomes g(s+t)=g(s)+g(t), and g(1)=1. Repeating the rule gives g(m)=m for nonnegative integers and then g(m/n)=m/n when m,n are integers with n positive.
For any real t≥0, bound t between rational numbers as close as desired. The assumed monotonicity of the information gives the same bounds for g(t). Since rational g-values are the rational arguments themselves, this forces g(t)=t and thus I(p)=−log₂ p.
For p=1 the event gives zero bits. The function tends to positive infinity as p decreases to zero, so a model assigning zero probability has infinite logarithmic loss at that outcome. In an entropy average a zero-probability term contributes zero, because the probability-weighted expression −p log₂ p tends to zero. Related reading: [Shannon’s entropy and its grouping principle](https://courses.washington.edu/ee420/handouts/shannon1948.pdf), [Finite entropy bounds and information divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/2243edffb30f57181ed97dcb77691580_MIT6_441S16_chapter_1.pdf). Event additivity and monotonicity with a bit normalization determine self-information. A zero-mass term has its continuous probability-weighted limit.
Prove nonnegativity of relative entropy
For probabilities p_x,q_x on a finite alphabet define D₂(P∥Q)=Σ_{x:p_x>0} p_x log₂(p_x/q_x). If some p_x>0 has q_x=0, the divergence is infinite. Otherwise all the ratios used in that sum are positive and it is finite.
For t>0 the function t−1−ln t has its minimum zero at t=1, since its derivative is 1−1/t and changes from negative to positive there. Apply −ln t≥1−t with t=q_x/p_x, multiply by p_x, and sum over p_x>0.
This gives (ln 2)D₂(P∥Q)≥Σ_{p_x>0}(p_x−q_x)=1−Σ_{p_x>0}q_x≥0. The last inequality holds because Q’s total mass is one. Division by ln 2 transfers the result to bits.
If D₂(P∥Q)=0, both inequalities must be equalities. The strictness of the logarithm inequality away from t=1 forces q_x=p_x at every positive p_x, and total mass then forces q_x=0 elsewhere. Conversely Q=P makes every included logarithm zero. This also identifies the exact equality condition with zero support terms present. Related reading: [Finite entropy bounds and information divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/2243edffb30f57181ed97dcb77691580_MIT6_441S16_chapter_1.pdf). The logarithm inequality applies directly on the support of P. An unassigned positive mass gets infinite loss, and equality needs the entire normalized law.
Find entropy bounds and their equality cases
Use the finite entropy H(P)=−Σ_{p_x>0} p_x log₂ p_x. Each summand is nonnegative since p_x≤1. For a positive p_x its summand vanishes exactly when p_x=1, so entropy is zero exactly when one outcome has all the mass.
For an alphabet of size m≥1 the uniform law U assigns 1/m to every symbol. The divergence from P to U expands as D₂(P∥U)=Σ p_x log₂ p_x+log₂ m=log₂ m−H(P), with the sum only over positive p_x.
Nonnegative divergence gives the upper bound H(P)≤log₂ m. The equality condition is P=U on the entire alphabet since that is the equality condition for divergence. If m=1 the point mass is also the uniform law, so both bounds coincide.
Entropy measures average self-information. A deterministic binary input has zero entropy, while the maximum one bit occurs at the uniform binary law.
| Quantity | Exact result |
|---|---|
| P(X=1) | 0 |
| Entropy in bits | 0 |
| Rounded entropy | 0 |
| Distribution | Deterministic |
| Binary masses | 1, 0 |
| Information contributions in bits | 0, 0 |
Exact inputs and supporting calculations
| Parameter | Value |
|---|---|
| p | 0 |
If only s symbols have positive mass, one can run the same comparison with the uniform law on those s symbols. This yields the sharper H(P)≤log₂ s and equality exactly when all supported letters have probability 1/s. Symbols outside that support contribute no entropy. Related reading: [Shannon’s entropy and its grouping principle](https://courses.washington.edu/ee420/handouts/shannon1948.pdf), [Finite entropy bounds and information divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/2243edffb30f57181ed97dcb77691580_MIT6_441S16_chapter_1.pdf). Uniformity maximizes entropy on the declared alphabet. A smaller effective support has its own sharp alphabet bound.
Derive the joint entropy chain rule
For a joint law p(x,y), take p(x)=Σ_y p(x,y). For p(x)>0 define p(y∣x)=p(x,y)/p(x), and define H(Y∣X) as the weighted sum over those x of the entropy of this conditional law. Values x with zero mass have no terms.
Whenever p(x,y)>0, both factors in p(x,y)=p(x)p(y∣x) are positive. Therefore −log₂ p(x,y)=−log₂ p(x)−log₂ p(y∣x). Multiply by p(x,y) and sum over its positive entries.
In the first sum, summing over y at each x gives the contribution −p(x)log₂ p(x). The second sum gives p(x) times the conditional entropy at x, then adds across x. Hence H(X,Y)=H(X)+H(Y∣X).
Apply the two-variable rule successively, taking the earlier coordinates together as the first variable. This gives H(X₁,…,X_n)=Σ_j H(X_j∣X₁,…,X_{j−1}), where the first term is H(X₁). If the variables are independent, each conditional law on a positive-probability history is its marginal and the entropy is the sum of individual entropies. Related reading: [Shannon’s entropy and its grouping principle](https://courses.washington.edu/ee420/handouts/shannon1948.pdf), [Finite entropy bounds and information divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/2243edffb30f57181ed97dcb77691580_MIT6_441S16_chapter_1.pdf). Every conditional logarithm is evaluated on a positive-probability joint entry. Independence gives equal marginal and conditional laws where used.
Express mutual information through a joint law
Define I(X;Y)=H(X)−H(X∣Y). The chain rule expresses this as H(X)+H(Y)−H(X,Y), so it also equals H(Y)−H(Y∣X). This identity uses the same joint law for both two-variable expansions.
At any positive p(x,y), both p(x) and p(y) are positive. The product-law divergence expands into the joint log probability minus the two marginal log probabilities. Summing over joint outcomes gives D₂(P_{X,Y}∥P_X P_Y)=−H(X,Y)+H(X)+H(Y).
Thus I(X;Y) is that divergence, always finite under the given marginals and nonnegative. It is zero exactly when each joint mass equals p(x)p(y) by the divergence equality condition. This includes pairs with zero joint mass.
The product equality is exactly independence of X and Y. As a consequence H(X∣Y)≤H(X), with equality exactly in the independent case. The bound concerns the average conditional entropy over the values of Y, and a single conditional law can have higher entropy than the unconditional law. Related reading: [Finite entropy bounds and information divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/2243edffb30f57181ed97dcb77691580_MIT6_441S16_chapter_1.pdf), [Conditional mutual information and processing](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/184197ca5d5418da2415d37e929860b9_MIT6_441S16_chapter_2.pdf). The product of marginals is positive wherever the joint mass is positive. Equality of that product law is exact independence.
Prove data processing through a Markov channel
For finite variables define I(X;Z∣Y) as the expectation over y with positive probability of the mutual information under the conditional law of X and Z given y. It is nonnegative and vanishes exactly when these conditional joint laws are products. By the entropy formula it equals H(X∣Y)−H(X∣Y,Z).
Using that difference and adding H(X)−H(X∣Y) gives I(X;Y,Z)=I(X;Y)+I(X;Z∣Y). Taking the coordinate Z first instead gives I(X;Y,Z)=I(X;Z)+I(X;Y∣Z). Both expansions concern the same ordered pair of observations as one joint variable.
The Markov condition X→Y→Z means that the law of Z given X,Y depends only on Y on positive-probability conditioning events. This makes X and Z conditionally independent given Y, so I(X;Z∣Y)=0. It follows that I(X;Y)=I(X;Z)+I(X;Y∣Z).
The last term is nonnegative. This proves data processing, and equality holds exactly when X and Y are conditionally independent given Z at every value of Z of positive probability. The argument includes deterministic processing and uses the Markov condition before setting any conditional mutual information to zero. Related reading: [Conditional mutual information and processing](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/184197ca5d5418da2415d37e929860b9_MIT6_441S16_chapter_2.pdf). Data processing uses both orders of the conditional information chain law. Equality tests the remaining dependence given the final output.
Prove the log-sum inequality with zero terms
Take nonnegative finite families (a_i),(b_i) with totals A=Σ_i a_i and B=Σ_i b_i. When A,B are positive and b_i>0 at every positive a_i, let p_i=a_i/A and q_i=b_i/B. Then Σ_i a_i log₂(a_i/b_i)=A log₂(A/B)+A D₂(P∥Q).
Nonnegative divergence gives the log-sum inequality Σ_i a_i log₂(a_i/b_i)≥A log₂(A/B). For positive totals and finite loss, equality holds exactly when the two normalized families coincide, including zero terms.
If A=0 the left side and aggregate term are both interpreted as zero. If A>0 and B=0, the aggregate and at least one summand are infinite. With positive B but a positive a_i paired with b_i=0, the left side is infinite and the right side finite. These are the remaining nonnegative cases.
To merge bins of two probability laws P and Q, apply the inequality separately within each bin, using the original probabilities as weights. Summing over bins gives D₂(P∥Q) at least the divergence between the merged laws. This comparison works for any fixed finite partition, with zero-mass bins treated by the same conventions. Related reading: [Conditional mutual information and processing](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/184197ca5d5418da2415d37e929860b9_MIT6_441S16_chapter_2.pdf), [Total variation and the Pinsker inequality](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/2243edffb30f57181ed97dcb77691580_MIT6_441S16_chapter_1.pdf). Normalize the sums only when positive. Apply the same zero conventions to each bin to obtain the coarse-graining inequality.
Bound total variation by relative entropy
Define TV(P,Q)=(1/2)Σ_x|p_x−q_x|. Let A be the set of x with p_x≥q_x and put a=P(A), b=Q(A). Because the signed differences sum to zero, their positive part has mass TV(P,Q), so a−b=TV(P,Q). Merging into A and its complement can only decrease divergence.
For 0<b<1 and 0<a<1, let f(a)=a ln(a/b)+(1−a)ln((1−a)/(1−b)), the natural-log Bernoulli divergence with b fixed. Direct differentiation gives f(b)=f′(b)=0 and f″(a)=1/a+1/(1−a)=1/(a(1−a))≥4.
Since a≥b, integrate from b to a first to get f′(t)≥4(t−b) for b≤t≤a, and then integrate again to obtain f(a)≥2(a−b)². At a=0 or a=1 use the continuous values given by zero log terms. The same inequality at a=b is immediate.
If b=0 or b=1, either a=b and TV is zero, or the positive mass of one bin where Q has zero gives infinite divergence. Otherwise the two-bin bound in bits is f(a)/(ln 2). Combining it with the merge and a−b=TV proves D₂(P∥Q)≥2TV(P,Q)²/(ln 2). Related reading: [Conditional mutual information and processing](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/184197ca5d5418da2415d37e929860b9_MIT6_441S16_chapter_2.pdf), [Total variation and the Pinsker inequality](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/2243edffb30f57181ed97dcb77691580_MIT6_441S16_chapter_1.pdf). The bin formed by nonnegative mass differences realizes total variation. Natural-log curvature gives the constant, then conversion gives bits.
Decompose the expected logarithmic loss
The expected logarithmic loss of assigning law Q when the true law is P is L(P,Q)=Σ_{p_x>0}p_x(−log₂ q_x). If q_x=0 at any positive p_x, this is infinite. Labels of zero P-mass are omitted from the expectation.
If the loss is finite, write −log₂ q_x=−log₂ p_x+log₂(p_x/q_x) on the support of P. Multiplying by p_x and summing gives L(P,Q)=H(P)+D₂(P∥Q). With a positive-mass zero q_x the same equality holds with infinite loss and divergence.
The entropy does not depend on Q. The divergence is nonnegative, and is zero exactly when P=Q. Thus Q=P uniquely minimizes the expected logarithmic loss over all laws on the finite alphabet.
The equality condition also forbids allocating part of Q’s mass to a symbol outside P’s support when seeking the minimum. In that case the assigned probabilities on the support cannot all equal p_x, since their sum is below one. The minimizer is a law on the whole listed alphabet with zero entries where required. Related reading: [Finite entropy bounds and information divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/2243edffb30f57181ed97dcb77691580_MIT6_441S16_chapter_1.pdf), [Expected code length and divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/67d8e68cd8fda55366e3f9f0a9465c17_MIT6_441S16_chapter_6.pdf). The exact expected log loss separates entropy and divergence. Missing positive support makes both sides infinite and retains the unique finite minimizer.
Prove the finite-alphabet typical-set bounds
Let X₁,…,X_n be independent copies of the same finite law P. On its positive support define the self-information Z_j=−log₂ p(X_j). Its mean is H and its variance v is finite, because only finitely many positive probabilities occur.
The block probability of a supported word x^n is the product of its letter probabilities, so its negative log probability is the sum of the letter self-informations. Fix ε>0 and let A_n consist of supported words for which that sum divided by n lies within ε of H. Independence gives variance v/n for the sample mean.
Chebyshev’s inequality gives P(A_n^c)≤v/(nε²). Thus for any δ>0 the mass of A_n is at least 1−δ for sufficiently large n, including immediate mass one when v=0. Each included word has probability between 2^(−n(H+ε)) and 2^(−n(H−ε)).
Using the lower probability per word with total mass at most one gives |A_n|≤2^(n(H+ε)). Using the upper probability per word with mass at least 1−δ gives |A_n|≥(1−δ)2^(n(H−ε)). A zero-probability letter can never appear in a sampled word and is outside both counts. Related reading: [Shannon’s high-probability long-sequence bound](https://courses.washington.edu/ee420/handouts/shannon1948.pdf), [Typical sets and fixed-length source compression](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/85014cb1add9f415ef38f60f678f16b2_MIT6_441S16_chapter_7.pdf). The block negative log probability is a sum of independent finite self-informations. A tolerance on their mean bounds each typical probability.
Derive a source coding threshold for a fixed bit budget
Fix a target rate R>H for the independent source and choose ε>0 with H+ε<R. Let b_n=⌊nR⌋. For sufficiently large n, b_n≥n(H+ε), so the number 2^(b_n) of binary labels can cover every word in the typical set A_n.
Assign distinct labels to the words of A_n and have the decoder return the attached word for each assigned label. The encoder sends each atypical input to an arbitrary label. Every typical word is decoded exactly, so the error probability is at most P(A_n^c), which tends to zero.
For the converse, a decoder with M possible labels can output at most M distinct source words. Each decodable typical word has probability at most 2^(−n(H−ε)). The total probability of success is consequently at most P(A_n^c)+M 2^(−n(H−ε)), whether or not the encoder actually reaches every label.
If b_n≤nR with R<H, then M≤2^(nR). Choose ε so R<H−ε, and the second term tends to zero exponentially while the first tends to zero by the typical-set bound. Thus the success probability of any such fixed-length budget tends to zero for this independent finite source. Related reading: [Shannon’s high-probability long-sequence bound](https://courses.washington.edu/ee420/handouts/shannon1948.pdf), [Typical sets and fixed-length source compression](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/85014cb1add9f415ef38f60f678f16b2_MIT6_441S16_chapter_7.pdf). The success event of a deterministic decoder includes at most its distinct named words. The count uses the upper individual probability at the chosen cutoff.
Derive the Kraft bound for prefix codes
Let a finite binary prefix code assign distinct strings with lengths ℓ_1,…,ℓ_m. Choose a common depth L at least their maximum length. Codeword i is a prefix of exactly 2^(L−ℓ_i) different binary strings of length L, by free choice of its appended bits.
If two sets of descendants intersected, one length-L string would have both codewords as prefixes. Its two initial segments are comparable by inclusion, so one codeword would be a prefix of the other. That contradicts the prefix condition for distinct codewords.
The descendant sets are thus disjoint inside the whole set of 2^L strings at depth L. Summing their counts and dividing by 2^L gives Σ_i 2^(−ℓ_i)≤1, the Kraft bound for this code.
The empty word has length zero and is a prefix of every binary string. If the code contains it, no other codeword is possible. Its contribution to the Kraft sum is exactly one, consistent with the count for a single empty codeword. Related reading: [Feasible lengths and unique decodability](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/67d8e68cd8fda55366e3f9f0a9465c17_MIT6_441S16_chapter_6.pdf). Distinct prefix descendants at one common depth are disjoint. A zero-length word claims the full binary tree.
Construct a prefix code from feasible lengths
Let 0≤ℓ_1≤⋯≤ℓ_m be the finite ordered integer lengths. Assume their Kraft sum is at most one. Suppose codewords for all preceding indices have already been chosen and are prefix-free.
At depth ℓ_j the earlier word indexed by i excludes exactly 2^(ℓ_j−ℓ_i) binary words because they extend it. The excluded sets are disjoint by prefix-freeness. The partial sum inequality Σ_{i<j}2^(−ℓ_i)+2^(−ℓ_j)≤1 shows the total excluded count is at most 2^ℓ_j−1.
At least one word of the required length therefore remains. Choose any one. It extends no earlier codeword by construction. Because no earlier word is longer, the new word cannot be its proper prefix. If an earlier word has the same length, exclusion already prevented equality.
Each length-ℓ prefix occupies a whole dyadic subtree of measure 2⁻ℓ. Disjoint subtrees prove the Kraft inequality. If the sum fits, greedy lexicographic allocation at sorted lengths leaves room for each next word.
| Quantity | Exact result |
|---|---|
| Lengths in allocation order | (1, 2, 2) |
| Kraft numerator over shared dyadic scale | 4/4 |
| Feasible | True |
| Allocated words | 0, 10, 11 |
| First blocked depth | None |
Exact inputs and supporting calculations
| Parameter | Value |
|---|---|
| lengths | [1,2,2] |
Induct on j to obtain the entire prefix code with the specified lengths. This proof allows ℓ_1=0, in which case the Kraft sum forbids further codewords. When the final Kraft sum is one, the same counting gives exactly complete coverage at any depth beyond all codewords. Related reading: [Feasible lengths and unique decodability](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/67d8e68cd8fda55366e3f9f0a9465c17_MIT6_441S16_chapter_6.pdf). At the required integer depth, earlier words exclude a known disjoint integer number of descendants. The Kraft slack leaves one available word.
Bound the expected length of a prefix code
Use one codeword of length ℓ_x for each symbol x of positive probability p_x. For a prefix code the Kraft sum K=Σ_x2^(−ℓ_x) lies in (0,1]. Let q_x=2^(−ℓ_x)/K, so −log₂ q_x=ℓ_x+log₂ K.
Take the expectation with respect to P. The cross-entropy equation gives Σ_x p_x ℓ_x=H(P)+D₂(P∥Q)−log₂ K. Both added terms are nonnegative. Equality with entropy requires Q=P and K=1, and these conditions suffice.
For a construction choose ℓ_x=⌈−log₂ p_x⌉. Then 2^(−ℓ_x)≤p_x and the Kraft sum is at most one. The feasible-length construction therefore supplies an actual prefix code of these lengths.
For each supported x its length is less than −log₂ p_x+1 and at least −log₂ p_x. Average these inequalities to get H(P)≤Σ_xp_xℓ_x<H(P)+1. A single certain symbol has length zero and satisfies both inequalities under the stated prefix convention. Related reading: [Feasible lengths and unique decodability](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/67d8e68cd8fda55366e3f9f0a9465c17_MIT6_441S16_chapter_6.pdf), [Expected code length and divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/67d8e68cd8fda55366e3f9f0a9465c17_MIT6_441S16_chapter_6.pdf). Normalize code weights to use divergence and keep the remaining Kraft slack term. Shannon lengths give an expected overhead strictly below a bit.
Prove the Huffman merging rule
For m≥2 positive weights choose any finite prefix code to get a finite upper cost L₀. A code of cost at most L₀ gives each leaf length at most L₀ divided by the smallest weight. Only finitely many labelled codes have those bounded lengths, so a minimum exists.
In a minimum, the prefix tree has no node with only one child. Contracting that edge would shorten every leaf below it and strictly decrease the positively weighted cost. Choose a leaf of greatest depth. Its sibling must be another leaf at the same depth, since an internal sibling would contain a deeper leaf.
Assign the two smallest weights to the selected sibling leaves by swapping labels. Putting a smaller weight at a weakly greater depth cannot increase the cost, since the cost change of swapping weights a≤b at depths d≤D is (b−a)(d−D)≤0. Both deepest sibling positions can be filled in this way while keeping any selected least-weight label already in place.
Replace the sibling leaves of weights a,b by their parent with weight a+b. This lowers cost by a+b because each of the two lengths decreases by one in the merged representation. An optimal smaller tree must have cost equal to the merged cost of some optimal larger tree, since expanding a better smaller tree would improve it. Starting with one root leaf and applying this relation proves recursive least-weight merging is optimal. Related reading: [Huffman’s least-weight merging rule](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/67d8e68cd8fda55366e3f9f0a9465c17_MIT6_441S16_chapter_6.pdf). A deepest sibling pair can carry both least positive weights after exchanges. Collapsing the pair subtracts exactly their combined cost.
Derive McMillan’s inequality for uniquely decodable codes
A uniquely decodable code here assigns each source symbol a binary word so that different finite source strings have different concatenated outputs. An empty codeword would let the same output arise from different repetitions of its source symbol, so all lengths are positive for a nonempty source alphabet.
Let the finitely many lengths have minimum a and maximum b. For each k≥1, expand K^k where K=Σ_i2^(−ℓ_i). Every length-k sequence of source symbols contributes 2^(−L) for the length L of its concatenation. Group these terms by L to obtain Σ_{L=ka}^{kb} N_L 2^(−L), where N_L counts these sequences of total length L.
Unique decodability ensures the N_L concatenations are all distinct, and there are only 2^L binary strings of that length. Hence N_L 2^(−L)≤1 for each L. The interval from ka to kb contains k(b−a)+1 integers, giving K^k≤k(b−a)+1.
Taking kth roots and letting k grow makes the right side tend to one, since log(k(b−a)+1)/k tends to zero. Therefore K≤1. The proof uses unique decodability of finite concatenations and does not require an individual codeword to terminate before the next bits are inspected. Related reading: [Feasible lengths and unique decodability](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/67d8e68cd8fda55366e3f9f0a9465c17_MIT6_441S16_chapter_6.pdf). Unique decodability supplies distinct concatenations for every fixed sequence length, with a linear number of possible total lengths.
Amortize the prefix overhead across independent blocks
Treat a block of n independent source letters with the same law P as one symbol on the finite set of supported words. Its probability is a product of its letter probabilities. The entropy chain rule gives H(X₁,…,X_n)=nH(P).
Apply the prefix-code lower bound to this block alphabet, giving expected block length at least nH(P) for any prefix code on it. Apply the Shannon construction to the same exact probability law to obtain a prefix code with expected block length below nH(P)+1.
Divide both comparisons by n. For the constructed code, the expected transmitted bits per source letter lie in [H(P),H(P)+1/n). The construction can use different codeword lengths for different blocks.
This interval is an expectation over the independent source block. It does not impose the same small overhead on the length of each separate realization. The block length n is declared, and in the one-symbol case the sole supported block may be represented by an empty codeword. Related reading: [Finite entropy bounds and information divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/2243edffb30f57181ed97dcb77691580_MIT6_441S16_chapter_1.pdf), [Shannon’s high-probability long-sequence bound](https://courses.washington.edu/ee420/handouts/shannon1948.pdf), [Expected code length and divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/67d8e68cd8fda55366e3f9f0a9465c17_MIT6_441S16_chapter_6.pdf), [Huffman’s least-weight merging rule](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/67d8e68cd8fda55366e3f9f0a9465c17_MIT6_441S16_chapter_6.pdf). The full independent block has entropy nH. Expected overhead per letter follows after applying the actual prefix construction to the block law.
Find the capacity of a binary symmetric channel
Let X be a binary input with P(X=1)=p. A binary symmetric channel of crossover probability ε produces Y=X⊕N where N is independent with P(N=1)=ε. For either value of X, the entropy of Y given that value is h₂(ε), where h₂(p)=−p log₂ p−(1−p) log₂(1−p), using the zero-term convention.
The output has probability P(Y=1)=p(1−ε)+(1−p)ε. Hence I(X;Y)=h₂(p(1−ε)+(1−p)ε)−h₂(ε). The first entropy is at most one bit because the output alphabet has two values.
Taking p=1/2 makes the output fair for every ε in [0,1] and attains the upper bound. The maximum over input laws, called the single-use capacity, is therefore 1−h₂(ε) bits. If ε differs from 1/2, a fair output in this parametrization requires p=1/2.
For the BSC with independent noise, H(Y|X)=H₂(p). Uniform input maximizes H(Y) at one bit, so capacity is 1−H₂(p).
| Quantity | Exact result |
|---|---|
| Crossover p | 0 |
| Noise entropy | 0 |
| Capacity in bits per use | 1 |
| Uniform-input output law | Bernoulli 1/2 |
| Achieving input | Uniform |
Exact inputs and supporting calculations
| Parameter | Value |
|---|---|
| p | 0 |
For ε=0 the output equals the input and for ε=1 it is its complement, both with capacity one bit. At ε=1/2 the output is independent of X for every p and capacity is zero. The capacity expression also treats ε>1/2 because complementing the output changes the crossover to 1−ε. Related reading: [Finite entropy bounds and information divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/2243edffb30f57181ed97dcb77691580_MIT6_441S16_chapter_1.pdf), [Binary symmetric and erasure capacity](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/f417578e714d472cb08d463825e45f03_MIT6_441S16_chapter_16.pdf), [A weak converse for reliable channel codes](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/8d9b42a8d43e28ca4a75e09fb4a89371_MIT6_441S16_chapter_14.pdf). The symmetric flip contributes h₂(ε) conditional output entropy. A fair input attains the unit upper bound on output entropy.
Find the capacity of a binary erasure channel
An erasure channel outputs either the true input bit or a distinct erasure symbol. The erasure indicator is independent of X and has probability ε. On any non-erased output of positive probability, the conditional input law is concentrated on that revealed bit.
Given the erasure symbol with positive probability, the input law is its original law by independence. Conditional entropy therefore averages zero over non-erased outputs and H(X) over the erasure, giving H(X∣Y)=ε H(X).
Mutual information is H(X)−H(X∣Y)=(1−ε)H(X). Input entropy is at most one and a fair bit attains one. Thus the maximum possible information over input probabilities is 1−ε bits.
A revealed output determines the input while an independently erased output leaves the input law unchanged. Thus H(X|Y)=εH₂(p), and the uniform input reaches capacity 1−ε.
| Quantity | Exact result |
|---|---|
| Erasure probability | 1/4 |
| Input p | 1/2 |
| Mutual information in bits | 0.75 |
| Rounded mutual information | 0.75 |
| Capacity in bits per use | 0.75 |
Exact inputs and supporting calculations
| Parameter | Value |
|---|---|
| epsilon | 1/4 |
| p | 1/2 |
At ε=0 the erasure term has zero weight and the input is always revealed. At ε=1 the output is a constant erasure and the information is zero for every input. These cases follow with conditional distributions evaluated only at outputs of positive probability. Related reading: [Finite entropy bounds and information divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/2243edffb30f57181ed97dcb77691580_MIT6_441S16_chapter_1.pdf), [Binary symmetric and erasure capacity](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/f417578e714d472cb08d463825e45f03_MIT6_441S16_chapter_16.pdf). Here the probability of erasure does not depend on the input. The conditional input law is unchanged on that event and determined on the other.
Establish the finite-alphabet Fano bound
Let X take values in an M-element alphabet with M≥2, and let a deterministic decision rule choose an alphabet symbol x̂(Y) from observation Y. Put E=1 when x̂(Y) differs from X and let P_e=P(E=1). The indicator E is determined by the pair X,Y.
Apply the conditional entropy chain rule in the two orders. Since H(E∣X,Y)=0, it gives H(X∣Y)=H(X,E∣Y)=H(E∣Y)+H(X∣E,Y). The first term is at most H(E)=h₂(P_e).
For E=0 and a given Y of positive joint probability, X equals its decoded value, with conditional entropy zero. For E=1 and fixed Y it lies in at most M−1 possible symbols. The entropy bound on that conditional law is log₂(M−1). Averaging yields H(X∣E,Y)≤P_e log₂(M−1).
Combining gives H(X∣Y)≤h₂(P_e)+P_e log₂(M−1). When M=1 the variable and the only valid decoded symbol are both certain, so H(X∣Y)=0 and P_e=0 directly. This handles the one-symbol case before using a logarithm of M−1. Related reading: [Finite entropy bounds and information divergence](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/2243edffb30f57181ed97dcb77691580_MIT6_441S16_chapter_1.pdf), [Binary symmetric and erasure capacity](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/f417578e714d472cb08d463825e45f03_MIT6_441S16_chapter_16.pdf), [The Fano conditional uncertainty bound](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/b208f091f76052d60eda895dc8d13e97_MIT6_441S16_chapter_5.pdf). Use the binary error indicator in the conditional chain rule. A wrong in-alphabet decision leaves at most M−1 possible values.
Prove the weak converse for memoryless channel codes
Let W be uniform on M≥2 messages, and let a fixed deterministic encoder send the word X^n=x^n(W) through a memoryless channel. Conditional on each message, the output coordinates are independent with the channel laws at the specified input letters. Averaging the conditional chain rule gives H(Y^n∣W)=Σ_{j=1}^n H(Y_j∣X_j).
The unconditional output chain rule and the fact that conditioning can only reduce entropy on average give H(Y^n)≤Σ_j H(Y_j). Subtraction yields I(W;Y^n)≤Σ_j I(X_j;Y_j)≤nC, where C is the maximum one-use mutual information for the given channel.
For any deterministic message decision based on Y^n, Fano gives H(W∣Y^n)≤h₂(P_e)+P_e log₂(M−1)≤1+P_e log₂ M. Since H(W)=log₂ M, we have log₂ M=I(W;Y^n)+H(W∣Y^n)≤nC+1+P_e log₂ M.
Writing R=(log₂ M)/n gives nR(1−P_e)≤nC+1. For rates bounded below by a positive R₀>C, the bound implies that the average error stays away from zero for sufficiently large n. A singleton message set has rate zero and fits the bound directly. Related reading: [Conditional mutual information and processing](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/184197ca5d5418da2415d37e929860b9_MIT6_441S16_chapter_2.pdf), [Binary symmetric and erasure capacity](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/f417578e714d472cb08d463825e45f03_MIT6_441S16_chapter_16.pdf), [The Fano conditional uncertainty bound](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/b208f091f76052d60eda895dc8d13e97_MIT6_441S16_chapter_5.pdf), [A weak converse for reliable channel codes](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/8d9b42a8d43e28ca4a75e09fb4a89371_MIT6_441S16_chapter_14.pdf). For a deterministic code over a memoryless channel, one-letter conditional output entropies sum. Fano bounds the finite uniform message remainder.
Prove a random coding bound for the binary symmetric channel
For a binary symmetric channel write Y^n=X^n⊕N^n with N^n consisting of independent crossover bits. Take 0<R<1−h₂(ε) and choose δ>0 with R+h₂(ε)+δ<1. Let A_n be the typical set of noise strings with P(N^n∉A_n) tending to zero and |A_n|≤2^(n(h₂(ε)+δ)).
Choose M=⌊2^(nR)⌋ ordered distinct binary words uniformly without replacement. The decoder declares the index whose codeword x satisfies Y^n⊕x∈A_n when this index is unique. For other outputs it chooses a fixed default index. The transmitted index is eligible whenever the actual noise is in A_n.
Condition on the transmitted codeword and the noise. Each individual other word is uniform on the 2^n−1 strings different from that transmitted word, since the random codebook and noise are independent. Its chance of eligibility is at most |A_n|/(2^n−1), because x↦Y^n⊕x is a bijection. The union bound needs no independence between competing words.
The average over codebooks, messages and noise of the error probability is at most P(N^n∉A_n)+(M−1)|A_n|/(2^n−1), which tends to zero by the choice of δ. For each n some fixed codebook has at most that average error. Its rate tends to R. Rate zero can use one message, and when capacity is zero there is no positive R under the assumed inequality. Related reading: [Shannon’s high-probability long-sequence bound](https://courses.washington.edu/ee420/handouts/shannon1948.pdf), [Typical sets and fixed-length source compression](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/85014cb1add9f415ef38f60f678f16b2_MIT6_441S16_chapter_7.pdf), [Binary symmetric and erasure capacity](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/f417578e714d472cb08d463825e45f03_MIT6_441S16_chapter_16.pdf), [Random channel coding and existence of a fixed code](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/83c18c0b0ff3d650e8734b7bc678a2fd_MIT6_441S16_chapter_15.pdf). The random codebook uses distinct words. A conditioned competitor is uniform among the other words, and a union bound controls all competitors.
Derive the Hamming sphere-packing inequality
For an alphabet of size q≥2 and one fixed word x of length n, a word at distance j from x is obtained by choosing j coordinates and replacing each with one of its q−1 other letters. This gives (n choose j)(q−1)^j possibilities, and different choices yield different words.
The radius-t ball of x thus contains V_q(n,t)=Σ_{j=0}^t (n choose j)(q−1)^j words for 0≤t≤n. Its size is independent of x. Each counted word agrees with x outside the chosen coordinates.
If a word lay within distance t of two distinct codewords x,y, the Hamming triangle inequality would give d(x,y)≤2t. That inequality follows coordinatewise because a difference between x and y requires at least one difference in the two comparisons with the intervening word.
Thus a code with pairwise distances at least 2t+1 has disjoint radius-t balls in the q^n total words. For size M the count gives M V_q(n,t)≤q^n. The conclusion is a necessary count on such codes. Related reading: [Single-error correcting binary codes and distance](https://zoo.cs.yale.edu/classes/cs323/doc/Hamming.pdf), [Hamming packing and the Singleton bound](https://www.cs.cmu.edu/~venkatg/teaching/codingtheory/notes/notes4.pdf). Count a substitution by its chosen coordinates and new symbols. A distance of at least twice the radius plus one prevents overlap.
Relate minimum distance to detection and correction
Let the code contain at least two words and have minimum distance d. Changing at least one and at most d−1 positions of a transmitted word cannot produce another codeword, by the definition of minimum distance. A decoder that checks whether the received word is in the code detects all these substitutions.
There are two codewords at distance exactly d because the code is finite. Changing the differing coordinates of the first to those of the second yields an undetected transmission error with d substitutions. This proves the stated detection guarantee is sharp.
Let t=⌊(d−1)/2⌋. A received word at distance at most t of the sent word cannot lie within t of any other codeword, since that would imply a codeword distance at most 2t<d. Choosing the unique such codeword corrects every error in this radius.
The distance guarantees quantify over every transmitted word and all errors of the stated weight. Actual nearest-neighbor uniqueness for one received input is a separate computation.
| Quantity | Exact result |
|---|---|
| Minimum pairwise distance | 3 |
| Guaranteed detected errors | 2 |
| Guaranteed uniquely corrected errors | 1 |
| Nearest distance | 1 |
| Closest words | 000 |
| Unique nearest neighbor | True |
Exact inputs and supporting calculations
| Parameter | Value |
|---|---|
| words | ["000","111"] |
| received | 010 |
| First | Second | Hamming distance |
|---|---|---|
| 000 | 111 | 3 |
Take a pair of codewords at distance d and form a received word that agrees with the first on ⌊d/2⌋ of their differing positions and the second on the rest, keeping all common positions. The two distances are ⌊d/2⌋ and ⌈d/2⌉. Both are at most t+1, so a single decision cannot correct both possible transmissions at that next radius. Related reading: [Single-error correcting binary codes and distance](https://zoo.cs.yale.edu/classes/cs323/doc/Hamming.pdf), [Hamming packing and the Singleton bound](https://www.cs.cmu.edu/~venkatg/teaching/codingtheory/notes/notes4.pdf). Construct a distance-d pair for failure of detection, and split its differing positions to show the next correction radius can fail.
Describe a linear code by its syndrome
Let H be an r-by-n matrix over the finite field 𝔽_q and set C={c∈𝔽_q^n:Hc=0}. It is a linear subspace of dimension n−rank H by rank-nullity. A basis of that dimension gives exactly q^(n−rank H) distinct codewords.
For any two words c,c′ their Hamming distance is the number of nonzero coordinates of c−c′, its Hamming weight. If c and c′ are distinct codewords, c−c′ is a nonzero word of C. Each nonzero word of C occurs as such a difference by taking c′=0.
Consequently for a code with at least two words, its minimum distance equals the minimum weight of a nonzero element of C. The zero code contains no distinct pair, so its dimension and syndrome statements apply without a finite pairwise minimum distance.
A syndrome describes a coset modulo the code. Equal columns give different one-bit errors with the same syndrome, and a unique one-bit candidate need not be the actual channel error.
| Quantity | Exact result |
|---|---|
| Received r | 101 |
| Observed Hr | (0, 1) |
| Single-bit candidates | 1 |
| Kernel codewords | 000, 111 |
| Unique among single-bit errors | True |
| Row parity terms | (1+1, 0+1) modulo 2 |
| Zero comparison at r=000 | Compatible errors 000 and 111. |
Exact inputs and supporting calculations
| Parameter | Value |
|---|---|
| H | [[1,0,1],[0,1,1]] |
| r | [1,0,1] |
| Index | Syndrome |
|---|---|
| 0 | (1, 0) |
| 1 | (0, 1) |
| 2 | (1, 1) |
| Error e | Candidate codeword r+e | Weight |
|---|---|---|
| 010 | 111 | 1 |
| 101 | 000 | 2 |
If the received word is y=c+e, the syndrome Hy equals He. Two errors e,e′ have the same syndrome exactly when H(e−e′)=0, which means their difference lies in C. Thus a syndrome identifies the corresponding coset of possible errors, and unique decoding on a chosen error class requires at most one representative per syndrome. Related reading: [Linear code and parity-check representations](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/f417578e714d472cb08d463825e45f03_MIT6_441S16_chapter_16.pdf). Rank gives the null code dimension. The syndrome identifies a coset, with unique error recovery only on a selected set of distinct representatives.
Construct and decode a binary Hamming code
Fix r≥2 and use all 2^r−1 distinct nonzero length-r column vectors over 𝔽₂ as the columns of H. They include each coordinate vector, so rank H=r. The binary code C=ker H then has length n=2^r−1 and dimension n−r.
No codeword of weight one exists because every column is nonzero. No weight-two word lies in the kernel because two distinct columns cannot sum to zero in characteristic two. Choose two distinct nonzero columns. Their sum is nonzero and differs from both, so the third column at that sum gives a weight-three kernel word with the first two.
This proves minimum distance three. The zero error has zero syndrome and a single-bit error at position j has the corresponding nonzero column as its syndrome. Every nonzero syndrome occurs at exactly one position, so flipping that position corrects every single-bit error.
Every received word has either zero syndrome and already lies in the code, or has the syndrome of one bit and becomes a codeword after that correction. The radius-one balls are therefore disjoint and cover the whole space. Their count is 2^(n−r)(1+n)=2^n, giving equality in sphere packing. Related reading: [Single-error correcting binary codes and distance](https://zoo.cs.yale.edu/classes/cs323/doc/Hamming.pdf), [Linear code and parity-check representations](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/f417578e714d472cb08d463825e45f03_MIT6_441S16_chapter_16.pdf), [Hamming packing and the Singleton bound](https://www.cs.cmu.edu/~venkatg/teaching/codingtheory/notes/notes4.pdf). All nonzero binary columns give rank r and distance three. Each syndrome selects the zero error or exactly one coordinate change.
Find an explicit double-error decoding failure
Let the transmitted codeword be c and let the error flip exactly two distinct positions i,j. The received word is y=c+e_i+e_j, with e_i,e_j the corresponding coordinate vectors. Its syndrome is s=h_i+h_j where h_i,h_j are the two columns.
The columns are distinct and nonzero. Their sum is nonzero, because equality of two binary columns would be needed for zero. It also differs from h_i and h_j, since equaling one would force the other to be zero. Thus s corresponds to a third index k.
The single-error decoder flips k and outputs c′=c+e_i+e_j+e_k. The new syndrome is h_i+h_j+h_k=s+s=0, so c′ is a codeword. It differs from c in the three distinct coordinates i,j,k.
The received word lies at distance two from c and distance one from c′. This gives a concrete failure of the radius-one decoder on a two-bit error. A test for nonzero syndrome alone still flags the original received word as having a transmission error. Related reading: [Single-error correcting binary codes and distance](https://zoo.cs.yale.edu/classes/cs323/doc/Hamming.pdf), [Linear code and parity-check representations](https://ocw.mit.edu/courses/6-441-information-theory-spring-2016/f417578e714d472cb08d463825e45f03_MIT6_441S16_chapter_16.pdf). The sum of two distinct nonzero binary columns equals a third. A decoder for one error then flips that third coordinate.
Prove the Singleton bound by puncturing
Let a finite q-ary code of length n have at least two words and minimum distance d. Then 1≤d≤n. Choose any common set of d−1 coordinate positions to remove from every word. The remaining words have length n−d+1.
If two distinct original words were identical after deletion, their differing positions would all lie among the d−1 removed ones. Their Hamming distance would then be at most d−1, contrary to the minimum distance.
Thus the puncture sends the code injectively into the set of all q^(n−d+1) remaining strings. Counting gives M≤q^(n−d+1), the Singleton bound. No linear structure was used to count the target.
For a linear [n,k] code over 𝔽_q of dimension k≥1, its cardinality is q^k. Taking logarithms base q gives k≤n−d+1, or d≤n−k+1. A singleton code has no pairwise distance to substitute and is outside this use of d. Related reading: [Hamming packing and the Singleton bound](https://www.cs.cmu.edu/~venkatg/teaching/codingtheory/notes/notes4.pdf), [Reed–Solomon distances by polynomial evaluation](https://www.cs.cmu.edu/~venkatg/teaching/codingtheory/notes/notes6.pdf). Deleting d−1 common coordinates is injective on a code of minimum distance d. The surviving positions supply the size bound.
Build an evaluation code that meets the Singleton bound
Fix a finite field 𝔽_q and integers 1≤k≤n≤q. Choose n distinct evaluation points α₁,…,α_n. For every polynomial f of degree less than k, including zero, form the length-n word (f(α₁),…,f(α_n)). Evaluation is linear in the coefficients.
A nonzero difference polynomial h of degree at most k−1 has at most k−1 distinct roots. Indeed each root yields a linear factor by polynomial division, and removing such a factor leaves a quotient that vanishes at every other distinct root because the removed factor is nonzero there. Each removal reduces the degree by one. Therefore the evaluated words of two distinct polynomials differ at at least n−k+1 points.
This proves injectivity and gives q^k words because the k coefficients are independently chosen. To attain the distance bound, choose h as the product of k−1 factors x−α_j using distinct chosen evaluation points. It has exactly those roots among the evaluation points and none at any other because the field has no zero divisors.
Comparing h’s word with the zero word gives distance n−k+1. For k=1 the empty product is the constant 1 and differs from zero at all n points. Thus the minimum is exact and the code size reaches q^(n−d+1) in the Singleton bound. Related reading: [Hamming packing and the Singleton bound](https://www.cs.cmu.edu/~venkatg/teaching/codingtheory/notes/notes4.pdf), [Reed–Solomon distances by polynomial evaluation](https://www.cs.cmu.edu/~venkatg/teaching/codingtheory/notes/notes6.pdf). A nonzero degree-less-than-k difference has at most k−1 roots. The chosen product attains that count on distinct evaluation points.
Compare deterministic algorithms and verifiable certificates
Fix standard finite binary encodings of instances. The class P consists of decision languages with deterministic procedures using at most polynomially many steps in input length. The class NP here consists of languages with a deterministic polynomial-time verifier V, and a polynomial p bounding certificate length, such that x belongs exactly if some binary y with |y|≤p(|x|) makes V accept.
If a language already has a polynomial-time decision procedure, define its verifier to run that procedure on x and ignore the certificate. The empty certificate works on every yes instance and no certificate works on a no instance. This proves P⊆NP.
For any given NP verifier, enumerate all binary strings of length up to p(n), where n is the input length, and run V on each. The defining equivalence implies the procedure accepts exactly if it finds a successful certificate. After a finite exhaustion with none, it rejects.
There are Σ_{j=0}^{p(n)}2^j=2^(p(n)+1)−1 possible certificates when p(n) is an integer bound. Each verification uses time polynomial in n+p(n), as does bookkeeping for an individual candidate. This shows decidability by an exhaustive procedure with the stated exponential-in-the-certificate-bound cost, without asserting that enumeration is necessary for any particular language. Related reading: [Polynomial-time reductions and the literal-occurrence graph](https://introtcs.org/public/lec_12_NP.html), [Clique certificates, independent sets and covers](https://courses.cs.washington.edu/courses/cse431/25wi/notes/lectures-19-20.pdf), [The Cook–Levin route to 3SAT hardness](https://introtcs.org/public/lec_13_Cook_Levin.html). For NP use a verifier and its polynomial certificate length. Enumeration gives a finite bound and the trivial verifier gives inclusion of P.
Compose polynomial many-one reductions
A polynomial many-one reduction from A to B is a deterministic polynomial-time transformation f on the encoded input such that x∈A exactly when f(x)∈B. Suppose f reduces A to B and g reduces B to C. Their composite satisfies x∈A if and only if f(x)∈B if and only if g(f(x))∈C.
If f runs for at most p(n) steps on an input of length n, it writes at most p(n) output bits in the ordinary finite-alphabet computation model. If g uses at most q(m) steps for inputs of length m, take a nondecreasing polynomial upper bound for q and bound its time by q(p(n)). The total is polynomial in n.
If B has a polynomial-time decision algorithm, apply it to f(x), after computing f. The same output-length argument bounds the decision time and the reduction preserves the answer. Thus A is in P whenever A reduces to B and B is in P.
If A is NP-hard, every NP language L has such a reduction to A. Composing each L-to-A map with f shows every L in NP reduces to B, so B is NP-hard. The hardness conclusion follows the forward direction of the reduction, and membership in NP is a separate certificate check for B. Related reading: [Polynomial-time reductions and the literal-occurrence graph](https://introtcs.org/public/lec_12_NP.html), [The Cook–Levin route to 3SAT hardness](https://introtcs.org/public/lec_13_Cook_Levin.html). The encoded length of a reduction’s output is bounded by its running time. This preserves composition and orients hardness correctly.
Reduce a three-literal formula to a clique decision
Let a 3-CNF formula have m clauses. Make a separate graph vertex for each literal occurrence, recording its clause, variable and sign. Join two vertices by an undirected edge exactly when they come from different clauses and the two literals are not complementary occurrences of the same variable. The target clique size is m.
If a truth assignment satisfies the formula, choose one true literal occurrence in each clause. Different chosen vertices are in different clauses, and two complementary literals cannot both be true. Each pair is therefore a graph edge, giving a clique of size m.
Conversely, a clique of size at least m has at most one vertex per clause because there are no edges within a clause. It has one from each clause. Its literal choices contain no complementary pair, so set the variables they mention to make all chosen literals true and assign any remaining variables arbitrarily. Every clause is then satisfied.
There are at most 3m vertices, and all pairs can be checked for clause, variable and sign in polynomial time in the formula encoding. Handling the empty conjunction uses m=0 and the empty clique. This is a polynomial reduction from 3-SAT to CLIQUE. Given the standard NP-completeness of 3-SAT and a polynomial verifier for cliques, it yields the NP-completeness of CLIQUE. Related reading: [Polynomial-time reductions and the literal-occurrence graph](https://introtcs.org/public/lec_12_NP.html), [Clique certificates, independent sets and covers](https://courses.cs.washington.edu/courses/cse431/25wi/notes/lectures-19-20.pdf), [The Cook–Levin route to 3SAT hardness](https://introtcs.org/public/lec_13_Cook_Levin.html). Use a vertex for every literal occurrence. A valid clique selects one consistent literal in every clause, with the 3SAT hardness premise identified.
Relate clique and independent set by graph complementation
For a finite simple graph G on vertex set V, its complement Ḡ has the same vertices and the opposite adjacency relation on every pair of distinct vertices. Neither graph has loops. For an explicit adjacency matrix, checking and replacing each off-diagonal entry takes polynomial time in the input size.
A set S⊆V is a clique of G when every two different members are adjacent in G. This is exactly the condition that no two distinct members are adjacent in Ḡ, which is the definition of an independent set there. Complementing the graph twice restores G.
The size of S is unchanged, so the same threshold k gives both reductions between CLIQUE and INDEPENDENT SET. If k exceeds |V| both answers are no, and the empty set handles k=0 in both problems. These conventions preserve the decision at the extremes.
A certificate lists k distinct vertices, which is polynomial in the input size for 0≤k≤|V|. Check the distinctness and each of the k(k−1)/2 pairs, requiring adjacency for a clique and its absence for independence. If a larger set exists it has a k-element subset of the same type. Thus these are polynomial verifiers for the at-least decisions. Related reading: [Polynomial-time reductions and the literal-occurrence graph](https://introtcs.org/public/lec_12_NP.html), [Clique certificates, independent sets and covers](https://courses.cs.washington.edu/courses/cse431/25wi/notes/lectures-19-20.pdf), [The Cook–Levin route to 3SAT hardness](https://introtcs.org/public/lec_13_Cook_Levin.html). Complement edges only on distinct vertices. The threshold and both certificate checks use the same explicit graph and vertex set.
Reduce independent set to vertex cover with the correct budget
Let S be a vertex subset in a finite simple graph, and let T=V∖S. If S is independent, no edge has both endpoints in S. Hence every edge has at least one endpoint in T, so T is a vertex cover.
Conversely, if T is a vertex cover then every edge meets T. No edge can have both endpoints in V∖T, so that complement is independent. The two operations are inverse and |T|=n−|S| for n vertices.
For 0≤k≤n, an independent set of size at least k exists exactly when a vertex cover of size at most n−k exists. The reduction keeps the graph and replaces k by n−k. For k>n, the input is a no instance and can be mapped to a fixed no instance, for example one edge with cover budget zero.
Computing n−k and copying the explicit graph take polynomial time in the input length. A proposed cover is verified by its size and a check that each edge has an endpoint in it. In combination with the graph complement reduction and the known 3-SAT hardness used for cliques, this gives NP-completeness for vertex cover. Related reading: [Clique certificates, independent sets and covers](https://courses.cs.washington.edu/courses/cse431/25wi/notes/lectures-19-20.pdf), [The Cook–Levin route to 3SAT hardness](https://introtcs.org/public/lec_13_Cook_Levin.html). Taking a complementary vertex set converts size at least k to size at most n−k, with a fixed no target outside the valid budget.
Recover a clique with a decision procedure
Suppose a polynomial-time decision routine tells whether an explicit graph contains a clique of size at least r. Start by asking whether the input graph contains a clique of the requested size k. Return failure if it does not. For k=0 the empty set is already a valid output.
For a remaining graph H known to have a clique of size r≥1, test each vertex v by asking whether the subgraph induced by its neighbours in H has a clique of size at least r−1. A vertex of any size-r clique passes this test because its other members are pairwise adjacent neighbours.
Choose a passing vertex, append it to the output and replace H by that induced neighbour subgraph. Decrease r by one. Each vertex in the new H is adjacent to the selected vertex and to all earlier selections, by the previously maintained restriction. The passing decision preserves the existence of the needed clique in the new H.
After k choices the selected vertices are distinct and pairwise adjacent, with the required count. No pass can fail when the invariant holds. Each step makes at most n tests on graphs with at most n vertices, so at most kn additional queries and polynomial graph construction suffice, with k≤n in the yes case. Related reading: [Polynomial-time reductions and the literal-occurrence graph](https://introtcs.org/public/lec_12_NP.html), [Clique certificates, independent sets and covers](https://courses.cs.washington.edu/courses/cse431/25wi/notes/lectures-19-20.pdf), [The Cook–Levin route to 3SAT hardness](https://introtcs.org/public/lec_13_Cook_Levin.html). The remaining graph contains a clique of the requested remaining size, and restricting to chosen neighbours keeps all earlier adjacencies.
Derive a comparison-sorting lower bound by counting leaves
Model deterministic comparison sorting of n distinct keys as a binary decision tree. The keys are opaque items and their relative order is learned only through comparisons. Each leaf specifies the order in which the algorithm outputs the original input positions.
Every strict total order of the n input positions can occur, giving n! possibilities. Two different orders require different correct output permutations of positions. They cannot follow the same leaf, because that leaf supplies one permutation.
A binary tree of maximum depth d has at most 2^d leaves. This follows by induction, or by assigning disjoint sets of full-depth binary strings to its distinct leaf paths. Therefore 2^d≥n! and d≥⌈log₂(n!)⌉.
For n≥2 at least ⌊n/2⌋ of the factors in n! are at least n/2. Consequently log₂(n!)≥⌊n/2⌋ log₂(n/2), yielding a worst-case lower bound of order n log n. The inference is for the stated comparison model, in which each binary decision reveals a comparison outcome. Related reading: [Binary comparison trees and sorting](https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/78a3c3444de1ff837f81e52991c24a86_MIT6_006S20_lec5.pdf). A leaf for distinct opaque keys must specify an output permutation. There are n! such permutations and at most 2^d leaves at depth d.
Count strings that are incompressible by a fixed decoder
Fix a partial decoder D that takes a finite binary description and, when defined, outputs one finite binary string. Write C_D(x) for the minimum input length that yields x, using infinity if no input yields it. Fix integers n≥0 and 0≤c≤n.
There are Σ_{j=0}^{n−c−1}2^j=2^(n−c)−1 input strings of length less than n−c, with this count zero when the upper limit is negative. Each description contributes at most one output, and some contribute no output or duplicate outputs.
Among the 2^n strings of length n, at most 2^(n−c)−1 can thus be decoded from such a short input. At least 2^n−2^(n−c)+1 have C_D(x)≥n−c, with equality in the bound only possible when every short input contributes a distinct n-bit output.
Under the uniform distribution on n-bit strings, the probability of that lower bound on description length is at least 1−2^(−c)+2^(−n). This is a counting statement for the specified decoder and length range. It does not identify a particular output as having large description length. Related reading: [Counting short binary descriptions](https://homepages.cwi.nl/~paulv/papers/sorting.pdf), [Why shortest universal description length is incomputable](https://homepages.cwi.nl/~paulv/papers/incomp.pdf). Each short description supplies at most one output. Count all shorter strings, including length zero, to bound the number of possible short representations.
Prove universal description length is not computable
Let U be the fixed universal partial decoder and C_U(x) its shortest description length. Universality supplies finite descriptions of every finite string and a fixed-size simulation prefix for each particular effective routine. Suppose C_U were computable as a function of x.
With c=0 the counting bound ensures at least one n-bit string has C_U(x)≥n. Using the assumed decision procedure for C_U, a fixed routine on input n can check the finitely many n-bit strings in lexicographic order and output the first one satisfying this inequality. It always halts.
For n≥1 encode its ordinary binary digits of length ℓ with a unary length prefix of ℓ ones followed by a zero, then those ℓ digits. This encoding has length 2ℓ+1. A fixed U simulation prefix and this encoding together describe the selected string, since the routine reconstructs n and conducts the search.
The resulting length is at most a fixed constant plus 2⌊log₂ n⌋+3, strictly below n for sufficiently large n. This contradicts how the selected string was chosen. The argument concerns the exact description-length function for the fixed universal decoder. Related reading: [Counting short binary descriptions](https://homepages.cwi.nl/~paulv/papers/sorting.pdf), [Why shortest universal description length is incomputable](https://homepages.cwi.nl/~paulv/papers/incomp.pdf). The procedure from the assumed exact solver yields a computable search with a short encoded index. A fixed simulation prefix yields the contradiction.
Compare exact information measures, prefix allocations, binary channels, errors and syndromes.
Compare exact binary-law cases and entropy extrema
Deterministic Bernoulli input: p=0
Entropy measures average self-information. A deterministic binary input has zero entropy, while the maximum one bit occurs at the uniform binary law.
| Quantity | Exact result |
|---|---|
| P(X=1) | 0 |
| Entropy in bits | 0 |
| Rounded entropy | 0 |
| Distribution | Deterministic |
| Binary masses | 1, 0 |
| Information contributions in bits | 0, 0 |
Exact inputs and supporting calculations
| Parameter | Value |
|---|---|
| p | 0 |
Use dyadic tree slots to construct or reject a code
Lengths fill the binary tree exactly
Each length-ℓ prefix occupies a whole dyadic subtree of measure 2⁻ℓ. Disjoint subtrees prove the Kraft inequality. If the sum fits, greedy lexicographic allocation at sorted lengths leaves room for each next word.
| Quantity | Exact result |
|---|---|
| Lengths in allocation order | (1, 2, 2) |
| Kraft numerator over shared dyadic scale | 4/4 |
| Feasible | True |
| Allocated words | 0, 10, 11 |
| First blocked depth | None |
Exact inputs and supporting calculations
| Parameter | Value |
|---|---|
| lengths | [1,2,2] |
Compare BSC capacities across crossover probabilities
Identity channel with zero crossover
For the BSC with independent noise, H(Y|X)=H₂(p). Uniform input maximizes H(Y) at one bit, so capacity is 1−H₂(p).
| Quantity | Exact result |
|---|---|
| Crossover p | 0 |
| Noise entropy | 0 |
| Capacity in bits per use | 1 |
| Uniform-input output law | Bernoulli 1/2 |
| Achieving input | Uniform |
Exact inputs and supporting calculations
| Parameter | Value |
|---|---|
| p | 0 |
Count the symbols that reveal their input
Uniform input and quarter erasure
A revealed output determines the input while an independently erased output leaves the input law unchanged. Thus H(X|Y)=εH₂(p), and the uniform input reaches capacity 1−ε.
| Quantity | Exact result |
|---|---|
| Erasure probability | 1/4 |
| Input p | 1/2 |
| Mutual information in bits | 0.75 |
| Rounded mutual information | 0.75 |
| Capacity in bits per use | 0.75 |
Exact inputs and supporting calculations
| Parameter | Value |
|---|---|
| epsilon | 1/4 |
| p | 1/2 |
Compute all distances and expose decoding ties
One nearest repetition word
The distance guarantees quantify over every transmitted word and all errors of the stated weight. Actual nearest-neighbor uniqueness for one received input is a separate computation.
| Quantity | Exact result |
|---|---|
| Minimum pairwise distance | 3 |
| Guaranteed detected errors | 2 |
| Guaranteed uniquely corrected errors | 1 |
| Nearest distance | 1 |
| Closest words | 000 |
| Unique nearest neighbor | True |
Exact inputs and supporting calculations
| Parameter | Value |
|---|---|
| words | ["000","111"] |
| received | 010 |
| First | Second | Hamming distance |
|---|---|---|
| 000 | 111 | 3 |
Separate a syndrome from a unique error diagnosis
Received noncodeword with one single-bit candidate
A syndrome describes a coset modulo the code. Equal columns give different one-bit errors with the same syndrome, and a unique one-bit candidate need not be the actual channel error.
| Quantity | Exact result |
|---|---|
| Received r | 101 |
| Observed Hr | (0, 1) |
| Single-bit candidates | 1 |
| Kernel codewords | 000, 111 |
| Unique among single-bit errors | True |
| Row parity terms | (1+1, 0+1) modulo 2 |
| Zero comparison at r=000 | Compatible errors 000 and 111. |
Exact inputs and supporting calculations
| Parameter | Value |
|---|---|
| H | [[1,0,1],[0,1,1]] |
| r | [1,0,1] |
| Index | Syndrome |
|---|---|
| 0 | (1, 0) |
| 1 | (0, 1) |
| 2 | (1, 1) |
| Error e | Candidate codeword r+e | Weight |
|---|---|---|
| 010 | 111 | 1 |
| 101 | 000 | 2 |
Worked examples
Compute entropy and distance from uniform
Let P=(1/2,1/4,1/4) on three outcomes. Compute their self-information, H(P), and D₂(P∥U) for the three-outcome uniform law U.
- For the symbol of probability 1/2, self-information is −log₂(1/2)=1 bit. Each symbol of probability 1/4 has self-information −log₂(1/4)=2 bits.
- The entropy is their weighted average, (1/2)·1+(1/4)·2+(1/4)·2=3/2 bits. The less probable symbols have more self-information when they appear.
- The uniform comparison law on the three symbols has probability 1/3 for each. Its logarithmic loss is log₂ 3 at every symbol, so its expected logarithmic loss under P is also log₂ 3.
- Subtract H(P) from this loss to obtain D₂(P∥U)=log₂ 3−3/2 bits. The same number is positive because the given law is different from the uniform law.
The three self-information values are 1, 2 and 2 bits. The entropy is 3/2 bits, and D₂(P∥U)=log₂ 3−3/2 bits.
Follow information through two independent binary flips
Let X be a fair bit, Y be X passed through a binary symmetric channel with error 1/4, and Z be Y passed through another independent flip of probability 1/4. Compute the effective flip probability and both mutual informations.
- Write Y=X⊕N₁ and Z=Y⊕N₂ where N₁,N₂ are independent of each other and of X, each with probability 1/4 of equaling one. The overall flip is N₁⊕N₂, which equals one when exactly one of the two individual flips occurs.
- Its probability is (1/4)(3/4)+(3/4)(1/4)=3/8. The overall flip remains independent of X, so the channel from X to Z is binary symmetric with that crossover probability.
- Since X is fair, both Y and Z are fair. The first conditional output entropy H(Y∣X) is h₂(1/4), and the conditional output entropy H(Z∣X) is h₂(3/8). Thus I(X;Y)=1−h₂(1/4) and I(X;Z)=1−h₂(3/8).
- On the interval from 1/4 to 3/8 the derivative h₂′(p)=log₂((1−p)/p) is positive. Therefore I(X;Z) is strictly smaller than I(X;Y), consistent with processing through the second independent channel.
The overall flip probability is 3/8. The mutual informations I(X;Y) and I(X;Z) are 1−h₂(1/4) and 1−h₂(3/8) bits.
Construct a Huffman code and its expected length
For probabilities (1/2,1/4,1/8,1/8), merge the two smallest weights at each step. Give a valid code and compare its expected length with the entropy.
- Name the source symbols a,b,c,d in order of their probabilities. Merge c,d, the two weights 1/8, into a parent of weight 1/4. The remaining weights are 1/2,1/4,1/4.
- Merge b with the first parent to obtain a second parent of weight 1/2. Merge that parent with a to make the root of weight one. A consistent choice of binary edges yields a↦0, b↦10, c↦110, and d↦111.
- The lengths are 1,2,3,3 and the code is prefix-free because each word ends at its own leaf. Its expected length is (1/2)·1+(1/4)·2+(1/8)·3+(1/8)·3=7/4 bits.
- The self-information of the four probabilities is exactly (1,2,3,3) bits. Their weighted average is therefore also 7/4 bits. This code attains the entropy lower bound and the greedy merge construction attains an optimum.
One optimal code is 0,10,110,111 in the given symbol order. Its expected length equals H=7/4 bits.
Build a prefix code from specified lengths
Construct binary prefix words of lengths (2,2,3,3) using the greedy depth rule. Compute the Kraft sum and the remaining unused length-three words. Show why lengths (1,1,2) fail.
- At depth two choose the two earliest distinct binary words 00 and 01. Their length-three descendants are 000,001,010,011, which are thereby excluded for the remaining two selections.
- The remaining depth-three words in lexicographic order are 100,101,110,111. Choose the first two, 100 and 101. None extends a previous codeword and they have the same length as each other.
- The Kraft sum is 2⁻²+2⁻²+2⁻³+2⁻³=3/4. The unused words 110 and 111 form the remaining two of the eight equally counted depth-three words, matching the unused fraction 1/4.
- For lengths (1,1,2) the Kraft sum is 1/2+1/2+1/4=5/4, which exceeds one. In fact the two distinct length-one words already cover the entire tree below them and leave no available length-two word.
The code 00,01,100,101 has Kraft sum 3/4 and leaves 110 and 111 unused at depth three. The infeasible sum is 5/4.
Count a shortest fixed-length code with a declared error
A fair independent binary source emits three bits. The decoder may receive a fixed b-bit word. Find the smallest b permitting success probability at least 7/8, and show how the count constrains b.
- The eight possible length-three source words each have probability 1/8 because the bits are independent and fair. A fixed b-bit input to the decoder has at most 2^b possible values, so it can name at most 2^b different source words.
- To succeed with probability at least 7/8, at least seven different source words must be decoded correctly. Hence the necessary inequality is 2^b≥7.
- For b≤2 there are at most four decoding values, and the success probability is at most 4/8. The desired success cannot be reached at those bit budgets.
- For b=3 send the source word itself and decode it unchanged. This succeeds with probability one, exceeding the requirement, so the smallest fixed length is three bits.
The smallest fixed description has three bits. At least seven of the eight equally likely source words must decode correctly.
Compute information through an erasure channel
An input bit has probability 1/3 of being one and an independent erasure occurs with probability 1/4. Compute input entropy, conditional entropy from the output, mutual information and the channel capacity.
- The source bit has entropy h₂(1/3)=−(1/3)log₂(1/3)−(2/3)log₂(2/3). When the output is an ordinary bit, it fixes the original value and the corresponding conditional entropy is zero.
- The erasure occurs with probability 1/4 and is independent of X. On that event the conditional input law remains Bernoulli with parameter 1/3. Thus H(X∣Y)=(1/4)h₂(1/3).
- Subtracting from the input entropy gives I(X;Y)=(3/4)h₂(1/3) bits for this particular input law. The three-quarters multiplier is the probability of an informative non-erased output.
- Maximizing over the Bernoulli parameter makes the input fair and its entropy one bit. The capacity is therefore 3/4 bit per use. The given input already has nonzero information and a fair bit yields the capacity value.
H(X)=h₂(1/3), H(X∣Y)=h₂(1/3)/4 and I(X;Y)=3h₂(1/3)/4 bits. Capacity is 3/4 bit per use.
Correct one error using a Hamming syndrome
Use the seven binary columns indexed 1 to 7 in ordinary three-bit representation. Send the word with ones at positions 1,2,3 and flip position 6. Compute the syndrome and corrected word.
- The three columns at positions 1,2,3 are 001,010,011. Their binary sum is zero, so the sent word c with ones precisely at these positions lies in the kernel of the parity-check matrix.
- After flipping position 6, the received word y has ones at 1,2,3,6. Its syndrome is the sum of those four columns, which equals column 6 because the first three cancel.
- Column 6 is 110. As the nonzero parity-check columns are all distinct, the single-error decoder identifies position 6 when it sees that syndrome.
- Flipping position 6 again removes that bit and gives the original word with ones at 1,2,3. Its syndrome is zero, confirming a valid decoded word that matches the transmitted one under the stipulated single-error model.
The syndrome is 110, so flip position 6 to restore the codeword with ones at 1,2,3.
See why two flips mislead a single-error decoder
In the same length-seven code send the zero word. Flip positions 1 and 4. Compute the syndrome, the bit flipped by a one-error decoder and the wrong decoded codeword.
- The zero codeword has zero syndrome. Flipping positions 1 and 4 gives a word with syndrome h₁+h₄=001+100=101, using binary addition.
- The column 101 is column 5. A single-error decoder therefore flips position 5. The resulting word has ones exactly at positions 1,4,5.
- Its syndrome is 001+100+101=000, so it is a nonzero codeword. It differs from the zero word that was sent in all three of those positions.
- The two-flip received word is at distance two from zero and one from this wrong codeword. The single-error rule produces the wrong answer outside its radius even though the returned word passes the parity check.
The syndrome is 101. The decoder flips position 5 and produces the nonzero codeword with ones at 1,4,5.
Compute distances in a polynomial evaluation code
Over 𝔽₅ evaluate f(x)=1+x and g(x)=3+2x at 0,1,2,3,4. Give both words and their distance. Verify the code of all these linear polynomials meets the Singleton bound.
- In order of the evaluation points (0,1,2,3,4), f(x)=1+x has word (1,2,3,4,0) over 𝔽₅. The polynomial g(x)=3+2x gives (3,0,2,4,1) after reduction modulo five.
- The two words agree only at point 3, where both give 4. Equivalently g−f=2+x has its one root at x=3 in the field. Their Hamming distance is four.
- Two distinct polynomials of degree at most one can agree at at most one evaluation point. Hence the minimum distance among all these codewords is at least four and the displayed pair proves equality.
- There are 5²=25 polynomials, with distinct evaluated words by that distance argument. The Singleton bound gives 5^(5−4+1)=25, so the code meets it exactly.
The evaluated words are (1,2,3,4,0) and (3,0,2,4,1). They are distance four, and the full code attains size 25.
Find a clique from a satisfying assignment
For C₁=(x∨y∨z), C₂=(¬x∨y∨¬z), C₃=(x∨¬y∨z), use x=y=1,z=0. Choose one true literal occurrence per clause, verify the three clique edges and show one incompatible pair lacks an edge.
- Under x=y=1 and z=0, choose the y occurrence in C₁, the y occurrence in C₂ and the x occurrence in C₃. Each selected literal is true, and the two occurrences of y are different graph vertices.
- The selected C₁ and C₂ occurrences are in different clauses and have the same positive literal, so they are adjacent. The selected C₃ occurrence x is in a third clause and is compatible with each choice of y.
- Thus all three possible edges between the selected vertices are present. They form a size-three clique, with one occurrence per clause.
- The positive x occurrence from C₁ and the negative x occurrence from C₂ form a pair from distinct clauses that lacks an edge. They are complementary literals, so this pair fails the compatibility test.
Choose the two positive y occurrences in the first two clauses and x in the third. The three form a clique. The opposite x signs lack an edge.
Convert a clique into a cover in the complement graph
Let G have vertices a,b,c,d and edges ab,ac,bc,cd. Find a clique of size three, find the complement graph and give the related independent set and vertex cover there.
- In G the pairs ab, ac and bc are all edges, so {a,b,c} is a clique of size three. The edge cd joins the remaining vertex to c and does not affect that clique.
- Among all six possible pairs of distinct vertices, the two absent edges of G are ad and bd. These and only these form the edges of the complement graph, with c isolated there.
- The clique vertices {a,b,c} therefore form an independent set in the complement. Their complement in the vertex set is {d}, and both complement edges have d as one endpoint.
- Thus {d} is a vertex cover of size one for the complement. The thresholds are related by n−k=4−3=1, and the original clique realizes the independent set and its cover through the exact reductions.
The clique {a,b,c} becomes independent in the complement with edges ad and bd. The remaining vertex {d} covers both edges.
Count guaranteed incompressible bit strings
For n=8 and c=2, count the possible descriptions of length less than n−c, including length zero. Determine how many 8-bit strings are guaranteed to have no such description.
- Here the short-description threshold is n−c=6, so the available lengths are 0,1,2,3,4,5. The empty string accounts for the single description of length zero.
- The total number of candidate descriptions is 1+2+4+8+16+32=63. A fixed decoder can assign at most one output to each description, and some outputs may be undefined or repeat.
- There are 2⁸=256 distinct eight-bit strings. At most 63 of them can have a description of length strictly below six for that decoder.
- At least 256−63=193 eight-bit strings therefore lack a description shorter than six bits. This conclusion depends only on the count and remains true if the decoder is defined on fewer candidate strings.
There are 63 descriptions shorter than six bits. At least 193 of the 256 eight-bit strings need six bits or more for this decoder.
Try it yourself
Use P=(1,0) and first Q=(1/4,3/4), then Q=(0,1). Compute H(P) and D₂(P∥Q) in each case and explain the zero-probability convention.
Show the answer and reasoning
H(P)=0. The divergence is two bits for the first comparison law and infinite for the second.
The law P places all the mass on the first outcome. Its only included entropy term is −1·log₂ 1=0. The second outcome contributes zero by the zero-mass entropy convention. For Q=(1/4,3/4), the only divergence term is 1·log₂(1/(1/4))=log₂ 4=2 bits. The two assigned probabilities sum to one and the supported probability under P is positive under Q. For Q=(0,1), the first outcome still has probability one under P but has assigned probability zero. Its logarithmic loss is infinite, so D₂(P∥Q)=+∞. In both cases there is no contribution from the second P-coordinate because that outcome never occurs under P. The infinite result is specifically the loss on an outcome of positive P-mass.
Let X be uniform on {0,1,2,3}, with Y=X mod 2. Compute H(X), H(Y), H(X∣Y), H(Y∣X) and I(X;Y).
Show the answer and reasoning
The entropies H(X), H(Y), H(X∣Y), H(Y∣X) are 2, 1, 1 and 0 bits. I(X;Y)=1 bit.
A uniform variable on four elements has H(X)=log₂ 4=2 bits. Each parity value has two preimages, so Y is fair and its entropy H(Y) is one bit. Given Y=0 the two possible X values are 0 and 2, each of conditional probability 1/2. Given Y=1 the two possible values are 1 and 3 with the same probabilities. Each conditional entropy is one bit. Thus H(X∣Y)=1 bit. Given X, parity is its determined value, so H(Y∣X)=0. These two conditional calculations use different source variables. The mutual information is H(X)−H(X∣Y)=2−1=1 bit. It also equals H(Y)−H(Y∣X)=1−0=1 bit, as required by symmetry.
Let X be a fair bit and Y=X. Let Z be constant. Compute both mutual informations and identify which conditional independence required for equality fails.
Show the answer and reasoning
I(X;Y)=1 bit and I(X;Z)=0. Given the constant Z, X and Y are still dependent.
Here Y equals X, so observing Y determines X. Since the fair input has one bit of entropy, I(X;Y)=H(X)−H(X∣Y)=1−0=1 bit. The constant output Z leaves the distribution of X unchanged at its one possible value. Hence H(X∣Z)=H(X)=1 and I(X;Z)=0. The equality condition for the Markov chain would require X and Y to be conditionally independent given Z. Conditioning on a constant gives their usual joint law. In that law P(X=0,Y=0)=1/2, whereas P(X=0)P(Y=0)=1/4. The product condition fails, which gives the strict drop that the direct calculation found.
For P=(3/4,1/4) and Q=(1/2,1/2) compute TV(P,Q) and D₂(P∥Q). State the exact lower bound from the divergence inequality.
Show the answer and reasoning
TV=1/4 and D₂=(3/4)log₂(3/2)−1/4, with lower bound 1/(8 ln 2).
The absolute differences of the two coordinates are |3/4−1/2|=1/4 and |1/4−1/2|=1/4. Half their sum gives TV(P,Q)=1/4. The two divergence ratios are (3/4)/(1/2)=3/2 and (1/4)/(1/2)=1/2. Thus D₂(P∥Q)=(3/4)log₂(3/2)+(1/4)log₂(1/2)=(3/4)log₂(3/2)−1/4. The lower bound in bits is (2/ln 2)(1/4)²=1/(8 ln 2). Both laws have positive coordinates, so the finite-case Bernoulli calculation applies. Here the two-bin partition can use the first coordinate as A. Its P-mass and Q-mass are respectively 3/4 and 1/2, so the merge is already the original two-outcome comparison and the bound follows directly.
For block size 100 and declared entropy H=0.8 bits, let the typical tolerance be 0.05 and typical-set mass at least 0.95. Derive the permitted cardinality interval without assuming uniform typical probabilities.
Show the answer and reasoning
The bound on the typical count is 0.95·2^75 ≤ |A| ≤ 2^85.
The typical self-information per symbol lies between H−ε=0.75 and H+ε=0.85. Multiplying by 100 gives block self-information between 75 and 85 bits. Exponentiating the negative of these numbers, each typical word has probability between 2^(−85) and 2^(−75). Its exact probability may vary from word to word. Since the total probability of the typical set is at most one and each included word has probability at least 2^(−85), there are at most 2^85 typical words. The mass is at least 0.95 and each word in it has probability at most 2^(−75). It therefore contains at least 0.95·2^75 words, with the lower bound rounded up if an integer count is needed.
For the binary code with words 0 and 01, exhibit the prefix relation, prove unique decodability by parsing and compute the Kraft sum.
Show the answer and reasoning
The parser takes 01 when the 0 is followed by 1, and 0 otherwise. This gives unique decoding with Kraft sum 3/4.
The word 0 is an initial segment of 01, so the two-word code fails the prefix condition. Each word begins with 0 and only the longer word has a second bit 1. For any valid output, the next word boundary has a 0. If it is immediately followed by a 1, these two bits must be 01 because a single 0 would leave a boundary beginning with 1, which no word can start. If the next bit is 0 or there is no next bit, the first word must be 0 because the longer word requires 1 in its second position. Every successive boundary is therefore forced, proving uniqueness of the parsing until all bits are consumed. The lengths are one and two, giving Kraft sum 2⁻¹+2⁻²=3/4. This is consistent with the bound for uniquely decodable codes even though this particular assignment has a prefix pair.
For weights (5,4,3), merge in the required order. Give the final codeword lengths, a binary prefix code and the normalized expected length.
Show the answer and reasoning
Merge 3 and 4 first. Lengths (1,2,2) from code 0,10,11 give expected length 19/12 bits.
Of weights 5,4,3, the two least are 3 and 4. Merge them into a node of weight 7. The two remaining nodes have weights 5 and 7. Join these as the two children of the final root. The symbol of weight 5 gets length one, while those of weights 4 and 3 get length two. For example assign codewords 0,10,11 to the symbols in the given order. The last two extend the branch 1 and neither extends 0, so the resulting code is prefix-free. The sum of the original weights is 12. The normalized expected length is (5·1+4·2+3·2)/12=19/12 bits per source symbol.
Use probabilities (1/2,1/4,1/4) and codeword lengths (1,3,3). Compute normalized weights from 2^(−length), the divergence, the Kraft slack term and the resulting gap to entropy.
Show the answer and reasoning
The normalized law is (2/3,1/6,1/6). The divergence and slack sum to 1/2 bit, the length gap.
The unnormalized weights from lengths (1,3,3) are (1/2,1/8,1/8) and sum to K=3/4. Dividing by K gives Q=(2/3,1/6,1/6). The ratio p_x/q_x is 3/4 for the first symbol and 3/2 for each of the other two. Combining their two weights 1/4 gives D₂(P∥Q)=(1/2)log₂(3/4)+(1/2)log₂(3/2)=(1/2)log₂(9/8). The second contribution in the length decomposition is −log₂ K=log₂(4/3). Its sum with the divergence equals one-half, since (9/8)(4/3)²=2. The direct expected length is (1/2)·1+(1/4)·3+(1/4)·3=2. The entropy is 3/2 bits, so the gap is 1/2 bit, matching the sum of the two computed terms.
For a binary symmetric channel with error 3/4 compute the capacity and show why complementing the received bit makes the error probability 1/4.
Show the answer and reasoning
Capacity is 1−h₂(1/4). Complementing the output changes the flip probability from 3/4 to 1/4.
At crossover probability ε=3/4 the binary symmetric channel has capacity 1−h₂(3/4) bits per use, using the maximum over input distributions. Since h₂(p)=h₂(1−p), this is 1−h₂(1/4). Write Y=X⊕N with N independent of X and P(N=1)=3/4. Complementing the received bit gives Y′=Y⊕1=X⊕(N⊕1). The new error bit is one exactly when N was zero. Its probability is therefore 1/4 and it stays independent of X, so the complemented channel has the stated smaller crossover. The map Y↦Y′ is invertible. Observing Y′ determines Y and conversely, so the conditional laws of X have the same entropy average under this relabeling. This explains why the information and capacity are unchanged by complementing the output.
Take a fair bit X and its binary symmetric channel output Y at error probability ε, decoded as Y. Compute the conditional entropy and Fano’s bound and compare them for 0≤ε≤1.
Show the answer and reasoning
The actual conditional entropy and Fano’s bound both equal h₂(ε).
For a fair X and an independent flip bit of probability ε, the output Y is also fair. For either output y, the two possible inputs have conditional weights 1−ε at x=y and ε at x=1−y. Thus H(X∣Y)=h₂(ε). This expression includes the endpoints ε=0 and ε=1, at which the conditional law is a point mass and the entropy is zero. The prescribed decision x̂=Y has error probability P_e=ε. Here M=2, so log₂(M−1)=log₂ 1=0 and Fano’s upper bound is just h₂(ε). The bound is attained for each ε between zero and one. This calculation uses the declared decoder. For ε>1/2 the complement decoder has lower error, while the conditional entropy still equals h₂(ε).
For a code of block length 100 for a memoryless channel of capacity 0.5 bits per use, let the uniform message set have size 2^75. Use the weak converse inequality to bound the average error from below.
Show the answer and reasoning
The inequality is 75(1−P_e)≤51, giving average error at least 8/25.
Here log₂ M=75 and the block length is n=100, so the rate is R=75/100 bits per use. The single-letter capacity is C=0.5 bits per use, giving nC=50 bits. The weak converse nR(1−P_e)≤nC+1 becomes 75(1−P_e)≤51. It uses the uniform message law and average probability of error of the given code. Dividing by 75 gives 1−P_e≤51/75. Reversing the inequality when subtracting from one yields P_e≥1−51/75=24/75. The simplified lower bound is 8/25=0.32. The inequality constrains the given finite-block average error for any code under the stated memoryless channel assumptions.
Use the binary code spanned by 1100 and 0011. List its words and minimum distance, then give a received word at distance one from two different codewords.
Show the answer and reasoning
The code is {0000,1100,0011,1111} with distance two. Received 1000 can be one flip from 0000 or 1100.
The two binary generators 1100 and 0011 are independent. The linear code has four words, namely 0000,1100,0011 and their sum 1111. The nonzero word weights are 2,2,4. For a linear code the differences between distinct codewords are exactly its nonzero words, so the minimum distance is 2. Take the received word 1000. It is at distance one from 0000 because only the first bit changes. It is at distance one from 1100 because only the second bit changes. Therefore one substitution can produce the same received word from two possible transmitted codewords. The code detects one substitution by testing membership, and its guaranteed unique correction radius is ⌊(2−1)/2⌋=0.
For binary block length 5 and a claimed unique-correction radius 1 guaranteed by minimum distance at least 3, calculate the radius-one volume and the strongest integer size bound from packing.
Show the answer and reasoning
The radius-one volume is six and the size bound is five.
A radius-one ball around a binary word of length five contains the word itself and one word from flipping each of its five positions. Its volume is 1+5=6. When the minimum distance is at least three, no word belongs to two radius-one balls around different codewords. If it did, their pairwise distance would be at most two by the triangle inequality. There are 2⁵=32 words total. For a code with M words the disjoint balls give 6M≤32 and therefore M≤32/6. The strongest integer conclusion from this count is M≤⌊32/6⌋=5. The argument gives a necessary restriction on code size from the stated distance.
In the degree-at-most-two evaluation code over 𝔽₇ at points 0 through 5, evaluate (x−1)(x−2). Identify its Hamming weight and check the expected minimum distance.
Show the answer and reasoning
The evaluated word is (2,0,0,2,6,5), of weight four. It attains the minimum 6−3+1.
Evaluate h(x)=(x−1)(x−2) in 𝔽₇ at the six points 0,1,2,3,4,5. The values at 1 and 2 are zero by the displayed factors. The other values are h(0)=2, h(3)=2, h(4)=6 and h(5)=12≡5 mod 7. In the given order the word is (2,0,0,2,6,5), with four nonzero entries. A nonzero polynomial of degree at most two has at most two distinct roots in the field. Therefore any two distinct evaluated polynomials differ at at least four of the six points. The displayed word is at distance exactly four from the zero word and attains that bound. This gives d=4=6−3+1 for dimension three and the stipulated six evaluation points.
Given A≤ₚB and B≤ₚC, with C in P, give the algorithm for A and justify the size and running-time bounds. Explain how NP-hardness of A would transfer to C.
Show the answer and reasoning
Compute the two reductions then decide C. The output length bounds make the whole procedure polynomial, and reductions from NP languages can be composed through A.
Let f compute the reduction from A to B and g the reduction from B to C. On input x compute f(x), then g(f(x)), then run the stated polynomial-time C decider on the latter. The reduction equivalences give x∈A exactly when f(x)∈B, which holds exactly when g(f(x))∈C. The C decider therefore returns the correct answer for A. The first output has length bounded by the polynomial time spent to write it. The second output and its computation time are polynomial in that first length. The last decision is polynomial in the second length, so the composed running time is polynomial in |x|. If A is NP-hard, choose any language L in NP and compose its polynomial reduction to A with f and g. This gives a polynomial reduction from L to C and establishes NP-hardness of C.
Use vertices a,b,c,d and edges ab,ac,bc,cd. Test claimed size-three clique certificates {a,b,c} and {a,c,d}, and give the cost of checking a general size-k certificate using an adjacency matrix.
Show the answer and reasoning
The certificate {a,b,c} passes. The certificate {a,c,d} fails on ad. A verification uses at most O(k²) pair checks and matrix lookups.
In {a,b,c}, all three required pairs ab, ac and bc occur as edges. The vertices are distinct and the size is three, so this certificate passes. In {a,c,d}, pairs ac and cd occur, but ad does not. The missing pair causes the certificate to fail even though two of its three required edges are present. For a general claimed certificate of size k, first verify that the entries are distinct allowed vertices. Then inspect the adjacency matrix for each of the k(k−1)/2 different unordered pairs. There are O(k²) lookups and pair checks, and all of them use the explicit graph encoding. This is a polynomial verification, independently of the number of candidates a search procedure might have to inspect.
Use binary comparison decisions and five distinct keys to compute the minimum number of leaves required and the resulting integer lower bound on worst-case comparisons.
Show the answer and reasoning
At least 120 leaves are needed, so the lower bound is seven comparisons.
With five distinct keys, there are 5·4·3·2·1=120 possible strict orders of the five input positions. Each order requires its own output permutation in the comparison model. Two strict orders that end at one leaf receive the same positional permutation, so that leaf can serve at most one of them. At least 120 leaves are needed. A binary decision tree of depth six has at most 2⁶=64 leaves, whereas depth seven has capacity 2⁷=128. The leaf count rules out depth six or less. The integer lower bound is therefore ⌈log₂ 120⌉=7 worst-case comparisons. It is derived solely from counting leaves in the stipulated decision model.
Under the hypothesis that the universal description length is computable, explain how to describe the selected high-complexity string of bit length n=2^m by a fixed procedure and a short encoding of m. Derive the contradiction for large m.
Show the answer and reasoning
The selected length-2^m string would have a description of length O(log m), below its required complexity 2^m for large m.
Under the assumed exact computability of C_U, a fixed routine can take an index m and compute n=2^m. It enumerates the finitely many n-bit strings and outputs the first with C_U(x)≥n. Such a string exists by the counting argument: there are fewer descriptions of length below n than n-bit strings. The search terminates using the assumed exact subroutine. Encode the binary digits of m with their length prefix and append that input to a fixed simulation prefix for this routine. Its total description length is bounded by a constant plus 2⌊log₂ m⌋+3 for m≥1. This grows more slowly than n=2^m and is strictly below n for large m. The routine nevertheless outputs the selected string of description length at least n, which contradicts the assumed computation of C_U.
What to carry forward
- Logarithmic loss is entropy plus divergence, with infinite loss for excluding a possible outcome.
- Data processing follows from conditional independence and the information chain rule.
- Prefix lengths satisfy Kraft’s inequality, and a feasible length list yields an actual prefix code.
- Grouping independent symbols reduces expected prefix overhead per symbol.
- A channel code’s reliability and a codeword set’s distance require different conditions.
- Syndromes identify error cosets, and the chosen correction radius controls unique decoding.
- A polynomial reduction transfers a solver from its target back to its source and hardness in the forward direction.
- Finite counting gives many long descriptions, while the shortest universal description function is incomputable.
References
Sources for the concepts and teaching approaches in this article.
- Shannon’s entropy and its grouping principleClaude E. ShannonPrimary · PDF
- MIT 6.441 Information Theory, Chapter 1Yury Polyanskiy and Yihong WuPrimary · PDFFinite entropy bounds and information divergenceConditional mutual information and processingTypical sets and fixed-length source compressionFeasible lengths and unique decodabilityBinary symmetric and erasure capacityThe Fano conditional uncertainty boundA weak converse for reliable channel codesRandom channel coding and existence of a fixed code
- Single-error correcting binary codes and distanceRichard W. HammingPrimary · PDF
- Clique certificates, independent sets and coversUniversity of Washington CSE 431 course authorsPrimary · PDF
- Binary comparison trees and sortingMIT 6.006 course authorsPrimary · PDF