03A - Counting Notes - G, Study notes of Computer science

03A - Counting Notes - Great T

Typology: Study notes

2025/2026

Uploaded on 05/02/2026

qwartz-brinz
qwartz-brinz 🇶🇦

20 documents

1 / 64

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 16
Counting
16.1 Why Count?
Are there two different subsets of the ninety 25-digit numbers shown below that
have the same sum —for example, maybe the sum of the numbers in the first col-
umn is equal to the sum of the numbers in the second column?
0020480135385502964448038
5763257331083479647409398
0489445991866915676240992
5800949123548989122628663
1082662032430379651370981
6042900801199280218026001
1178480894769706178994993
6116171789137737896701405
1253127351683239693851327
6144868973001582369723512
1301505129234077811069011
6247314593851169234746152
1311567111143866433882194
6814428944266874963488274
1470029452721203587686214
6870852945543886849147881
1578271047286257499433886
6914955508120950093732397
1638243921852176243192354
6949632451365987152423541
1763580219131985963102365
7128211143613619828415650
1826227795601842231029694
7173920083651862307925394
1843971862675102037201420
7215654874211755676220587
2396951193722134526177237
7256932847164391040233050
2781394568268599801096354
7332822657075235431620317
2796605196713610405408019
7426441829541573444964139
2931016394761975263190347
7632198126531809327186321
2933458058294405155197296
7712154432211912882310511
3075514410490975920315348
3171004832173501394113017
8247331000042995311646021
3208234421597368647019265
8496243997123475922766310
3437254656355157864869113
8518399140676002660747477
3574883393058653923711365
8543691283470191452333763
3644909946040480189969149
8675309258374137092461352
3790044132737084094417246
8694321112363996867296665
3870332127437971355322815
8772321203608477245851154
4080505804577801451363100
8791422161722582546341091
4167283461025702348124920
9062628024592126283973285
4235996831123777788211249
9137845566925526349897794
4670939445749439042111220
9153762966803189291934419
4815379351865384279613427
9270880194077636406984249
4837052948212922604442190
9324301480722103490379204
5106389423855018550671530
9436090832146695147140581
5142368192004769218069910
9475308159734538249013238
5181234096130144084041856
9492376623917486974923202
5198267398125617994391348
9511972558779880288252979
5317592940316231219758372
9602413424619187112552264
5384358126771794128356947
331
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40

Partial preview of the text

Download 03A - Counting Notes - G and more Study notes Computer science in PDF only on Docsity!

Chapter 16

Counting

16.1 Why Count?

Are there two different subsets of the ninety 25-digit numbers shown below that have the same sum —for example, maybe the sum of the numbers in the first col umn is equal to the sum of the numbers in the second column?

0020480135385502964448038 5763257331083479647409398 0489445991866915676240992 5800949123548989122628663 1082662032430379651370981 6042900801199280218026001 1178480894769706178994993 6116171789137737896701405 1253127351683239693851327 6144868973001582369723512 1301505129234077811069011 6247314593851169234746152 1311567111143866433882194 6814428944266874963488274 1470029452721203587686214 6870852945543886849147881 1578271047286257499433886 6914955508120950093732397 1638243921852176243192354 6949632451365987152423541 1763580219131985963102365 7128211143613619828415650 1826227795601842231029694 7173920083651862307925394 1843971862675102037201420 7215654874211755676220587 2396951193722134526177237 7256932847164391040233050 2781394568268599801096354 7332822657075235431620317 2796605196713610405408019 7426441829541573444964139 2931016394761975263190347 7632198126531809327186321 2933458058294405155197296 7712154432211912882310511 3075514410490975920315348

