A11 · Lesson 3 · Counting
Permutations, combinations and error patterns
How many 8-bit bytes have exactly two 1s? How many 6-digit PINs are there? If a reel of 50 chips has 2 bad ones and you test 3 at random, how likely are you to miss both? When outcomes are equally likely, every one of these is a counting problem, and the sample spaces are far too big to list. A few counting rules handle them all, and one of them, the binomial coefficient, will run through the rest of the course: it counts the ways errors can land in a code word.
- The bars show what share of all words of bits have exactly ones: .
- Change . Where is the peak? Watch the readouts: how fast do the counts grow?
- The slider moves the marker; the readout gives the count for . Check that .
Predict
How many different 8-bit bytes contain exactly two 1s?
- Choose which two of the eight positions hold the 1s. There are ways to pick them in order, but each pair is picked twice (first 3 then 5, or first 5 then 3), so . That's .
Name it
The multiplication rule
If a choice is made in stages, with options at the first stage, at the second and so on, the number of outcomes is . A 6-digit PIN has possibilities; an -bit word has .
Ordered choices: permutations
Choosing things from in order, without repeats:
All of them in order: .
Unordered choices: combinations
Choosing from when order doesn't matter, the binomial coefficient:
Each unordered set appears times among the ordered choices, so divide by . Two facts worth knowing: (choosing the ones is choosing the zeros), and .
Error patterns
If each bit of an -bit word flips independently with probability , a particular pattern with errors has chance , and there are such patterns:
This is the binomial distribution, lesson 9's first named distribution.
Sampling without replacement
Draw items from , of which are defective. Every set of is equally likely, so
Worked example
An 8-bit word goes over a link where each bit flips with probability 0.01. A single-error-correcting code fixes the word if at most one bit is wrong. How often does it succeed?
Show the solution
- No errors.
- Exactly one error.
- The code succeeds in either case.
- Compare. Uncorrectable words drop from 7.7% to 0.27%.
Answer the code succeeds with probability 0.9973.
Worked example
A reel of 50 chips has 2 bad ones. You test 3 at random. What's the chance of finding neither bad chip?
Show the solution
- Count the samples. All 3 chips must come from the 48 good ones:
- What it means. Sampling only 3 chips misses the bad ones 88% of the time, which is why acceptance sampling uses larger samples.
- With replacement. Drawing with replacement would give nearly the same, because the sample is small.
Answer the chance of finding neither bad chip is 0.882.
Worked example
A random 4-bit word has each bit equally likely to be 0 or 1. What is the chance it has exactly two 1s?
Show the solution
- Count the words. There are ways to choose which two bits are 1, out of equally likely words:
- The whole distribution. The full distribution of the count is 1, 4, 6, 4, 1 out of 16: a row of Pascal's triangle, the binomial distribution with .
Answer the chance of exactly two 1s is 0.375.
Check
How many 8-bit words have exactly 2 ones?
Check
How many 6-digit PINs are there, if digits may repeat?
Check
2 different test jobs go to 2 of 5 machines, one each. In how many ways can they be assigned?
Check
Each bit of an 8-bit word flips with probability 0.05, independently. What is the chance of exactly 1 errors?
Check
A batch of 20 parts has 2 defective. You test 5 at random. What is the chance none of them is defective?
Check
What is ?
Check
A word has 8 bits, each flipped independently with probability 0.01.
(a)
In how many ways can exactly 2 bits flip?
(b)
What is the chance of exactly 2 flips?
Check
A reel of chips has bad ones; you test 2 at random.
Step 1
What is the chance both are good?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is the chance of finding at least one bad chip?
Explain why
Why do you divide by when order doesn't matter?
Counting ordered choices treats picking positions 3 then 5 as different from 5 then 3. Any particular set of positions can be listed in orders, and the ordered count includes every one of them. So the ordered count is times too big for the question "which positions", and dividing by leaves each set counted once.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.