The Basics of Counting

Textbook
Rosen 8e, Section 6.1
Study day
Saturday, Nov 7
Homework
Written HW 7: 1–17 odd, 21–37 odd, 41, 45–59 odd, 63–73 odd
Progress
Notes not read 0 / 35 problems graded

Every counting problem comes down to one question: am I doing things in a sequence of steps (multiply), or choosing one of several separate cases (add)?

The product rule

Product rule

If a procedure is a sequence of tasks and task can be done in ways (no matter how the earlier tasks were done), then the procedure can be done in

Quick product-rule examples from class
  • Assign 3 employees to 10 different offices: .
  • Chair labels "letter + integer 1–99": .
  • Bit strings of length 6: .
  • Plates with 4 letters then 5 digits: .
Counting functions, subsets, and products

Let and .

  • All functions : each of the inputs picks one of outputs, so .
  • One-to-one functions: if , and if .
  • Subsets of an -set: . Each element is in or out, like a bit string.
  • Cartesian product: .
  • Relations from to (subsets of ): .

The sum rule

Sum rule

If a task can be done in one of ways or one of ways, and none of the ways is the same as any of the ways, then there are ways.

Use it to split into cases (by length, by first letter, …), count each case, then add.

Variable names (class Problem 11)

A name is 1 or 2 alphanumeric characters (case-insensitive), starting with a letter, and 10 two-character names are reserved.

Length 1: . Length 2: . Total: .

Passwords (class Problem 12)

6 to 9 characters, each an uppercase letter or digit, with at least one digit.

For length : all strings minus strings with no digits, . Total: .

"At least one" means count the complement


Counting "at least one" directly usually double counts. The complement is almost always easier.

The subtraction rule (inclusion–exclusion)

Subtraction rule

If a task can be done in ways or ways, and some ways are shared, subtract the overlap:

Use it whenever a problem says "or"

"Start with 0 or end with 11": count each, then subtract the strings that do both.

Length-8 bit strings that start with 0 or end with 11:

Majors (class Problem 14)

350 applicants: 210 CS, 150 sociology, 50 both. Neither?
, so neither .

Counting multiples
  • Multiples of in : .
  • Multiples of in : .
  • "Divisible by both and " means divisible by . For 4 and 6 that is 12, not 24.

The division rule

Division rule

If every outcome you want is counted exactly times in your count, divide by : there are ways.

Circular seating

people around a round table, rotations considered the same: .
If reflections also count as the same ("same two neighbors, ignoring left/right"): .

Class Problem 16: 5 people, same right and left neighbor means same seating, so .

Goat legs (class Problem 15)

400 legs counted, each goat counted 4 times, so goats. That's the division rule.

Tree diagrams

When the choices at each step depend on earlier choices, draw a tree and count the leaves.

Length-4 bit strings with no two consecutive 0s (class Problem 18)
Solution

Branch on each bit, pruning any branch that would create "00":

  • Start 1: 1010, 1011, 1101, 1110, 1111 (5 strings)
  • Start 0 (next must be 1): 0101, 0110, 0111 (3 strings)

Total: 8. (These counts are Fibonacci numbers: the answer for length is .)

T-shirts (class Problem 17)

5 sizes; four sizes come in 4 colors, L in 3, XL in 2: . A tree, or the sum rule over sizes.

Strategy

How to attack any counting problem
  1. Decide what one outcome looks like (a string? a set? an arrangement?).
  2. Sequence of choices? Multiply (product rule). Make sure each step's count doesn't depend on which earlier choice was made.
  3. Separate cases? Add (sum rule). Make sure cases don't overlap.
  4. "At least one"? Total minus none.
  5. "Or" with overlap? Inclusion–exclusion.
  6. Each outcome counted times? Divide.
  7. Sanity check with a tiny case you can list by hand.
Common mistakes
  • Leading zeros: "positive integers between 100 and 999" have a first digit of 1–9.
  • "Between 50 and 100": check whether the endpoints matter.
  • Counting -digit numbers with distinct digits: , not (first digit nonzero, second can be 0).
  • Adding overlapping cases without subtracting the overlap.
Fixes to your class notes
  • Problem 7 (): the bit should be if , the subset, not .
  • Problem 13: . Your notes wrote "" at the end.
  • Problem 14: the line "" should read ; the final answer 40 is right.
  • Sum rule note: if are disjoint then , so .

Exam checklist

  • Product rule with restrictions (no repeats, first digit nonzero, fixed positions).
  • Count functions, one-to-one functions, subsets, relations.
  • Split into cases and add; use the complement for "at least one."
  • Inclusion–exclusion for "or," including divisibility counts with floors.
  • Circular arrangements (division rule).
  • Small tree-diagram counts.
Go to problems