3171004832173501394113017 8247331000042995311646021 3208234421597368647019265 8496243997123475922766310 3437254656355157864869113 8518399140676002660747477 3574883393058653923711365 8543691283470191452333763 3644909946040480189969149 8675309258374137092461352 3790044132737084094417246 8694321112363996867296665 3870332127437971355322815 8772321203608477245851154 4080505804577801451363100 8791422161722582546341091 4167283461025702348124920 9062628024592126283973285 4235996831123777788211249 9137845566925526349897794 4670939445749439042111220 9153762966803189291934419 4815379351865384279613427 9270880194077636406984249 4837052948212922604442190 9324301480722103490379204 5106389423855018550671530 9436090832146695147140581 5142368192004769218069910 9475308159734538249013238 5181234096130144084041856 9492376623917486974923202 5198267398125617994391348 9511972558779880288252979 5317592940316231219758372 9602413424619187112552264 5384358126771794128356947

331

332 CHAPTER 16. COUNTING

7858918664240262356610010 9631217114906129219461111 8149436716871371161932035 3157693105325111284321993 3111474985252793452860017 5439211712248901995423441 7898156786763212963178679 9908189853102753335981319 3145621587936120118438701 5610379826092838192760458 8147591017037573337848616 9913237476341764299813987 3148901255628881103198549 5632317555465228677676044 5692168374637019617423712 8176063831682536571306791

Finding two subsets with the same sum may seem like an silly puzzle, but solving problems like this turns out to be useful, for example in finding good ways to fit packages into shipping containers and in decoding secret messages. The answer to the question turns out to be “yes.” Of course this would be easy to confirm just by showing two subsets with the same sum, but that turns out to be kind of hard to do. So before we put a lot of effort into finding such a pair, it would be nice to be sure there were some. Fortunately, it is very easy to see why there is such a pair —or at least it will be easy once we have developed a few simple rules for counting things.

The Contest to Find Two Sets with the Same Sum

One term, Eric Lehman, a 6.042 instructor who contributed to many parts of this book, offered a $100 prize for being the first 6.042 student to actually find two different subsets of the above ninety 25-digit numbers that have the same sum. Eric didn’t expect to have to pay off this bet, but he underestimated the ingenuity and initiative of 6.042 students. One computer science major wrote a program that cleverly searched only among a reasonably small set of “plausible” sets, sorted them by their sums, and actually found a couple with the same sum. He won the prize. A few days later, a math major figured out how to reformulate the sum problem as a “lattice basis reduc tion” problem; then he found a software package implementing an efficient basis reduction procedure, and using it, he very quickly found lots of pairs of subsets with the same sum. He didn’t win the prize, but he got a standing ovation from the class —staff included.

Counting seems easy enough: 1, 2, 3, 4, etc. This direct approach works well for counting simple things —like your toes —and may be the only approach for ex tremely complicated things with no identifiable structure. However, subtler meth ods can help you count many things in the vast middle ground, such as:

  • The number of different ways to select a dozen doughnuts when there are five varieties available.
  • The number of 16-bit numbers with exactly 4 ones.

334 CHAPTER 16. COUNTING

Let’s consider a particular element of set A:

����^ 0 0^ ���� 0 � 0 0 0�� 0 0�^ ����0 0^ ����0 0

chocolate lemon-filled sugar^ glazed plain

We’ve depicted each doughnut with a 0 and left a gap between the different vari eties. Thus, the selection above contains two chocolate doughnuts, no lemon-filled, six sugar, two glazed, and two plain. Now let’s put a 1 into each of the four gaps:

����^ 0 0^1 ���� 1 0 � 0 0 0�� 0 0 �^1 ����0 0^1 ����0 0

chocolate lemon-filled sugar^ glazed plain

We’ve just formed a 16-bit number with exactly 4 ones— an element of B! This example suggests a bijection from set A to set B: map a dozen doughnuts consisting of:

c chocolate, l lemon-filled, s sugar, g glazed, and p plain

to the sequence:

�^0 .��^.. 0 �^1 �^0 .��^.. 0 �^1 �^0 .��^.. 0 �^1 �^0 .��^.. 0 �^1 �^0 .��^.. 0 �

c (^) l s g p

