Skip to content

The Basics of Counting

Counting problems arise when we want to know how many ways something can be done, without listing every possibility. They are built on a few simple counting principles.

The Product Rule

Def

Suppose that a procedure can be broken down into a sequence of two tasks. If there are n1 ways to do the first task and, for each of these, n2 ways to do the second task, then there are

n1n2

ways to do the procedure.

The product rule applies when a task is made of successive steps, and the choices for each step do not depend on which choices were made before (only the count matters).

Extended to a sequence of tasks T1,T2,,Tm with n1,n2,,nm ways respectively, the number of ways to do the procedure is:

n1n2nm
  • Example:
    • A license plate has 2 letters followed by 3 digits.
    • Letters: 26 choices each, digits: 10 choices each.
    • Total =2626101010=676,000.

Set form

If A1,A2,,Am are finite sets, the number of elements in their Cartesian product is the product of their sizes:

|A1×A2××Am|=|A1||A2||Am|

The Sum Rule

Def

If a task can be done either in one of n1 ways or in one of n2 ways, where none of the set of n1 ways is the same as any of the set of n2 ways, then there are

n1+n2

ways to do the task.

The sum rule applies when we choose from disjoint alternatives — exactly one of the groups is used, and the groups share no options.

Extended to tasks T1,T2,,Tm that can be done in n1,n2,,nm ways, where no two tasks can be done at the same time, the number of ways to do one of the tasks is:

n1+n2++nm
  • Example:
    • A student picks one project from 3 math topics or 4 CS topics.
    • The two lists have no topic in common.
    • Total =3+4=7 choices.

Set form

If A1,A2,,Am are pairwise disjoint finite sets, then:

|A1A2Am|=|A1|+|A2|++|Am|

WARNING

The sum rule requires the alternatives to be disjoint. If the groups overlap, simply adding their sizes double counts the shared options — use the subtraction rule instead.

The Subtraction Rule

Also known as the Inclusion–Exclusion principle for two sets.

Def

If a task can be done in either n1 ways or n2 ways, then the number of ways to do the task is

n1+n2n12

where n12 is the number of ways to do the task that are common to the two different ways.

We add the sizes of the two groups, then subtract the overlap once, because elements in both groups were counted twice.

Set form

For any two finite sets A and B:

|AB|=|A|+|B||AB|
  • Example:
    • How many bit strings of length 8 either start with a 1 or end with 00?
    • Start with 1: 27=128.
    • End with 00: 26=64.
    • Both (start with 1 and end with 00): 25=32.
    • Total =128+6432=160.

The Division Rule

Def

There are n/d ways to do a task if it can be done using a procedure that can be carried out in n ways, and for every way w, exactly d of the n ways correspond to way w.

The division rule applies when a straightforward count produces each outcome d times. Dividing by d removes the over-counting.

Set form

If a finite set A is the union of n pairwise disjoint subsets each with d elements, then the number of subsets is:

n=|A|d
  • Example:
    • How many different ways can 4 people be seated around a circular table, where two seatings are the same when each person has the same left and right neighbor?
    • In a row there are 4!=24 orderings.
    • Each circular arrangement corresponds to d=4 rotations of the same seating.
    • Total =4!4=244=6.

Intuition

RuleWhen to useCombine by
ProductA sequence of independent steps (do this and then this)×
SumDisjoint alternatives (do this or this)+
SubtractionAlternatives that overlap+ then overlap
DivisionA count where each outcome appears d times÷d

Built with ❤️ and curiosity