Lecture notes · Math for Computer Science · Lecture 16

Counting Rules I

MIT 6.042J Mathematics for Computer Science, lecture 16, explained in plain English

Want this lecture to stick? In LessonBound you get checked practice questions for every part, can ask about anything you don't get, and can listen with your screen off. Free, no ads.

Learn this lecture free

Watch or read the original lecture: MIT OpenCourseWare.

Part 1 · 0:00–10:00

This part introduces counting with sets, sequences, and permutations, and shows how to count the ways to arrange things in order.

Key ideas

Words to know

Set
A group of different things where the order does not matter. Repeats are not allowed.
Sequence
A list of things in a fixed order. The same thing can appear more than once.
Permutation
One way to arrange every item in a group in a line, using each item exactly once.
Factorial
Multiplying a whole number by every whole number below it, down to 1. For example, 3 factorial is 3 times 2 times 1, which is 6.

Example

Imagine three friends, Ann, Ben, and Cy, lining up for a photo. Each different line-up is one permutation, and there are six possible line-ups. You can count them by noting there are 3 choices for the first spot, 2 for the second, and 1 for the last, which gives 3 times 2 times 1.

3 checked practice questions for this part are in the app.

Part 2 · 10:00–20:00

This part explains what a function is, the three special kinds of functions (surjective, injective, and bijective), and why a permutation counts as a bijection.

Key ideas

Words to know

function
A rule that sends every item in one set to exactly one item in another set.
surjective
Every item in the target set gets hit at least once, so none are left out.
injective
Every item in the target set gets hit at most once, so no two inputs share a target.
bijective
Every item in the target set gets hit exactly once, so it is both surjective and injective.

Example

Think of guests and chairs at a dinner. If each guest sits in exactly one chair, and every chair has exactly one guest, the seating is bijective. If one guest sits in two chairs, it is not a function, because each guest must have exactly one seat.

3 checked practice questions for this part are in the app.

Part 3 · 20:00–30:00

This part explains how comparing set sizes lets you count hard things by matching them up with easier things, and shows how to count subsets with bit sequences.

Key ideas

Words to know

cardinality
The number of elements in a set. It is how big the set is.
surjective
A function where every element in the target set gets hit by at least one element from the starting set. Nothing is left out.
injective
A function where each target element is hit by at most one starting element. No two starting elements share the same result.
bijection
A pairing where every element on one side matches exactly one element on the other side, with nothing left over on either side.

Example

Think of handing out name tags to guests at a party so that each guest gets exactly one tag and each tag goes to exactly one guest. If every guest gets a tag and every tag is used, the number of guests equals the number of tags. That is the bijection idea: a perfect one-to-one matching means the two groups have the same count.

3 checked practice questions for this part are in the app.

Part 4 · 30:00–40:00

This part shows how to count hard things by matching them to easier things, and how the pigeonhole principle proves that some items must share a property even when you cannot find them.

Key ideas

Words to know

bijection
A perfect matching where every item in one group pairs with exactly one item in the other group, and no item is left out or used twice.
cardinality
The size of a set, meaning how many items it has.
pigeonhole principle
If you put more items into boxes than there are boxes, at least one box must hold two or more items.
non-constructive proof
A proof that shows something must be true without finding or showing the specific example.

Example

Imagine 5 pigeons flying into 4 holes. The pigeons cannot all have their own hole, so at least two must share one. You do not need to see which pigeons they are to know this must happen.

3 checked practice questions for this part are in the app.

Part 5 · 40:00–50:00

This part shows how counting can prove that two groups of numbers must match in some way, even when you never find the matching pair.

Key ideas

Words to know

non-constructive proof
A way of showing that something is true without giving a specific example of it. The proof uses reasoning, such as counting, instead.
pigeonhole principle
If you have more items than containers, at least one container must hold two or more items. Here, more subsets than possible sums means two subsets share a sum.
cardinality
The size of a set, or how many elements it has.
bijection
A matching between two sets where every element of one set pairs with exactly one element of the other, with nothing left over on either side.

Example

Imagine you have 1,024 letters and only 991 mailboxes. You cannot put each letter in its own box, so at least one box must get two letters. You know a box has two letters without ever opening the boxes, which is the same kind of reasoning the lecturer used with the subsets.

3 checked practice questions for this part are in the app.

Part 6 · 50:00–1:00:00

This part shows how to count the ways to place 2 identical rooks on a chessboard so that no two share a row or column, by counting sequences and then correcting for double counting.

Key ideas

Words to know

sequence
a list of items in a fixed order, like r1, c1, r2, c2, where the order matters.
cardinality
the number of items in a set, or how many things there are to count.
bijective
a matching where every item on one side is paired with exactly one item on the other side. The lesson checks this by asking whether each valid configuration is hit exactly once.
division rule
a counting shortcut: if every outcome is produced by the same number of sequences, count the sequences and divide by that number.

Example

Imagine you have two identical red cups and you want to count the ways to put them on two different shelves. If you list the choices as (shelf for cup 1, shelf for cup 2), then picking shelf A then shelf B and picking shelf B then shelf A describe the same setup, because the cups look the same. Each real arrangement is counted twice, so you divide your total list by 2.

3 checked practice questions for this part are in the app.

Part 7 · 1:00:00–1:10:00

This part shows how to count the number of possible outcomes by multiplying the choices at each step, and it uses that idea to show that a strange-looking property is actually common.

Key ideas

Words to know

permutation
an ordered arrangement of items, where the order matters and no item is used twice.
factorial
a number written with an exclamation mark, such as n!, equal to n times each smaller whole number down to 1.
fraction
a part of a whole, shown as one number divided by another, such as the share of bills that are non-defective.
counterintuitive
surprising, because it goes against what your first guess would be.

Example

Imagine a club of 10 people choosing a leader, then a secretary, then a consultant, with no one holding two jobs. The leader has 10 choices, the secretary has 9, and the consultant has 8, so there are 10 times 9 times 8 ways to fill the roles. Multiplying the choices at each step gives the total.

3 checked practice questions for this part are in the app.

Part 8 · 1:10:00–1:19:56

This part teaches two basic counting rules, the product rule and the sum rule, and shows how to use them together to count passwords.

Key ideas

Words to know

cardinality
The number of items in a set. If a set has 52 items, its cardinality is 52.
disjoint
Two or more sets that share no items at all. Their overlap is empty.
union
All the items you get when you put several sets together into one combined set.
sequence
An ordered list of items, where the order matters. For example, 0 then 1 is different from 1 then 0.

Example

Suppose you pick an outfit with one shirt from 3 choices and one pair of pants from 2 choices. Each shirt can go with each pair of pants, so you multiply 3 by 2 to get 6 outfits, which is the product rule. If you then choose between two separate lists of shoes that share no pairs, you add the two counts together, which is the sum rule.

3 checked practice questions for this part are in the app.

← Lecture 13: Sums and Asymptotics · Lecture 18: Probability Introduction →

Notes written by AI (Claude) from the lecture's official transcript, so check anything important against the lecture. MIT OpenCourseWare · CC BY-NC-SA 4.0 · not affiliated with or endorsed by MIT. These notes are shared under the same license.

LessonBound · Free lecture notes · Privacy · Terms · New York