The resulting sequence always has 16 bits and exactly 4 ones, and thus is an element of B. Moreover, the mapping is a bijection; every such bit sequence is mapped to by exactly one order of a dozen doughnuts. Therefore, |A| = |B| by the Bijection Rule! This demonstrates the magnifying power of the bijection rule. We managed to prove that two very different sets are actually the same size— even though we don’t know exactly how big either one is. But as soon as we figure out the size of one set, we’ll immediately know the size of the other. This particular bijection might seem frighteningly ingenious if you’ve not seen it before. But you’ll use essentially this same argument over and over, and soon you’ll consider it routine.

16.2.2 Counting Sequences

The Bijection Rule lets us count one thing by counting another. This suggests a general strategy: get really good at counting just a few things and then use bijec tions to count everything else. This is the strategy we’ll follow. In particular, we’ll get really good at counting sequences. When we want to determine the size of some other set T , we’ll find a bijection from T to a set of sequences S. Then we’ll use our super-ninja sequence-counting skills to determine |S|, which immediately gives us |T |. We’ll need to hone this idea somewhat as we go along, but that’s pretty much the plan!

16.2. COUNTING ONE THING BY COUNTING ANOTHER 335

16.2.3 The Sum Rule

Linus allocates his big sister Lucy a quota of 20 crabby days, 40 irritable days, and 60 generally surly days. On how many days can Lucy be out-of-sorts one way or another? Let set C be her crabby days, I be her irritable days, and S be the generally surly. In these terms, the answer to the question is |C ∪ I ∪ S|. Now assuming that she is permitted at most one bad quality each day, the size of this union of sets is given by the Sum Rule:

Rule 1 (Sum Rule). If A 1 , A 2 ,... , An are disjoint sets, then:

|A 1 ∪ A 2 ∪... ∪ An| = |A 1 | + |A 2 | +... + |An|

Thus, according to Linus’ budget, Lucy can be out-of-sorts for:

|C ∪ I ∪ S| = |C| + |I| + |S| = 20 + 40 + 60 = 120 days

Notice that the Sum Rule holds only for a union of disjoint sets. Finding the size of a union of intersecting sets is a more complicated problem that we’ll take up later.

16.2.4 The Product Rule

The Product Rule gives the size of a product of sets. Recall that if P 1 , P 2 ,... , Pn are sets, then P 1 × P 2 ×... × Pn

is the set of all sequences whose first term is drawn from P 1 , second term is drawn from P 2 and so forth.

Rule 2 (Product Rule). If P 1 , P 2 ,... Pn are sets, then:

|P 1 × P 2 ×... × Pn| = |P 1 | · |P 2 | · · · |Pn|

Unlike the sum rule, the product rule does not require the sets P 1 ,... , Pn to be disjoint. For example, suppose a daily diet consists of a breakfast selected from set B, a lunch from set L, and a dinner from set D:

B = {pancakes, bacon and eggs, bagel, Doritos} L = {burger and fries, garden salad, Doritos} D = {macaroni, pizza, frozen burrito, pasta, Doritos}

Then B ×L×D is the set of all possible daily diets. Here are some sample elements:

(pancakes, burger and fries, pizza) (bacon and eggs, garden salad, pasta) (Doritos, Doritos, frozen burrito)

16.2. COUNTING ONE THING BY COUNTING ANOTHER 337

There is a natural bijection from subsets of X to n-bit sequences. Let x 1 , x 2 ,... , xn be the elements of X. Then a particular subset of X maps to the sequence (b 1 ,... , bn) where bi = 1 if and only if xi is in that subset. For example, if n = 10 , then the subset {x 2 , x 3 , x 5 , x 7 , x 10 } maps to a 10-bit sequence as follows:

subset: { x 2 , x 3 , x 5 , x 7 , x 10 } sequence: ( 0 , 1 , 1 , 0 , 1 , 0 , 1 , 0 , 0 , 1 )

We just used a bijection to transform the original problem into a question about sequences —exactly according to plan! Now if we answer the sequence question, then we’ve solved our original problem as well. But how many different n-bit sequences are there? For example, there are 8 different 3-bit sequences:

