Answer key · Unit 6
Information and codes.
Each lesson’s practice questions, their correct answers and the mistakes they spot. Answers read off the Scene use the same setting the learner sees.
Answer key 5
Lesson 1 of 5 · About 20 minutes
Surprise measured in bits
What the word information means in computer science: how much uncertainty a message removes, why a fair coin flip carries one bit, and why a rare outcome is more surprising.
The 5 steps and their answers
Practice · Choose
Question
Two messages reach you. The first says “The sun rose this morning”. The second gives the result of a fair coin flip. Which carries more information, in Shannon’s sense?
Correct answer
Correct The result of the coin flip
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 50 %
- Code block size
- 4 flipsdefaulthidden
- Measure and compress
- Coins
Choices
Shown in a random order.
Correct The result of the coin flip
Wrong The message about the sun, because it is about something more important
Misconception: Takes information to be how important or meaningful a message is, not how much uncertainty it removes.
Feedback from the catalogue
In computer science information does not measure importance or meaning. It measures how much uncertainty a message removes: how much you did not know before it arrived. A message you knew in advance carries bits, however important it is. The result of a fair coin flip, which matters to nobody, carries one whole bit, because you could not have guessed it.
Wrong Both the same: each is one message
Feedback
Information is not counted in messages but in how much uncertainty each message removes. You could have written the message about the sun yourself before it arrived.
Feedback for a right answer
You knew the sun had risen before you read it, so that message removes no uncertainty: bits. The coin’s result you could not have guessed, and its message removes one whole bit of uncertainty.
Hint
Before each message arrived, how sure were you of what it would say?
Worked solution
- Information measures how much uncertainty a message removes, not how important it is.
- That the sun rose was certain in advance: probability , surprise bits.
- A fair coin’s result cannot be guessed: each face has probability , and the message carries one bit.
- So the coin’s message carries more information.
If you chose the sun, you measured importance. To Shannon, a message you knew in advance tells you nothing, however important it is.
Practice · Calculate
Question
The coin is fair: Chance of heads is fixed at 50%. The surprise of an outcome with probability is bits. How many bits of surprise does heads carry?
Correct answer
1 ± 0.01
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 50 %fixed
- Code block size
- 4 flipsdefaulthidden
- Measure and compress
- Coinsfixed
- Accepted within
- ± 0.01
- Computed from the Scene at this step’s setting
- Surprise of a heads, −log₂ p, in bits (infinite when heads cannot happen)
/nodes/stream/outputs/surpriseHeads
Wrong answers it recognises
0.5 ± 0.01
Misconception: Gives the probability itself as the surprise or the entropy, instead of −log₂ p.
Feedback from the catalogue
The probability is not the surprise. The surprise of an outcome with probability is bits: how many times you halve the chance from to reach it. An outcome with probability carries one bit, not ; an outcome with probability carries two bits, not . The probability is a number between and , and the surprise grows as the probability gets smaller.
Feedback for a right answer
: exactly one bit, the answer to one yes-or-no question. That is also why the tape gives each flip one bit.
Hint
: to what power must you raise to get ?
Worked solution
- The probability of heads: .
- The surprise: .
- Substitute: , because .
- Heads carries one bit.
If you answered , you gave the probability itself. The surprise is the logarithm of one over the probability.
Practice · Predict, then look
Question
Now the coin is biased: it lands heads in 90% of flips. Which face carries more surprise? Choose, and then Measure and compress moves to Entropy and shows the surprise of each face.
Correct answer
Correct Tails, the rare outcome
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 90 %fixed
- Code block size
- 4 flipsdefaulthidden
- Measure and compress
- Coinsfixed
Choices
Correct Tails, the rare outcome
Wrong Heads, because it turns up far more often
Misconception: Thinks the likely outcome carries more information, because it turns up more often.
Feedback from the catalogue
The surprise of an outcome depends on how unexpected it is: . The smaller the chance, the bigger the surprise. When a coin lands heads 90% of the time, heads carries only bits, because you guessed it in advance. The rare tails carries bits. Heads does turn up more often, but each time it tells you little.
Wrong Both the same, because every flip is printed as one bit
Feedback
The tape does give each flip one bit, but that is the length of the record, not the amount of information. A heads you guessed in advance tells you less than a tails you did not expect.
Once the prediction is locked in, the Scene changes
- Measure and compress
- Entropyfixed
The Scene then shows: 3.322 · Surprise of a tails, −log₂ (1 − p), in bits (infinite when tails cannot happen)
/nodes/stream/outputs/surpriseTailsA prediction is never marked as a failure: the learner sees the outcome and the explanation either way.
Feedback for a right answer
Tails carries bits, and heads only . When the coin almost always lands heads, heads is small news and tails is big news.
Hint
Which face would you guess before the flip? The surprise is what you did not guess.
Worked solution
- The chance of heads is , of tails .
- The surprise of heads: bits.
- The surprise of tails: bits.
- Tails, the rare outcome, carries far more surprise.
If you chose heads, you counted how often each face turns up. The surprise of one outcome depends on how unexpected it is.
Practice · Calculate
Question
Chance of heads is now fixed at 25%. How many bits of surprise does heads carry?
Correct answer
2 ± 0.01
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 25 %fixed
- Code block size
- 4 flipsdefaulthidden
- Measure and compress
- Coinsfixed
- Accepted within
- ± 0.01
- Computed from the Scene at this step’s setting
- Surprise of a heads, −log₂ p, in bits (infinite when heads cannot happen)
/nodes/stream/outputs/surpriseHeads
Wrong answers it recognises
0.25 ± 0.01
Misconception: Gives the probability itself as the surprise or the entropy, instead of −log₂ p.
Feedback from the catalogue
The probability is not the surprise. The surprise of an outcome with probability is bits: how many times you halve the chance from to reach it. An outcome with probability carries one bit, not ; an outcome with probability carries two bits, not . The probability is a number between and , and the surprise grows as the probability gets smaller.
4 ± 0.01
Misconception: Gives the number of equally likely outcomes, 1/p, instead of the bits it takes to tell them apart, log₂ (1/p).
Feedback from the catalogue
is the number of equally likely outcomes: an outcome with probability is one of four equal possibilities. To tell four possibilities apart, two bits are enough, , , and , because each bit doubles the number of possibilities. So the surprise is the logarithm: , not . Eight possibilities take three bits, and a thousand about ten.
Feedback for a right answer
bits. Each halving of the chance adds one bit: carries one bit, two, three.
Hint
How many times must you halve to reach ?
Worked solution
- .
- The surprise: .
- , so .
- Heads carries bits.
If you answered , you worked out without the logarithm: that is the number of equal possibilities, not the bits it takes to tell them apart. If you answered , you gave the probability.
Practice · Reach the target
Question
Tails on a 90% coin carries bits. Change Chance of heads until heads carries exactly the same surprise, then press Check.
Goal
3.32 ± 0.01
At the start of the step: 1
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 50 %
- Code block size
- 4 flipsdefaulthidden
- Measure and compress
- Entropyfixed
- Read from the Scene at
- Surprise of a heads, −log₂ p, in bits (infinite when heads cannot happen)
/nodes/stream/outputs/surpriseHeads
One setting that reaches it
- Chance of heads
- 10 %
Feedback for a right answer
At 10%: now heads is the rare outcome, one in ten, and . The surprise does not depend on the face’s name, only on its probability.
Feedback for a wrong answer
Not yet. Look for the chance at which heads comes up once in every ten flips.
Hint
The surprise depends only on the outcome’s probability. At what chance of heads does heads have probability ?
Worked solution
- You want .
- So , that is .
- Set Chance of heads to 10%.
If you headed for 90%, you raised the chance of heads, and heads became more expected and less surprising.
Lesson 2 of 5 · About 20 minutes
Entropy
A source's average surprise: how to work it out, why it peaks for a fair coin and falls to zero when the outcome is certain, and why random noise is full of information.
The 5 steps and their answers
Practice · Calculate
Question
Chance of heads is fixed at 90%. Heads carries bits of surprise, and tails . What is the coin’s entropy, the average surprise per flip, in bits?
Correct answer
0.469 ± 0.01
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 90 %fixed
- Code block size
- 4 flipsdefaulthidden
- Measure and compress
- Coinsfixed
- Accepted within
- ± 0.01
- Computed from the Scene at this step’s setting
- Shannon entropy of one flip, H(p), in bits: the average surprise and the least any code can spend per flip
/nodes/stream/outputs/entropy
Wrong answers it recognises
1.74 ± 0.02
Misconception: Averages the surprises (or codeword lengths) as if every outcome were equally likely, without weighting each by its probability.
Feedback from the catalogue
Entropy, and the average cost of a code too, is a weighted average: each value counts by its probability. With a 90% coin, heads turns up in nine flips out of ten and tails in one, so , not . A plain average treats the rare tails as if it turned up in half the flips.
0.9 ± 0.01
Misconception: Gives the probability itself as the surprise or the entropy, instead of −log₂ p.
Feedback from the catalogue
The probability is not the surprise. The surprise of an outcome with probability is bits: how many times you halve the chance from to reach it. An outcome with probability carries one bit, not ; an outcome with probability carries two bits, not . The probability is a number between and , and the surprise grows as the probability gets smaller.
Feedback for a right answer
bits per flip. Most flips bring a small surprise, and only one in ten a big one, so the average is under half a bit.
Hint
A weighted average: multiply each surprise by its chance, and add.
Worked solution
- Heads: probability , surprise . Tails: probability , surprise .
- Entropy is the weighted average of the surprises: .
- Substitute: .
- The entropy: about bits per flip.
If you got , you took a plain average, , as if tails turned up in half the flips. It turns up in only a tenth of them.
Practice · Predict, then look
Question
The marker on the curve shows bits for a coin that lands heads 90% of the time. Now the bias flips: the coin will land heads in only 10% of flips, and tails in 90%. What will its entropy be?
Correct answer
Correct The same entropy, bits
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 90 %fixed
- Code block size
- 4 flipsdefaulthidden
- Measure and compress
- Entropyfixed
Choices
Correct The same entropy, bits
Wrong Lower, because now heads, the outcome printed as 1, is rare
Feedback
The tape writes for heads and for tails, but that is only a convention. The entropy depends on the probabilities, not on the faces’ names or digits.
Wrong Higher, because now the rare outcome is heads
Feedback
There is still one common outcome, , and one rare one, . Only the names have swapped.
Once the prediction is locked in, the Scene changes
- Chance of heads
- 10 %fixed
- Measure and compress
- Entropyfixed
The Scene then shows: 0.469 · Shannon entropy of one flip, H(p), in bits: the average surprise and the least any code can spend per flip
/nodes/stream/outputs/entropyA prediction is never marked as a failure: the learner sees the outcome and the explanation either way.
Feedback for a right answer
The same entropy, bits. The formula does not change when and swap, so the curve is symmetric about 50%: a coin biased to tails is exactly as predictable as one biased the same amount to heads.
Hint
Write down the new coin’s two probabilities and two surprises. What has changed?
Worked solution
- On a coin with a 10% chance of heads, heads carries bits and tails : the same two surprises, with the roles swapped.
- The weights swap too: .
- The entropy equals that of the 90% coin.
What sets the entropy is how easy the flip is to guess, not which way the coin leans.
Practice · Predict, then look
Question
What will the entropy be when the coin always lands heads? Write a number in bits per flip, and then Chance of heads moves to 100%.
Correct answer
0 ± 0.01
A number prediction counts as right within ± 0.01
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 90 %fixed
- Code block size
- 4 flipsdefaulthidden
- Measure and compress
- Entropyfixed
Once the prediction is locked in, the Scene changes
- Chance of heads
- 100 %fixed
- Measure and compress
- Entropyfixed
The Scene then shows: 0 · Shannon entropy of one flip, H(p), in bits: the average surprise and the least any code can spend per flip
/nodes/stream/outputs/entropyA prediction is never marked as a failure: the learner sees the outcome and the explanation either way.
Feedback for a right answer
Zero. When the outcome is certain there is no uncertainty to remove: heads carries bits, and tails never happens. Such a coin tells you nothing, even after a hundred flips.
Feedback for a wrong answer
The tape does print a bit for every flip, but the whole tape could have been written in advance, without looking at the coin. How much surprise is in that?
Hint
If you knew the whole tape before the first flip, how much would it tell you?
Worked solution
- : heads on every flip.
- The surprise of heads: , because .
- Tails never happens, so it adds to the average.
- bits per flip.
If you wrote , you thought each flip carries a bit because the tape prints one bit per flip. That is the length of the record, not the information.
Practice · Reach the target
Question
Change Chance of heads until the coin’s entropy is bits per flip, then press Check.
Goal
0.811 ± 0.005
At the start of the step: 1
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 50 %
- Code block size
- 4 flipsdefaulthidden
- Measure and compress
- Entropyfixed
- Read from the Scene at
- Shannon entropy of one flip, H(p), in bits: the average surprise and the least any code can spend per flip
/nodes/stream/outputs/entropy
One setting that reaches it
- Chance of heads
- 25 %
Feedback for a right answer
At 75% (or 25%): . A coin that lands heads three flips out of four is still fairly surprising: four fifths of a bit per flip.
Feedback for a wrong answer
Not yet. Move the marker along the curve until its height is .
Hint
The entropy falls as you move away from 50%. Try a coin that lands heads three flips out of four.
Worked solution
- You want .
- Try : heads carries , and tails .
- .
- Set Chance of heads to 75%. 25% works too, since the curve is symmetric.
Practice · Choose
Question
Two tapes of bits, the same length. Tape A looks completely random: about as many 0s as 1s, with no pattern at all. Tape B is almost all 1s. Which tape has the higher entropy per bit?
Correct answer
Correct Tape A, the random one
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 50 %
- Code block size
- 4 flipsdefaulthidden
- Measure and compress
- Entropy
Choices
Shown in a random order.
Correct Tape A, the random one
Wrong Tape B, because a random tape carries no message
Misconception: Thinks a random-looking stream with no pattern carries little information, because it means nothing.
Feedback from the catalogue
The opposite is true. Information in Shannon’s sense is uncertainty, and a random stream with no pattern is as unpredictable as anything can be: you cannot guess its next bit, so every bit surprises. Its entropy is close to one bit per bit, the most there is. A stream that is almost all 1s is easy to guess, and its entropy is close to zero. That is also why a compressed or encrypted file looks like noise: everything predictable has already been taken out of it.
Wrong Both the same, because they are the same length
Feedback
A tape’s length says how many bits are written on it, not how much information they carry. You could guess almost all of tape B without reading it.
Feedback for a right answer
Tape A. When you cannot guess the next bit, every bit surprises, and that is exactly high entropy: close to one bit per bit. On tape B the guess “one” is almost always right, so each bit tells you little.
Hint
On which tape is the next bit harder to guess?
Worked solution
- Entropy measures how hard the next symbol is to guess.
- On tape A each bit is like a fair coin flip: the entropy is close to bit per bit.
- On tape B the guess “one” is almost always right: the entropy is close to .
- So tape A has the higher entropy.
If you chose tape B, you thought a random tape carries no information because it has no meaning. Information in Shannon’s sense is uncertainty, and random noise is as unpredictable as anything can be.
Lesson 3 of 5 · About 25 minutes
Compression
How Huffman's code shortens predictable data: short words for common blocks, why a fair coin does not compress, and why no code goes below the entropy.
The 5 steps and their answers
Practice · Calculate
Question
Chance of heads is 90% and Code block size is two flips. Huffman’s code gives each pair a codeword: heads-heads 0, heads-tails 10, tails-tails 110, tails-heads 111. The pairs’ probabilities are , , and , in the same order. How many bits does a pair cost, on average?
Correct answer
1.29 ± 0.01
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 90 %fixed
- Code block size
- 2 flipsfixed
- Measure and compress
- Compressedfixed
- Accepted within
- ± 0.01
- Computed from the Scene at this step’s setting
- Average codeword length, in bits, for one block of blockSize flips
/nodes/stream/outputs/bitsPerBlock
Wrong answers it recognises
2.25 ± 0.01
Misconception: Averages the surprises (or codeword lengths) as if every outcome were equally likely, without weighting each by its probability.
Feedback from the catalogue
Entropy, and the average cost of a code too, is a weighted average: each value counts by its probability. With a 90% coin, heads turns up in nine flips out of ten and tails in one, so , not . A plain average treats the rare tails as if it turned up in half the flips.
Feedback for a right answer
bits a pair, instead of on the upper tape. That is bits a flip: the code saves more than a third.
Hint
Multiply each codeword’s length by its pair’s probability, and add.
Worked solution
- The codeword lengths: , , and bits.
- The pairs’ probabilities: , , and .
- Weighted average: .
- A pair costs bits on average.
If you got , you took a plain average of the lengths, . But the pair heads-heads, with the shortest word, turns up 81% of the time, and that is the whole secret of compression.
Practice · Predict, then look
Question
The coin is fair, and the code reads blocks of four flips. When you open the compressed tape, how many bits per flip will it cost?
Correct answer
Correct Exactly one bit per flip, like the upper tape
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 50 %fixed
- Code block size
- 4 flipsfixed
- Measure and compress
- Entropyfixed
Choices
Correct Exactly one bit per flip, like the upper tape
Wrong Less than a bit, because a good code always saves something
Misconception: Thinks any data can be squeezed below its entropy: with a cleverer code, longer blocks, or by compressing the compressed result again.
Feedback from the catalogue
Shannon proved that no code that loses nothing can spend fewer bits on average than the entropy. For a 90% coin the limit is bits a flip: longer blocks bring the code close to it, but never past it. A fair coin, with an entropy of , cannot be compressed at all. And a tape that has already been compressed looks like a fair coin, so compressing it a second time saves nothing more.
Wrong More than a bit, because the code adds long codewords
Feedback
Huffman’s code never costs more than the plain record: when there is nothing to bet on, it gives every block a word of the same length.
Once the prediction is locked in, the Scene changes
- Measure and compress
- Compressedfixed
The Scene then shows: 1 · Average bits per flip the Huffman code over blocks of blockSize spends (1 for the bare tape)
/nodes/stream/outputs/bitsPerFlipA prediction is never marked as a failure: the learner sees the outcome and the explanation either way.
Feedback for a right answer
Exactly one bit. With a fair coin each of the blocks turns up with the same probability, , so no block deserves a short word: they all get four bits, and the lower tape is exactly as long as the upper one. The entropy is bit per flip, and there is nothing to save.
Hint
With a fair coin, is any block of four flips likelier than another?
Worked solution
- With a fair coin each block of four flips has probability .
- When all blocks are equal, the best code gives each one four bits: .
- Four bits for four flips: one bit per flip.
- That is also the entropy of a fair coin, the limit no code can go below.
Compression is a bet on what is likely. When nothing is likelier than anything else, there is nothing to bet on.
Practice · Reach the target
Question
Chance of heads is fixed at 90%. In blocks of one flip the code saves nothing: one bit per flip. Change Code block size until the code costs about bits per flip, then press Check.
Goal
0.49 ± 0.005
At the start of the step: 1
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 90 %fixed
- Code block size
- 1 flips
- Measure and compress
- Compressedfixed
- Read from the Scene at
- Average bits per flip the Huffman code over blocks of blockSize spends (1 for the bare tape)
/nodes/stream/outputs/bitsPerFlip
One setting that reaches it
- Code block size
- 4 flips
Feedback for a right answer
In blocks of four: bits per flip, very close to the limit. The longer the block, the more different probabilities the code has to work with, and the cost closes in on the entropy from above.
Feedback for a wrong answer
Not yet. In blocks of two the code costs , and in three . Keep going.
Hint
Try longer blocks, one after another, and watch the count under the lower tape.
Worked solution
- A block of one flip: two one-bit codewords, bit per flip.
- Blocks of : . Blocks of : .
- Blocks of : .
- Set Code block size to . At five and six the cost keeps falling slowly, toward .
A single flip does not compress, because a codeword cannot be shorter than one bit.
Practice · Choose
Question
In Huffman’s code for blocks of four flips of a 90% coin, the block four heads, the most common of all, gets a one-bit codeword. What does the block four tails, the rarest of all, get?
Correct answer
Correct A codeword longer than four bits
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 90 %fixed
- Code block size
- 4 flipsfixed
- Measure and compress
- Compressed
Choices
Shown in a random order.
Correct A codeword longer than four bits
Wrong Four bits, as on the upper tape
Feedback
If every block but one got four bits, there would be no room for a one-bit word: such a word “uses up” half of all possible words, because no other word may start with it.
Wrong Also one bit
Feedback
Two blocks cannot share a codeword, or the receiver would not know which one was sent.
Feedback for a right answer
Ten bits. So that no codeword is the start of another, the short words of the common blocks “use up” room, and the rare blocks pay with long words. Four tails is so rare, probability , that the price hardly shows in the average.
Hint
A one-bit word is the start of half of all possible words. Who pays for that?
Worked solution
- In a code where no word is the start of another, the tape can be read with no gaps.
- The word 0 for four heads rules out every other word that starts with 0: half of all words.
- The other blocks must start with 1, so some of them get words longer than four bits.
- The rarest blocks, four tails among them, get the longest: ten bits.
A good code does not give every block the same length. It gives short words to what is common, and long ones to what is rare.
Practice · Choose
Question
A coin lands heads 90% of the time. Someone offers a clever code that records its flips, losing none, at bits per flip on average, over millions of flips. What do you make of it?
Correct answer
Correct It is impossible: the entropy, bits per flip, is the limit
Setup, choices and feedback
The Scene at this step
- Chance of heads
- 90 %
- Code block size
- 6 flips
- Measure and compress
- Compressed
Choices
Shown in a random order.
Correct It is impossible: the entropy, bits per flip, is the limit
Wrong It is possible, given long enough blocks
Misconception: Thinks any data can be squeezed below its entropy: with a cleverer code, longer blocks, or by compressing the compressed result again.
Feedback from the catalogue
Shannon proved that no code that loses nothing can spend fewer bits on average than the entropy. For a 90% coin the limit is bits a flip: longer blocks bring the code close to it, but never past it. A fair coin, with an entropy of , cannot be compressed at all. And a tape that has already been compressed looks like a fair coin, so compressing it a second time saves nothing more.
Wrong It is possible: compress the compressed tape a second time
Misconception: Thinks any data can be squeezed below its entropy: with a cleverer code, longer blocks, or by compressing the compressed result again.
Feedback from the catalogue
Shannon proved that no code that loses nothing can spend fewer bits on average than the entropy. For a 90% coin the limit is bits a flip: longer blocks bring the code close to it, but never past it. A fair coin, with an entropy of , cannot be compressed at all. And a tape that has already been compressed looks like a fair coin, so compressing it a second time saves nothing more.
Feedback for a right answer
Shannon proved that no code that loses nothing can spend fewer bits on average than the entropy. Longer blocks bring the code close to , but not below. And a compressed tape already looks random, with an entropy of about one bit per bit, so a second compression gives nothing.
Hint
What did Shannon prove about the entropy and every code that loses nothing?
Worked solution
- The entropy of a 90% coin: bits per flip.
- By Shannon, every code that loses nothing spends at least bits per flip on average.
- , so the offer is impossible.
The ways around the limit do not work either: in blocks of six flips the code costs , right at the limit, and a tape that is already compressed hardly compresses further.
Lesson 4 of 5 · About 20 minutes
The parity bit
A noisy line flips bits: how many blocks arrive wrong, how one parity bit catches a flip, and what it cannot catch.
The 5 steps and their answers
Practice · Calculate
Question
Chance a bit flips is fixed at 5%. Each block carries four bits, and each bit flips independently of the others. What is the chance that a block arrives with at least one error? Answer in per cent.
Correct answer
18.55 ± 0.2
Setup, choices and feedback
The Scene at this step
- Chance a bit flips
- 5 %fixed
- Check and repair
- Bare bitsfixed
- Accepted within
- ± 0.2
- Computed from the Scene at this step’s setting
- Chance a block of four bare data bits arrives wrong (0..1)
/nodes/link/outputs/rawBlockError
Wrong answers it recognises
20 ± 0.2
Misconception: Adds the chances of independent events (4 × 5% = 20%) instead of working out the chance through the complement, 1 − (1 − p)ⁿ.
Feedback from the catalogue
Adding chances works only for disjoint events, which cannot happen together. Flips of different bits can happen together, so adding counts twice the blocks in which two bits flipped, and with enough bits it would pass 100%. Use the complement: a block arrives intact only if every bit survives, , so the chance of at least one error is . For four bits at 5%: , not 20%.
Feedback for a right answer
, that is about 18.5%: roughly one block in five. A block is intact only if all four bits survive, , and the rest are wrong.
Hint
The complement is easier: what is the chance that all four bits survive?
Worked solution
- Each bit survives with chance .
- The bits are independent, so all four survive with chance .
- The complement: at least one error with chance .
- The answer: about 18.5%.
If you got 20%, you added . Adding counts twice the blocks in which two bits flipped, so it comes out too big.
Practice · Predict, then look
Question
Now a storm hits the line: Chance a bit flips goes up to 15% for each bit. Roughly what share of four-bit blocks will arrive wrong?
Correct answer
Correct About half: roughly 48%
Setup, choices and feedback
The Scene at this step
- Chance a bit flips
- 5 %fixed
- Check and repair
- Bare bitsfixed
Choices
Correct About half: roughly 48%
Wrong 60%: four times 15%
Misconception: Adds the chances of independent events (4 × 5% = 20%) instead of working out the chance through the complement, 1 − (1 − p)ⁿ.
Feedback from the catalogue
Adding chances works only for disjoint events, which cannot happen together. Flips of different bits can happen together, so adding counts twice the blocks in which two bits flipped, and with enough bits it would pass 100%. Use the complement: a block arrives intact only if every bit survives, , so the chance of at least one error is . For four bits at 5%: , not 20%.
Wrong 15%, the same as one bit’s chance
Feedback
A block is wrong if any of its four bits flipped, so it is hit more often than any one bit on its own.
Once the prediction is locked in, the Scene changes
- Chance a bit flips
- 15 %fixed
The Scene then shows: 0.478 · Chance a block of four bare data bits arrives wrong (0..1)
/nodes/link/outputs/rawBlockErrorA prediction is never marked as a failure: the learner sees the outcome and the explanation either way.
Feedback for a right answer
. Almost every other block arrives with an error, and without a code the receiver cannot tell which.
Hint
Work out the chance a block survives: .
Worked solution
- Each bit survives with chance .
- All four survive with chance .
- At least one error: , about 48%.
If you chose 60%, you added the chances. With seven bits adding would give 105%, more than certainty, which shows it cannot be right.
Practice · Reach the target
Question
Change Chance a bit flips until about one block in ten, 10%, arrives with an error, then press Check.
Goal
0.1 ± 0.01
At the start of the step: 0.3439
Setup, choices and feedback
The Scene at this step
- Chance a bit flips
- 10 %
- Check and repair
- Bare bitsfixed
- Read from the Scene at
- Chance a block of four bare data bits arrives wrong (0..1)
/nodes/link/outputs/rawBlockError
One setting that reaches it
- Chance a bit flips
- 2.5 %
Feedback for a right answer
About 2.5% per bit: . When the chance is small, adding, , comes close, because hardly any block is hit twice. As the noise grows, the gap between adding and the right answer grows.
Feedback for a wrong answer
Not yet. Look for a chance per bit at which .
Hint
When the chances are small, a block is hit about four times as often as a bit.
Worked solution
- You want , that is .
- , so .
- On the slider, in half-per-cent steps: 2.5% gives .
- Set Chance a bit flips to 2.5%.
Practice · Choose
Question
You send the four bits 1 0 1 1, and add a parity bit so that the count of 1s in all five bits is even. What is the parity bit?
Correct answer
Correct
Setup, choices and feedback
The Scene at this step
- Chance a bit flips
- 5 %
- Check and repair
- Bare bitsfixed
Choices
Correct
Wrong
Feedback
1 0 1 1 has three 1s. With a parity bit of there are still three, and three is odd.
Feedback for a right answer
1 0 1 1 has three 1s, and a parity bit of brings the count to four. If one bit flips on the way, the count will be odd, and the receiver will know something went wrong.
Hint
Count the 1s in the four bits. What must you add to make the count even?
Worked solution
- Count the 1s in 1 0 1 1: three.
- Three is odd, so one more is needed.
- The parity bit is , and the block 1 0 1 1 1 holds four 1s.
The parity bit says nothing about the data itself. It only makes the count even, so that a single flip stands out.
Practice · Choose
Question
A block of four data bits and a parity bit sets out, and on the way two of its bits flip. What does the receiver see when it counts the 1s?
Correct answer
Correct The count is even: the check passes, and the error goes unnoticed
Setup, choices and feedback
The Scene at this step
- Chance a bit flips
- 5 %
- Check and repair
- Bare bitsfixed
Choices
Shown in a random order.
Correct The count is even: the check passes, and the error goes unnoticed
Wrong The count is odd: the check fails
Misconception: Thinks a parity bit catches every error, however many bits flip.
Feedback from the catalogue
A parity bit only checks whether the count of 1s is even. Each flip changes the count by one, so one flip, or three, makes it odd and the check fails. But two flips change it by two, and the count stays even: the check passes, and the wrong block is taken as good. One parity check catches every odd number of flips, and misses every even number.
Wrong The check fails and shows which two bits flipped
Misconception: Thinks a failing parity check shows which bit flipped.
Feedback from the catalogue
One parity check answers just one yes-or-no question: is the count of 1s even? When it fails, any bit in the block could be to blame, the parity bit included, and the receiver can only ask for the block again. To find where the error is takes several overlapping checks, as in Hamming’s code: their answers together point to one position.
Feedback for a right answer
Each flip changes the count by one, and two flips change it by two: an even number stays even. One parity bit catches every odd number of flips, and misses every even number.
Hint
By how much does the count of 1s change when one bit flips? And when two flip?
Worked solution
- Before sending, the block’s count of 1s is even.
- Each flip adds one or takes one away, so it changes the parity.
- Two flips change the parity twice, and it is even again.
- The check passes, and the wrong block is taken as good.
Even when a parity check fails, it does not say which bit is to blame. It answers one question only: even or not.
Lesson 5 of 5 · About 25 minutes
Hamming's code
Three overlapping parity checks find which bit flipped and repair it: how to read them as a number in base 2, what happens when two bits flip, and what it costs.
The 6 steps and their answers
Practice · Predict, then look
Question
The line is perfectly quiet, but Faulty bit is 6: in every block the bit in position 6 flips. Which of the checks A, B and C will fail? Choose, and then Look inside moves to Parity checks.
Correct answer
Correct B and C
Setup, choices and feedback
The Scene at this step
- Chance a bit flips
- 0 %fixed
- Faulty bit
- 6fixed
- Bare bits / Repaired
- Bare bits
Choices
Correct B and C
Wrong A and B
Misconception: Reads the failing checks A B C as a binary number with A as the highest digit, instead of C B A.
Feedback from the catalogue
In Hamming’s code check A covers the positions whose number has its bit set, B its bit, and C its bit. So A is the lowest digit: read the checks in the order C B A. When B and C fail and A passes, write 1 1 0, that is . Reading them as A B C gives 0 1 1, that is , and the receiver would flip a good bit.
Wrong All three, because a flip spoils the whole block
Feedback
Each check counts only the positions it covers. A check that does not cover position 6 does not notice it flip.
Once the prediction is locked in, the Scene changes
- Bare bits / Repaired
- Parity checks
The Scene then shows: 6 · The failing checks read as the binary number C B A (0 when all pass): the position of a lone flip
/nodes/link/outputs/syndromeA prediction is never marked as a failure: the learner sees the outcome and the explanation either way.
Feedback for a right answer
B and C. Position 6 is in check B (positions 2, 3, 6, 7) and in check C (positions 4, 5, 6, 7), but not in A. Read the checks in the order C B A: 1 1 0, which is 6 in base 2.
Hint
A covers 1, 3, 5, 7; B covers 2, 3, 6, 7; C covers 4, 5, 6, 7. Which of them contain 6?
Worked solution
- Write 6 in base 2: , that is 110.
- The bit is set: check C covers position 6 and fails.
- The bit is set: check B covers it and fails.
- The bit is clear: check A does not cover it and passes.
If you chose A and B, you read 110 left to right as A B C. But A is the lowest digit, the ones digit.
Practice · Calculate
Question
A new fault on the line, and this time you are not shown where. In every block checks A and B fail, and check C passes. In which position does the bit flip?
Correct answer
3 ± 0.1
Setup, choices and feedback
The Scene at this step
- Chance a bit flips
- 0 %fixed
- Faulty bit
- 3hidden
- Bare bits / Repaired
- Bare bitsfixed
- Accepted within
- ± 0.1
- Computed from the Scene at this step’s setting
- The failing checks read as the binary number C B A (0 when all pass): the position of a lone flip
/nodes/link/outputs/syndrome
Wrong answers it recognises
6 ± 0.1
Misconception: Reads the failing checks A B C as a binary number with A as the highest digit, instead of C B A.
Feedback from the catalogue
In Hamming’s code check A covers the positions whose number has its bit set, B its bit, and C its bit. So A is the lowest digit: read the checks in the order C B A. When B and C fail and A passes, write 1 1 0, that is . Reading them as A B C gives 0 1 1, that is , and the receiver would flip a good bit.
Feedback for a right answer
Position 3: the only one in A and B but not in C. In the order C B A the checks spell 0 1 1, that is . The receiver flips that bit, and the block is repaired.
Hint
Write for each check that failed and for each that passed, in the order C B A.
Worked solution
- C passed, B failed, A failed: in the order C B A that is 0 1 1.
- In base 2: .
- Check: position 3 is in A (1, 3, 5, 7) and in B (2, 3, 6, 7), not in C (4, 5, 6, 7).
- The bit flips in position 3.
If you answered 6, you read the checks in the order A B C, 1 1 0. Position 6 is in B and C, not in A.
Practice · Reach the target
Question
Change Faulty bit until only check C fails, while A and B pass. Press Check.
Goal
0 ± 0.1
At the start of the step: 0
0 ± 0.1
At the start of the step: 0
1 ± 0.1
At the start of the step: 0
Setup, choices and feedback
The Scene at this step
- Chance a bit flips
- 0 %fixed
- Faulty bit
- 0
- Bare bits / Repaired
- Parity checksfixed
- Read from the Scene at
- 1 when check A (positions 1 3 5 7) fails for a block whose only flip is at fault, else 0
/nodes/link/outputs/checkA - Read from the Scene at
- 1 when check B (positions 2 3 6 7) fails for a block whose only flip is at fault, else 0
/nodes/link/outputs/checkB - Read from the Scene at
- 1 when check C (positions 4 5 6 7) fails for a block whose only flip is at fault, else 0
/nodes/link/outputs/checkC
One setting that reaches it
- Faulty bit
- 4
Feedback for a right answer
Position 4, 100 in base 2: it is inside circle C only, and it is C’s parity bit. A parity bit can flip on the way too, and the code finds it like any other bit.
Feedback for a wrong answer
Not yet. Watch the red circles on the board: only C should be red.
Hint
Which position is inside circle C and no other circle?
Worked solution
- You want the pattern C B A = 1 0 0.
- In base 2 that is .
- Position 4 is in check C (4, 5, 6, 7) only.
- Set Faulty bit to .
Positions 1, 2 and 4, the powers of 2, are exactly the positions inside one circle only. That is why the parity bits sit there: each belongs to its own check.
Practice · Choose
Question
In one block two bits flip, in positions 3 and 5. What does the receiver do?
Correct answer
Correct Checks B and C fail, and it flips position 6, which was fine: the block ends up with three errors
Setup, choices and feedback
The Scene at this step
- Chance a bit flips
- 5 %
- Faulty bit
- 0fixed
- Bare bits / Repaired
- Repaired
Choices
Shown in a random order.
Correct Checks B and C fail, and it flips position 6, which was fine: the block ends up with three errors
Wrong It finds both errors and repairs both
Misconception: Thinks a Hamming code repairs any number of flipped bits in a block.
Feedback from the catalogue
The Hamming (7,4) code repairs one flip in a block. When two bits flip, the checks that fail are those of one flip or the other but not both, and the pattern points to a third bit that was fine. The receiver dutifully flips it, and the block ends up with three errors. So even with the code some blocks arrive wrong: on a line that flips 5% of bits, about 4.4% of them.
Wrong Every check passes, and it leaves the block alone
Feedback
In check A, which covers both 3 and 5, the two flips do cancel. But B covers only 3, and C only 5, so both of them fail.
Feedback for a right answer
A covers both 3 and 5, and the two flips cancel in it. B covers only 3, and C only 5, so they fail: C B A = 1 1 0, that is 6. The receiver flips position 6, which was fine. The code assumes at most one flip in a block, and when that fails, so does it.
Hint
For each check on its own: how many of positions 3 and 5 does it cover? An even number of flips does not make it fail.
Worked solution
- Check A (1, 3, 5, 7) covers 3 and 5: two flips, the count stays even, A passes.
- Check B (2, 3, 6, 7) covers only 3: B fails.
- Check C (4, 5, 6, 7) covers only 5: C fails.
- C B A = 1 1 0 = 6, and the receiver flips position 6.
- Now three bits are wrong: 3, 5 and 6.
The Hamming (7,4) code repairs one flip in a block. Repairing two takes a code with more parity bits.
Practice · Calculate
Question
Chance a bit flips is fixed at 5%, and the code repairs. A coded block arrives wrong only if two or more of its seven bits flipped. What is the chance of that? Answer in per cent.
Correct answer
4.438 ± 0.1
Setup, choices and feedback
The Scene at this step
- Chance a bit flips
- 5 %fixed
- Faulty bit
- 0fixed
- Bare bits / Repaired
- Repairedfixed
- Accepted within
- ± 0.1
- Computed from the Scene at this step’s setting
- Chance a Hamming (7,4) block takes two or more flips and is decoded wrong (0..1)
/nodes/link/outputs/codedBlockError
Wrong answers it recognises
0 ± 0.1
Misconception: Thinks a Hamming code repairs any number of flipped bits in a block.
Feedback from the catalogue
The Hamming (7,4) code repairs one flip in a block. When two bits flip, the checks that fail are those of one flip or the other but not both, and the pattern points to a third bit that was fine. The receiver dutifully flips it, and the block ends up with three errors. So even with the code some blocks arrive wrong: on a line that flips 5% of bits, about 4.4% of them.
Feedback for a right answer
About 4.4%: . Without the code 18.5% of blocks arrive wrong; the code cuts that fourfold, at the price of three extra bits for every four.
Hint
Work out the complement: no flip, , or exactly one flip, .
Worked solution
- A coded block is repaired if zero or one of its bits flipped.
- No flip: .
- Exactly one flip: possible positions, .
- Two or more flips: , about 4.4%.
If you answered , you thought the code repairs everything. It repairs one flip in a block, and two flips fool it.
Practice · Calculate
Question
The message HELLO is five characters, eight bits each, sent in blocks of four bits. How many bits does one copy of it take on the line with Hamming’s code?
Correct answer
70 ± 0.1
Setup, choices and feedback
The Scene at this step
- Chance a bit flips
- 5 %fixed
- Faulty bit
- 0fixed
- Bare bits / Repaired
- Repairedfixed
- Accepted within
- ± 0.1
- Computed from the Scene at this step’s setting
- Bits one copy of the message takes on the line with the code: seven for every four, fourteen per character
/nodes/link/outputs/codedBits
Wrong answers it recognises
40 ± 0.1
Misconception: Forgets that the parity bits travel down the line too, and counts only the message's own bits.
Feedback from the catalogue
Parity bits do not come for free: they are sent down the line like any other bit. In the Hamming (7,4) code every four data bits leave as seven, so one character, eight bits, takes fourteen on the line. That is the price of repair: three bits out of every seven carry no part of the message.
Feedback for a right answer
bits: data bits make blocks, and each block leaves as seven bits. of them are parity bits, which carry no part of the message. That is the price of repair: the line carries data at only of its rate.
Hint
How many blocks of four bits are in the message, and how many bits leave for each block?
Worked solution
- The message: data bits.
- In blocks of four: blocks.
- Each coded block is bits: .
- One copy takes bits on the line.
If you answered , you counted only the message’s bits. The parity bits travel down the line like any other bit.
Across the unit · 13 misconceptions
Misconception catalogue
Each common mistake this unit recognises, in a few words. Open one for what the learner reads when an answer matches it, and where it is asked.
Takes information to be how important or meaningful a message is, not how much uncertainty it removes.
- The learner reads
In computer science information does not measure importance or meaning. It measures how much uncertainty a message removes: how much you did not know before it arrived. A message you knew in advance carries bits, however important it is. The result of a fair coin flip, which matters to nobody, carries one whole bit, because you could not have guessed it.
- Recognised in
Thinks the likely outcome carries more information, because it turns up more often.
- The learner reads
The surprise of an outcome depends on how unexpected it is: . The smaller the chance, the bigger the surprise. When a coin lands heads 90% of the time, heads carries only bits, because you guessed it in advance. The rare tails carries bits. Heads does turn up more often, but each time it tells you little.
- Recognised in
Gives the probability itself as the surprise or the entropy, instead of −log₂ p.
- The learner reads
The probability is not the surprise. The surprise of an outcome with probability is bits: how many times you halve the chance from to reach it. An outcome with probability carries one bit, not ; an outcome with probability carries two bits, not . The probability is a number between and , and the surprise grows as the probability gets smaller.
Gives the number of equally likely outcomes, 1/p, instead of the bits it takes to tell them apart, log₂ (1/p).
- The learner reads
is the number of equally likely outcomes: an outcome with probability is one of four equal possibilities. To tell four possibilities apart, two bits are enough, , , and , because each bit doubles the number of possibilities. So the surprise is the logarithm: , not . Eight possibilities take three bits, and a thousand about ten.
- Recognised in
Averages the surprises (or codeword lengths) as if every outcome were equally likely, without weighting each by its probability.
- The learner reads
Entropy, and the average cost of a code too, is a weighted average: each value counts by its probability. With a 90% coin, heads turns up in nine flips out of ten and tails in one, so , not . A plain average treats the rare tails as if it turned up in half the flips.
Thinks a random-looking stream with no pattern carries little information, because it means nothing.
- The learner reads
The opposite is true. Information in Shannon’s sense is uncertainty, and a random stream with no pattern is as unpredictable as anything can be: you cannot guess its next bit, so every bit surprises. Its entropy is close to one bit per bit, the most there is. A stream that is almost all 1s is easy to guess, and its entropy is close to zero. That is also why a compressed or encrypted file looks like noise: everything predictable has already been taken out of it.
Thinks any data can be squeezed below its entropy: with a cleverer code, longer blocks, or by compressing the compressed result again.
- The learner reads
Shannon proved that no code that loses nothing can spend fewer bits on average than the entropy. For a 90% coin the limit is bits a flip: longer blocks bring the code close to it, but never past it. A fair coin, with an entropy of , cannot be compressed at all. And a tape that has already been compressed looks like a fair coin, so compressing it a second time saves nothing more.
Adds the chances of independent events (4 × 5% = 20%) instead of working out the chance through the complement, 1 − (1 − p)ⁿ.
- The learner reads
Adding chances works only for disjoint events, which cannot happen together. Flips of different bits can happen together, so adding counts twice the blocks in which two bits flipped, and with enough bits it would pass 100%. Use the complement: a block arrives intact only if every bit survives, , so the chance of at least one error is . For four bits at 5%: , not 20%.
Thinks a parity bit catches every error, however many bits flip.
- The learner reads
A parity bit only checks whether the count of 1s is even. Each flip changes the count by one, so one flip, or three, makes it odd and the check fails. But two flips change it by two, and the count stays even: the check passes, and the wrong block is taken as good. One parity check catches every odd number of flips, and misses every even number.
- Recognised in
Thinks a failing parity check shows which bit flipped.
- The learner reads
One parity check answers just one yes-or-no question: is the count of 1s even? When it fails, any bit in the block could be to blame, the parity bit included, and the receiver can only ask for the block again. To find where the error is takes several overlapping checks, as in Hamming’s code: their answers together point to one position.
- Recognised in
Reads the failing checks A B C as a binary number with A as the highest digit, instead of C B A.
- The learner reads
In Hamming’s code check A covers the positions whose number has its bit set, B its bit, and C its bit. So A is the lowest digit: read the checks in the order C B A. When B and C fail and A passes, write 1 1 0, that is . Reading them as A B C gives 0 1 1, that is , and the receiver would flip a good bit.
Thinks a Hamming code repairs any number of flipped bits in a block.
- The learner reads
The Hamming (7,4) code repairs one flip in a block. When two bits flip, the checks that fail are those of one flip or the other but not both, and the pattern points to a third bit that was fine. The receiver dutifully flips it, and the block ends up with three errors. So even with the code some blocks arrive wrong: on a line that flips 5% of bits, about 4.4% of them.
Forgets that the parity bits travel down the line too, and counts only the message's own bits.
- The learner reads
Parity bits do not come for free: they are sent down the line like any other bit. In the Hamming (7,4) code every four data bits leave as seven, so one character, eight bits, takes fourteen on the line. That is the price of repair: three bits out of every seven carry no part of the message.
- Recognised in