A113 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 2n words of n bits have exactly k ones: (nk)/2n.
  • Change n. Where is the peak? Watch the readouts: how fast do the counts grow?
  • The r slider moves the marker; the readout gives the count for k=r. Check that (nk)=(nn−k).

Predict

How many different 8-bit bytes contain exactly two 1s?

Name it

The multiplication rule

If a choice is made in stages, with n1 options at the first stage, n2 at the second and so on, the number of outcomes is n1n2⋯. A 6-digit PIN has 106 possibilities; an n-bit word has 2n.

Ordered choices: permutations

Choosing k things from n in order, without repeats:

n(n−1)⋯(n−k+1)=n!(n−k)!

All n of them in order: n!.

Unordered choices: combinations

Choosing k from n when order doesn't matter, the binomial coefficient:

(nk)=n!k!(n−k)!

Each unordered set appears k! times among the ordered choices, so divide by k!. Two facts worth knowing: (nk)=(nn−k) (choosing the ones is choosing the zeros), and ∑k(nk)=2n.

Error patterns

If each bit of an n-bit word flips independently with probability p, a particular pattern with k errors has chance pk(1−p)n−k, and there are (nk) such patterns:

P(k errors)=(nk)pk(1−p)n−k

This is the binomial distribution, lesson 9's first named distribution.

Sampling without replacement

Draw k items from N, of which D are defective. Every set of k is equally likely, so

P(no defective)=(N−Dk)(Nk)

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
  1. No errors. P(0)=0.998=0.9227
  2. Exactly one error. P(1)=(81)(0.01)(0.99)7=0.0746
  3. The code succeeds in either case. 0.9227+0.0746=0.9973
  4. 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
  1. Count the samples. All 3 chips must come from the 48 good ones: P=(483)(503)=48⋅47⋅4650⋅49⋅48=47×4650×49=0.882
  2. What it means. Sampling only 3 chips misses the bad ones 88% of the time, which is why acceptance sampling uses larger samples.
  3. With replacement. Drawing with replacement would give (4850)3=0.885 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
  1. Count the words. There are (42)=6 ways to choose which two bits are 1, out of 24=16 equally likely words: 616=0.375
  2. 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 p=12.

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 ∑k=010(10k)?

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 N chips has D 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°.

Explain why

Why do you divide by k! when order doesn't matter?

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.