(0, 0 , 0) (0, 0 , 1) (0, 1 , 0) (0, 1 , 1) (1, 0 , 0) (1, 0 , 1) (1, 1 , 0) (1, 1 , 1)

Well, we can write the set of all n-bit sequences as a product of sets:

{ 0 , 1 } × { 0 , 1 } ×... × { 0 , 1 } = { 0 , 1 }n n terms

Then Product Rule gives the answer:

|{ 0 , 1 }n^ | = |{ 0 , 1 }|n = 2n

This means that the number of subsets of an n-element set X is also 2 n^. We’ll put this answer to use shortly.

16.2.6 Problems

Practice Problems

Problem 16.1. How many ways are there to select k out of n books on a shelf so that there are always at least 3 unselected books between selected books? (Assume n is large enough for this to be possible.)

Class Problems

Problem 16.2. A license plate consists of either:

  • 3 letters followed by 3 digits (standard plate)
  • 5 letters (vanity plate)

338 CHAPTER 16. COUNTING

  • 2 characters – letters or numbers (big shot plate)

Let L be the set of all possible license plates. (a) Express L in terms of

A = {A, B, C,... , Z} D = { 0 , 1 , 2 ,... , 9 }

using unions (∪) and set products (×).

(b) Compute |L|, the number of different license plates, using the sum and prod uct rules.

Problem 16.3. (a) How many of the billion numbers in the range from 1 to 109 contain the digit 1? (Hint: How many don’t?)

(b) There are 20 books arranged in a row on a shelf. Describe a bijection between ways of choosing 6 of these books so that no two adjacent books are selected and 15 -bit strings with exactly 6 ones.

Problem 16.4.

(a) Let Sn,k be the possible nonnegative integer solutions to the inequality

x 1 + x 2 + · · ·+ xk ≤ n. (16.1)

That is (^) � � Sn,k ::= (x 1 , x 2 ,... , xk) ∈ Nk^ | (16.1) is true.

Describe a bijection between Sn,k and the set of binary strings with n zeroes and k ones.

(b) Let Ln,k be the length k weakly increasing sequences of nonnegative integers ≤ n. That is

Ln,k ::= (y 1 , y 2 ,... , yk) ∈ Nk^ | y 1 ≤ y 2 ≤ · · · ≤ yk ≤ n.

Describe a bijection between Ln,k and Sn,k.

Problem 16.5. An n-vertex numbered tree is a tree whose vertex set is { 1 , 2 ,... , n} for some n > 2. We define the code of the numbered tree to be a sequence of n − 2 integers from 1 to n obtained by the following recursive process:

340 CHAPTER 16. COUNTING

Homework Problems

Problem 16.6. Answer the following questions with a number or a simple formula involving fac torials and binomial coefficients. Briefly explain your answers.

(a) How many ways are there to order the 26 letters of the alphabet so that no two of the vowels a, e, i, o, u appear consecutively and the last letter in the ordering is not a vowel?

Hint: Every vowel appears to the left of a consonant.

(b) How many ways are there to order the 26 letters of the alphabet so that there are at least two consonants immediately following each vowel?

(c) In how many different ways can 2 n students be paired up?

(d) Two n-digit sequences of digits 0,1,... ,9 are said to be of the same type if the digits of one are a permutation of the digits of the other. For n = 8, for example, the sequences 03088929 and 00238899 are the same type. How many types of n-digit integers are there?

Problem 16.7. In a standard 52-card deck, each card has one of thirteen ranks in the set, R, and one of four suits in the set, S, where

R ::= {A, 2 ,... , 10 , J, Q, K} , S ::= {♣, ♦, ♥, ♠}.

A 5-card hand is a set of five distinct cards from the deck. For each part describe a bijection between a set that can easily be counted using the Product and Sum Rules of Ch. 16.2, and the set of hands matching the specifi cation. Give bijections, not numerical answers. For instance, consider the set of 5-card hands containing all 4 suits. Each such hand must have 2 cards of one suit. We can describe a bijection between such hands and the set S × R 2 × R^3 where R 2 is the set of two-element subsets of R. Namely, an element

