Math paradoxes

Glossary / Combinatorics

Glossary · combinatorics

Has anyone ever seen this exact order of cards?

Take an ordinary 52-card deck and shuffle it well. Decks have been played with for centuries, by millions of people every day, so it feels as if every order must have come up long ago. In fact your order is almost certainly new: no one has ever held it before. Combinatorics is the art of counting how many ways there are to arrange or choose things, without listing the ways one by one.

In plain wordspictures, analogies, small numbers

“In plain words” is hidden on all puzzles.

The shuffled deck paradox

Start with a small deck and add cards with the slider. Under the cards is how many different orders exist, and how long it would take to go through them all, laying out one order every second. How many cards does it take before the age of the universe is not enough?

Different orders–
Going through all, one per second–

How many cards it takes to keep going for longer than:

    No one has seen your order

    For a full deck there are about 8 · 1067 orders: an eight followed by 67 more digits. Imagine all 8 billion people shuffling a deck every second, starting at the Big Bang, 13.8 billion years ago. Together that makes about 3.5 · 1027 shuffles. That is a mere fraction 4 · 10−41 of all possible orders, which is to say nothing. For comparison, physicists estimate there are about 1050 atoms in the whole Earth, and there are hundreds of millions of billions of times more deck orders still.

    The secret is multiplication. Each new card doesn't add orders, it multiplies them: it can be slotted into any position of the row you already have. The seventh card multiplies by 7, the twentieth by 20, the fifty-second by 52.

    Rigoroustables, charts, formulas

    “Rigorous” is hidden on all puzzles.

    Permutations: n!

    A permutation is one way of lining up n different objects in a row. Any of the n can go first, any of the remaining n − 1 second, and so on to the last one. The number of ways is written n! and read "n factorial".

    n! = n · (n − 1) · … · 2 · 1 · 3! = 3 · 2 · 1 = 6 · 4! = 24 · 10! = 3 628 800

      Combinations: choosing k of n

      Often the order doesn't matter: all that matters is which objects were chosen. The number of ways to choose k objects out of n is written C(n, k) and read "n choose k".

      Worked example: a 6-of-49 lottery

      First count as if the order mattered: the first ball can be any of 49, the second any of 48, and so on to the sixth.

      49 · 48 · 47 · 46 · 45 · 44 = 10,068,347,520 ordered draws

      But a ticket is a set of six numbers, and the same six numbers can come out in 6! = 720 different orders. So we divide:

      C(49, 6) = 10,068,347,520 / 720 = 13,983,816 different tickets

      The chance of matching all six with one ticket is one in almost 14 million.

      Try it yourself

      Order matters–
      Order doesn't matter: C(n, k)–

      Pascal's triangle

      All the C(n, k) fit neatly into a triangle: row n holds C(n, 0), C(n, 1), … C(n, n). The edges are always ones, and each number inside is the sum of the two above it. Tap any number.

      –

      When order matters and when it doesn't

      • A podium: order matters8 runners, gold, silver and bronze: 8 · 7 · 6 = 336 outcomes. Who is first and who is third makes a different result.
      • A team: order doesn't matterPicking three of the same eight for a team: C(8, 3) = 336 / 3! = 56. Six times fewer, because each trio can be lined up in 6 ways.
      • A poker hand is a setFive cards out of 52, and the order they were dealt in doesn't matter: C(52, 5) = 2,598,960 different hands.
      • Repeats are another storyIn a PIN digits may repeat, so it is neither a permutation nor a combination: 10 · 10 · 10 · 10 = 10,000 codes.
      • Ask: "what if I swap them?"If swapping two of the chosen objects changes the outcome, count with order. If not, divide by k!.
      Deepergeneralisations, theory, history

      “Deeper” is hidden on all puzzles.

      Where the combinations formula comes from

      The number of ordered choices of k objects out of n is n · (n − 1) · … · (n − k + 1). This product is n! with the tail (n − k)! cut off. Each unordered set of k objects was counted exactly k! times, once for each of its orderings. So we also divide by k!:

      n · (n − 1) · … · (n − k + 1) = n! / (n − k)! ⇒ C(n, k) = n! / (k! · (n − k)!)

      This shows the symmetry C(n, k) = C(n, n − k) straight away: choosing 6 balls out of 49 is the same as choosing the 43 that are left out of the ticket. That is why Pascal's triangle is symmetric.

      Why each number is the sum of the two above

      C(n, k) = C(n − 1, k − 1) + C(n − 1, k)

      Mark one of the n objects, say the ace of spades. All sets of k objects split into two piles that don't overlap. Either the ace is in the set: then the other k − 1 come from the remaining n − 1, which is C(n − 1, k − 1) ways. Or the ace isn't: then all k come from the n − 1, which is C(n − 1, k). Together that is every set, each exactly once.

      –

      The same idea explains why row n adds up to 2n: each object is either taken or not, so the sets of every size together number 2 · 2 · … · 2.

      Stirling's formula: n! without multiplying

      n! ≈ √(2πn) · (n / e)n

      Multiplying 52 numbers takes a while, but James Stirling found a shortcut back in 1730. For twenty it is off by less than half a percent, and the larger n, the more accurate: the relative error is about 1 / (12n). Compare it with the exact value.

      Exact n!–
      By Stirling–
      Error–
      Estimate 1 / (12n)–

      Where do π and e come from? The logarithm of a factorial is the sum ln 1 + ln 2 + … + ln n, and that sum is almost the area under the curve ln x, roughly n ln n − n. That gives the factor (n / e)n. The root √(2πn) is a finer correction, and its π comes from the same integral that gives the area under the Gaussian curve of the normal distribution.

      Where it shows up

      Other terms