Information Theory ExercisesInformation Theory · Exercises
0 / 0

Workbench / Information Theory Exercises

B1·03

The Probability You Need

Exercises for chapter 3: the rules in your own words, independence against disjointness, conditional probability and its reversal, why expectations add, frequencies against probabilities, and the birthday problem; a million simulated chips against Bayes' theorem, adaptive probability estimates that never say zero, bit errors in packets against the binomial, letters predicted from the letter before, collisions found in truncated hashes, and senior exercises on alert fatigue, sizing a deduplication hash, and how many users an experiment needs.

20 topics · ~5 min read
Updated Suggest a correction

Start here: how these exercises work

Write your answer in the box first; hints open one at a time as you write, and the solution a couple of minutes after the last hint. Theory is in your own words, practice and programs come with real output (Python 3.13), cumulative projects use chapters 1 to 3 together, what the chapter leaves out explains what it skips, and senior exercises put the ideas into designs and reviews.

Theory

T1. The three rules, and why they're enough

State the three rules every probability obeys, in your own words, and derive from them the rule for the complement and the rule for two overlapping events.

T2. Independent is not the same as disjoint

Explain the difference between independent events and disjoint events, with an example of each. Can two events with positive probability be both?

T3. Reversing a conditional

A friend says: "Most people in hospital with this illness are smokers, so most smokers will end up in hospital with it." Explain the mistake using conditional probability and Bayes' theorem.

T4. Why expectations always add

Explain why the expected value of a sum is the sum of the expected values, even when the variables depend on each other, and why the same isn't true for variances.

T5. Frequency and probability

Someone flips a coin 10 times, gets 7 heads, and says the coin's probability of heads is 0.7. Explain what's right and wrong about this, using the law of large numbers.

T6. The birthday problem without formulas

Explain to someone without algebra why 23 people are enough for a better-than-even chance of a shared birthday, when 365 days seems to need many more.

Practice and programs

P1. By hand

(a) A password is 4 random digits. What's the chance a guess is right? That at least one of 3 guesses is right? (b) Two cards are drawn from a deck. What's the probability both are aces? (c) A die is rolled until a six appears. What's the probability it takes more than 6 rolls? (d) In 100 tosses of a fair coin, what's the expected number of heads and the standard deviation?

P2. Bayes' theorem against a million chips

Simulate a million chips, each faulty with probability 0.001, with a test that flags 99 % of faulty chips and 2 % of good ones. What fraction of flagged chips is faulty? Compare with Bayes' theorem.

P3. Estimates that never say zero

Code Shakespeare's bytes adaptively: predict each byte from the counts of the bytes before it, and add up the surprises. Compare raw counts with add-one, add-a-half and add-1256 smoothing, on the first 1,000 and 20,000 bytes and on the whole file, and with the surprise you'd get if the final counts were known in advance.

P4. Bit errors in packets

Send 100,000 packets of 1,000 bits through a channel that flips each bit independently with probability 0.001. Count the errors per packet and compare with the binomial distribution. What fraction of packets arrives error-free?

Cumulative projects (chapters so far: 01–03)

C1. Letters predicted from the letter before

Compute the average surprise of a letter in Shakespeare's plays on its own (chapter 1 found 4.19 bits) and given the letter before it, using P(b∣a) =count(ab)count(a·). Then compare the surprise of a few letters alone and in context. What do the cases where context raises surprise tell you?

C2. Finding collisions in a short hash

Hash the strings "item 0", "item 1", … with SHA-256, keep only the first b bits, and stop at the first repeat, for b=16,24,32,40. Compare the number of items with the birthday prediction: the expected number of values before the first repeat is about 1.25M.

What the chapter leaves out

Continuous probability

The chapter's distributions are lists of values. Measurements like voltages, times and positions take any real value, and their probabilities are spread with a density: the probability of a range is the area under a curve, and the probability of any exact value is zero. The normal (Gaussian) distribution, the curve that sums of many small independent effects approach (the central limit theorem, de Moivre 1733 and Laplace 1810), is the most important. Chapter 9 uses it once, for noise on a radio channel; the Mathematics shelf's Probability book covers densities fully.

Interpretations of probability

The axioms say how probabilities behave, not what they are. Frequentists say a probability is a long-run frequency, and only repeatable experiments have one. Bayesians say it's a degree of belief, updated by Bayes' theorem as evidence arrives, so even one-off events ("will this bridge design fail?") have probabilities. Propensity views say it's a physical tendency of the set-up. Statistics has frequentist and Bayesian schools, with different methods (confidence intervals against credible intervals, p-values against posterior probabilities). Information theory sits happily with any of them.

Markov chains

Experiment 2 showed that a letter depends on the one before. A Markov chain is a source where each symbol's distribution depends only on the previous few: exactly the model C1 used. Andrey Markov introduced them in 1906 and tested them in 1913 on the vowels and consonants of Pushkin's Eugene Onegin, the first statistical study of a text. Shannon used them in 1948 to generate "approximations to English"; chapter 7 and chapter 10 use them to measure the information in text with context.

The law of large numbers, precisely

The chapter states the law informally. The weak law (Bernoulli) says the chance of a large deviation shrinks to zero; the strong law (Borel 1909, Kolmogorov 1930) says the average converges with probability 1. Chebyshev's inequality (1867) gives a simple bound on how fast: the chance that an average of n samples is more than ε from the mean is at most σ2nε2. Chapter 6's typical sequences use exactly this.

Senior exercises

S1. An alert that's usually wrong

A monitoring system flags anomalies in a service's traffic. It detects 95 % of real incidents and flags 0.5 % of normal minutes. Real incidents occur in about 1 minute in 10,000. (a) What fraction of alerts are real? (b) The team proposes making the detector more sensitive, catching 99 % at the cost of flagging 1 % of normal minutes. What happens? (c) What would you do instead?

S2. Sizing a deduplication hash

A storage system splits data into blocks and stores each distinct block once, identified by a hash of its content. It expects up to 1012 distinct blocks over its life. (a) If two different blocks ever get the same hash, what happens? (b) How many hash bits keep the chance of any collision below one in a billion? (c) Why might you still choose 256 bits?

S3. How many users does an experiment need?

A product team runs an experiment: does a new checkout page raise the conversion rate from about 4 %? They want to detect a change of 0.4 percentage points (to 4.4 %). Roughly how many users does each version need, and what would you tell them about checking results daily?