(s, {r 1 , r 2 } , (r 3 , r 4 , r 5 )) ∈ S × R 2 × R^3

indicates

  1. the repeated suit, s ∈ S,
  2. the set, {r 1 , r 2 } ∈ R 2 , of ranks of the cards of suit, s, and
  3. the ranks (r 3 , r 4 , r 5 ) of remaining three cards, listed in increasing suit order where ♣ � ♦ � ♥ � ♠.

16.3. THE PIGEONHOLE PRINCIPLE 341

For example,

(♣, { 10 , A} , (J, J, 2)) ←→ {A♣, 10 ♣, J♦, J♥, 2 ♠}.

(a) A single pair of the same rank (no 3-of-a-kind, 4-of-a-kind, or second pair).

(b) Three or more aces.

16.3 The Pigeonhole Principle

Here is an old puzzle:

A drawer in a dark room contains red socks, green socks, and blue socks. How many socks must you withdraw to be sure that you have a matching pair?

For example, picking out three socks is not enough; you might end up with one red, one green, and one blue. The solution relies on the Pigeonhole Principle, which is a friendly name for the contrapositive of the injective case 2 of the Mapping Rule of Lemma 4.8.2. Let’s write it down:

If |X| > |Y |, then no total function^1 f : X → Y is injective.

And now rewrite it again to eliminate the word “injective.”

Rule 3 (Pigeonhole Principle). If |X| > |Y |, then for every total function f : X → Y , there exist two different elements of X that are mapped to the same element of Y.

What this abstract mathematical statement has to do with selecting footwear under poor lighting conditions is maybe not obvious. However, let A be the set of socks you pick out, let B be the set of colors available, and let f map each sock to its color. The Pigeonhole Principle says that if |A| > |B| = 3, then at least two elements of A (that is, at least two socks) must be mapped to the same element of B (that is, the same color). For example, one possible mapping of four socks to three colors is shown below.

A f^ B 1st sock �red

2nd sock

3rd sock

green

blue

4th sock �

(^1) This Mapping Rule actually applies even if f is a total injective relation.

16.3. THE PIGEONHOLE PRINCIPLE 343

25-digit number is less than 1025. So let B be the set of integers 0 , 1 ,... , 90 · 1025 , and let f map each subset of numbers (in A) to its sum (in B). We proved that an n-element set has 2 n^ different subsets. Therefore:

|A| = 2^90 ≥ 1. 237 × 1027

On the other hand:

|B| = 90 · 1025 + 1 ≤ 0. 901 × 1027

Both quantities are enormous, but |A| is a bit greater than |B|. This means that f maps at least two elements of A to the same element of B. In other words, by the Pigeonhole Principle, two different subsets must have the same sum! Notice that this proof gives no indication which two sets of numbers have the same sum. This frustrating variety of argument is called a nonconstructive proof.

Sets with Distinct Subset Sums

How can we construct a set of n positive integers such that all its subsets have distinct sums? One way is to use powers of two:

{ 1 , 2 , 4 , 8 , 16 }

This approach is so natural that one suspects all other such sets must involve larger numbers. (For example, we could safely replace 16 by 17, but not by 15.) Remark ably, there are examples involving smaller numbers. Here is one:

{ 6 , 9 , 11 , 12 , 13 }

One of the top mathematicans of the Twentieth Century, Paul Erd˝os, conjectured in 1931 that there are no such sets involving significantly smaller numbers. More precisely, he conjectured that the largest number must be > c 2 n^ for some constant c > 0. He offered $500 to anyone who could prove or disprove his conjecture, but the problem remains unsolved.

16.3.3 Problems

Class Problems

Problem 16.8. Solve the following problems using the pigeonhole principle. For each problem,

344 CHAPTER 16. COUNTING

try to identify the pigeons, the pigeonholes, and a rule assigning each pigeon to a pigeonhole.

(a) Every MIT ID number starts with a 9 (we think). Suppose that each of the 75 students in 6.042 sums the nine digits of his or her ID number. Explain why two people must arrive at the same sum.

(b) In every set of 100 integers, there exist two whose difference is a multiple of

(c) For any five points inside a unit square (not on the boundary), there are two points at distance less than 1 /

(d) Show that if n + 1 numbers are selected from { 1 , 2 , 3 ,... , 2 n}, two must be consecutive, that is, equal to k and k + 1 for some k.

Homework Problems

Problem 16.9. Pigeon Huntin’ (a) Show that any odd integer x in the range 109 < x < 2 · 109 containing all ten digits 0 , 1 ,... , 9 must have consecutive even digits. Hint: What can you conclude about the parities of the first and last digit?

(b) Show that there are 2 vertices of equal degree in any finite undirected graph with n ≥ 2 vertices. Hint: Cases conditioned upon the existence of a degree zero vertex.

Problem 16.10. Show that for any set of 201 positive integers less than 300, there must be two whose quotient is a power of three (with no remainder).

16.4 The Generalized Product Rule

We realize everyone has been working pretty hard this term, and we’re considering awarding some prizes for truly exceptional coursework. Here are some possible categories:

Best Administrative Critique We asserted that the quiz was closed-book. On the cover page, one strong candidate for this award wrote, “There is no book.”

Awkward Question Award “Okay, the left sock, right sock, and pants are in an antichain, but how— even with assistance— could I put on all three at once?”

Best Collaboration Statement Inspired by a student who wrote “I worked alone” on Quiz 1.

346 CHAPTER 16. COUNTING

16.4.1 Defective Dollars

A dollar is defective if some digit appears more than once in the 8-digit serial num ber. If you check your wallet, you’ll be sad to discover that defective dollars are all-too-common. In fact, how common are nondefective dollars? Assuming that the digit portions of serial numbers all occur equally often, we could answer this question by computing:

of serial #’s with all digits different

fraction dollars that are nondefective = total # of serial #’s

Let’s first consider the denominator. Here there are no restrictions; there are are 10 possible first digits, 10 possible second digits, 10 third digits, and so on. Thus, the total number of 8-digit serial numbers is 108 by the Product Rule. Next, let’s turn to the numerator. Now we’re not permitted to use any digit twice. So there are still 10 possible first digits, but only 9 possible second digits, 8 possible third digits, and so forth. Thus, by the Generalized Product Rule, there are

10! 10 · 9 · 8 · 7 · 6 · 5 · 4 · 3 = 2 = 1, 814 , 400

serial numbers with all digits different. Plugging these results into the equation above, we find:

1 , 814 , 400 fraction dollars that are nondefective = 100 , 000 , 000 = 1.8144%

16.4.2 A Chess Problem

In how many different ways can we place a pawn (p), a knight (k), and a bishop (b) on a chessboard so that no two pieces share a row or a column? A valid config uration is shown below on the left, and an invalid configuration is shown on the right.

k

b

p

p

b k

valid invalid

16.5. THE DIVISION RULE 347

First, we map this problem about chess pieces to a question about sequences. There is a bijection from configurations to sequences

(rp, cp, rk, ck, rb, cb)

where rp, rk, and rb are distinct rows and cp, ck, and cb are distinct columns. In particular, rp is the pawn’s row, cp is the pawn’s column, rk is the knight’s row, etc. Now we can count the number of such sequences using the Generalized Product Rule:

  • rp is one of 8 rows
  • cp is one of 8 columns
  • rk is one of 7 rows (any one but rp)
  • ck is one of 7 columns (any one but cp)
  • rb is one of 6 rows (any one but rp or rk)
  • cb is one of 6 columns (any one but cp or ck)

Thus, the total number of configurations is (8 · 7 ·6)^2.

16.4.3 Permutations

A permutation of a set S is a sequence that contains every element of S exactly once. For example, here are all the permutations of the set {a, b, c}:

(a, b, c) (a, c, b) (b, a, c) (b, c, a) (c, a, b) (c, b, a) How many permutations of an n-element set are there? Well, there are n choices for the first element. For each of these, there are n − 1 remaining choices for the second element. For every combination of the first two elements, there are n − 2 ways to choose the third element, and so forth. Thus, there are a total of

n · (n − 1) · (n − 2) · · · 3 · 2 ·1 = n!

permutations of an n-element set. In particular, this formula says that there are 3! = 6 permuations of the 3-element set {a, b, c}, which is the number we found above. Permutations will come up again in this course approximately 1.6 bazillion times. In fact, permutations are the reason why factorial comes up so often and why we taught you Stirling’s approximation:

n! ∼

2 πn

� (^) n �n e

16.5 The Division Rule

Counting ears and dividing by two is a silly way to count the number of people in a room, but this approach is representative of a powerful counting principle. A k-to-1 function maps exactly k elements of the domain to every element of the codomain. For example, the function mapping each ear to its owner is 2-to-1:

16.5. THE DIVISION RULE 349

But now there’s a snag. Consider the sequences:

(1, 1 , 8 , 8) and (8, 8 , 1 , 1)

The first sequence maps to a configuration with a rook in the lower-left corner and a rook in the upper-right corner. The second sequence maps to a configuration with a rook in the upper-right corner and a rook in the lower-left corner. The problem is that those are two different ways of describing the same configuration! In fact, this arrangement is shown on the left side in the diagram above. More generally, the function f maps exactly two sequences to every board con figuration; that is f is a 2-to-1 function. Thus, by the quotient rule, |A| = 2 · |B|. Rearranging terms gives:

|B| =

|A

(8 · 7)^2

On the second line, we’ve computed the size of A using the General Product Rule just as in the earlier chess problem.

16.5.2 Knights of the Round Table

In how many ways can King Arthur seat n different knights at his round table? Two seatings are considered equivalent if one can be obtained from the other by rotation. For example, the following two arrangements are equivalent:

k 1 k 3

k 4 k 2 k 2 k 4

k 3 k 1

Let A be all the permutations of the knights, and let B be the set of all possible seating arrangements at the round table. We can map each permutation in set A to a circular seating arrangement in set B by seating the first knight in the permuta tion anywhere, putting the second knight to his left, the third knight to the left of the second, and so forth all the way around the table. For example:

k 2

(k 2 , k 4 , k 1 , k 3 ) −→^ k 3 k 4

k 1

350 CHAPTER 16. COUNTING

This mapping is actually an n-to-1 function from A to B, since all n cyclic shifts of the original sequence map to the same seating arrangement. In the example, n = 4 different sequences map to the same seating arrangement:

(k 2 , k 4 , k 1 , k 3 ) (^) ��^ k 2 (k 4 , k 1 , k 3 , k 2 ) (k 1 , k 3 , k 2 , k 4 )

k 3 k 4

(k 3 , k 2 , k 4 , k 1 ) (^) k 1

Therefore, by the division rule, the number of circular seating arrangements is:

|B| =

|A

n

n!

n = (n − 1)!

Note that |A| = n! since there are n! permutations of n knights.

16.5.3 Problems

Class Problems

Problem 16.11. Your 6.006 tutorial has 12 students, who are supposed to break up into 4 groups of 3 students each. Your TA has observed that the students waste too much time trying to form balanced groups, so he decided to pre-assign students to groups and email the group assignments to his students.

(a) Your TA has a list of the 12 students in front of him, so he divides the list into consecutive groups of 3. For example, if the list is ABCDEFGHIJKL, the TA would define a sequence of four groups to be ({A, B, C} , {D, E, F } , {G, H, I} , {J, K, L}). This way of forming groups defines a mapping from a list of twelve students to a sequence of four groups. This is a k-to-1 mapping for what k?

(b) A group assignment specifies which students are in the same group, but not any order in which the groups should be listed. If we map a sequence of 4 groups,

({A, B, C} , {D, E, F } , {G, H, I} , {J, K, L}),

into a group assignment

{{A, B, C} , {D, E, F } , {G, H, I} , {J, K, L}} ,

this mapping is j-to-1 for what j?