0% found this document useful (0 votes)
16 views

Full(0)

The document outlines the LibreTexts project, which provides free educational resources and allows instructors to customize materials for their courses. It includes a detailed table of contents for a text on discrete mathematics, covering topics such as groups, counting principles, and permutations. The text emphasizes the importance of open-access resources in reducing textbook costs and improving higher education accessibility.

Uploaded by

danicajavier0314
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Full(0)

The document outlines the LibreTexts project, which provides free educational resources and allows instructors to customize materials for their courses. It includes a detailed table of contents for a text on discrete mathematics, covering topics such as groups, counting principles, and permutations. The text emphasizes the importance of open-access resources in reducing textbook costs and improving higher education accessibility.

Uploaded by

danicajavier0314
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

SUPPLEMENTS FOR

DISCRETE JUDY DEAN


Supplements for Discrete Judy Dean
This text is disseminated via the Open Education Resource (OER) LibreTexts Project (https://LibreTexts.org) and like the hundreds
of other texts available within this powerful platform, it is freely available for reading, printing and "consuming." Most, but not all,
pages in the library have licenses that may allow individuals to make changes, save, and print this book. Carefully
consult the applicable license(s) before pursuing such effects.
Instructors can adopt existing LibreTexts texts or Remix them to quickly build course-specific resources to meet the needs of their
students. Unlike traditional textbooks, LibreTexts’ web based origins allow powerful integration of advanced features and new
technologies to support learning.

The LibreTexts mission is to unite students, faculty and scholars in a cooperative effort to develop an easy-to-use online platform
for the construction, customization, and dissemination of OER content to reduce the burdens of unreasonable textbook costs to our
students and society. The LibreTexts project is a multi-institutional collaborative venture to develop the next generation of open-
access texts to improve postsecondary education at all levels of higher learning by developing an Open Access Resource
environment. The project currently consists of 14 independently operating and interconnected libraries that are constantly being
optimized by students, faculty, and outside experts to supplant conventional paper-based books. These free textbook alternatives are
organized within a central environment that is both vertically (from advance to basic level) and horizontally (across different fields)
integrated.
The LibreTexts libraries are Powered by NICE CXOne and are supported by the Department of Education Open Textbook Pilot
Project, the UC Davis Office of the Provost, the UC Davis Library, the California State University Affordable Learning Solutions
Program, and Merlot. This material is based upon work supported by the National Science Foundation under Grant No. 1246120,
1525057, and 1413739.
Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not
necessarily reflect the views of the National Science Foundation nor the US Department of Education.
Have questions or comments? For information about adoptions or adaptions contact [email protected]. More information on our
activities can be found via Facebook (https://facebook.com/Libretexts), Twitter (https://twitter.com/libretexts), or our blog
(http://Blog.Libretexts.org).
This text was compiled on 02/04/2024
TABLE OF CONTENTS
Licensing

1: Groups I
1.1: Definition of a Group
1.3: Integers Modulo n
1.4: Permutations

2: Counting
2.1: Additive and Multiplicative Principles
2.2: Binomial Coefficients
2.3: Combinations and Permutations
2.4: Combinatorial Proofs
2.5: Stars and Bars
2.6: Advanced Counting Using PIE
2.E: Counting (Exercises)
2.S: Counting (Summary)

Index
Glossary
Detailed Licensing

1 https://math.libretexts.org/@go/page/34370
Licensing
A detailed breakdown of this resource's licensing can be found in Back Matter/Detailed Licensing.

1 https://math.libretexts.org/@go/page/115737
CHAPTER OVERVIEW

1: Groups I
We give a precise definition of a group and explore some different groups in the context of this definition.
1.1: Definition of a Group
1.3: Integers Modulo n
1.4: Permutations

Contributors
Tom Denton (Fields Institute/York University in Toronto)

1: Groups I is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

1
1.1: Definition of a Group

Algebraic Structures 2.1 - Group De niti…


niti…

Consider an object X with some symmetries S . We've seen that we can compose any of the symmetries in S and obtain another
symmetry of X. We've also seen that these symmetries obey certain rules. We can now, at last, define a group.

 Definition 2.1.0: Group


A group is a set S with an operation ∘ : S × S → S satisfying the following properties:
1. Identity: There exists an element e ∈ S such that for any f ∈ S we have e ∘ f =f ∘e =f .
2. Inverses: For any element f ∈ S there exists g ∈ S such that f ∘ = e .
3. Associativity: For any f , g, h ∈ S , we have (f ∘ g) ∘ h = f ∘ (g ∘ h) .

An essential notion in mathematics is abstraction. Note that our definition certainly applies to any collection S of symmetries of an
object, but in fact there are other contexts where the definitions apply as well! The operation can be any way of combining two
things in S and getting another back; S doesn't need to be a collection of functions, and the operation doesn't need to be
composition. A group is defined purely by the rules that it follows! This is our first example of an algebraic structure; all the others
that we meet will follow a similar template: A set with some operation(s) that follow some particular rules.
For example, consider the integers Z with the operation of addition. To check that the integers form a group, we need to check four
things:
1. Addition takes two integers and gives another integer back. (Here we're checking the requirement that the operation is one from
S × S → S . Notice that the the output of the operation is always in S ! This is called closure of the operation.)

2. There's an identity element, 0, where for any integer n , we have n + 0 = 0 + n = n .


3. Every integer n has an inverse, −n, with n + (−n) = (−n) + n = 0 .
4. Addition of integers is associative.
Thus, the integers - with the operation of addition - form a group.
On the other hand, the set of integers with the operation of multiplication do not form a group. Multiplication does indeed take two
integers and return another integer, and there is an identity 1, and multiplication is associative. But not every element has an
inverse that is also an integer. For example, the multiplicative inverse of 2 is , but this isn't an integer! Thus, integers with
1

multiplication do not form a group.

 An important note about inverses: An inverse means, roughly, that we can go back to where we started after
applying an operation. Algebraically, this means we can cancel elements. When we have something like
gh = gk , we can multiply both sides on the left by g to get h = k . We have to be careful to multiply on the
−1

same side on both sides, since groups aren't always commutative! If gh = kg , it doesn't necessarily tell us that
h = k!

1.1.1 https://math.libretexts.org/@go/page/32557
 of X .)

 Show that the symmetries of an equilateral triangle are not commutative. In other words, find two symmetries
f , g of the equilateral triangle such that f g ≠ gf .

Contributors and Attributions


Tom Denton (Fields Institute/York University in Toronto)

1.1: Definition of a Group is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

1.1.2 https://math.libretexts.org/@go/page/32557
1.3: Integers Modulo n

Algebraic Structures 2.2 - Integers Mod n

Recall the 'bumpy' hexagon, which had rotational symmetry but no reflection symmetry. The group of symmetries of the bumpy
hexagon is called Z . In this section, we'll consider the general case, Z , which we can initially think of as the group of symmetries
6 n

of a 'bumpy' n -sided polygon.


There are many different ways in which Zn appears in mathematics; it's a very important group! We now describe a number of
different ways in which it arises.
1. Well, first we have the group of symmetries of the 'bumpy' n -sided polygon. By the exercise at the end of the last section, we
know this is a group.
2. For our second definition, we'll define the 'remainder by n ' operation: for any integer a , define a%n to be the remainder of a
when divided by n . For example, 5%3 = 2 , because the remainder of 5 when divided by 3 is 2. (You should check that for any
integer k , (kn)%n = 0 .) This operation is usually called 'modulus' or 'mod.' So 12%5 is read 'twelve modulo 5' or 'twelve mod
5.' (And is equal, of course, to two!)
Usually, we don't write + for the addition. From now on, whenever you see an expression like 4 + 3 , you will have to be
n

mindful of the context! If we consider 4 and 3 as plain old integers, the answer is 7. If they are integers mod 5, then the answer
is 2!
3. The next definition is really just an easy way to think of the second definition. Imagine a distant planet where the clock has n
hours on it instead of 12 (or 24). Then, just as our hours 'wrap around' the circle beyond 12 o'clock, the hours wrap around at n .
Now if we imagine the clock is numbered 0 through n − 1 instead of 1 to n , we have exactly the situation of Z . n

4. Our last definition will identify Z with the n -th roots of unity, which are complex numbers. Recall that any complex number
n

may be written as re , where r is a positive real number and θ is any angle. Now let n and k be some positive integers, and

k k

consider the complex number x = e


k
n . Then we can see that x = (e
2iπ n
k
n
2iπ
) =e
n
= 1 . Then we call x an n th root of
k2iπ
k

unity, because raising it to the n th power gives us 1 (aka, unity).


All of these are somehow the same; but there's a question of how to formally show that two groups are the same. What do we mean
by the same? This is an important question to consider, which we will come back to later. For now, an exercise.

 Write out tables for n = 5 and n = 6 for:


1. composition of the rotations of the 'bumpy' n -gon,
2. addition in Z ,
n

3. addition of hours on an extraterrestrial clock with n hours,


4. and for multiplication of the n -th roots of unity.
In what ways are all of these groups the same? In what ways are they different?

1.3.1 https://math.libretexts.org/@go/page/32558
Contributors and Attributions
Tom Denton (Fields Institute/York University in Toronto)

1.3: Integers Modulo n is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

1.3.2 https://math.libretexts.org/@go/page/32558
1.4: Permutations
A permutation of n distinct objects is just a listing of the objects in some order. For example, [c, b, a] is a permutation of the set
{a, b, c} of three objects. Likewise, [triangle, melon, airplane] is a permutation of three objects as well. From our mathematical

point of view, the objects we use don't actually matter; all we care about is the order they are arranged in. So usually we'll just talk
about permutations of the numbers 1 through n . You can think of each number as just counting the objects involved: first object,
second object, n th object.
Permutations arise in the world in a many, many ways. For example, suppose you are asked to list your preferences amongst a
bunch of presidential candidates. The list you make up, from favorite to least favorite, is a permutation of the candidates. In fact,
you can use the mathematics of permutations to learn interesting things about different kinds of voting systems.

Figure 2.3: Instant run-off voting uses a full permutation of the candidates to find a winner. (Source)
Another example is a deck of playing cards. In a standard deck, each card appears exactly once. When you shuffle the deck, you are
just creating a random permutation of the cards. One can use mathematics related to permutations to answer interesting questions
about cards. Like: 'How many times do I need to shuffle the deck before it is truly randomized?' The answer, by the way, seems to
be 7 for a standard riffle shuffle. But proving that is well beyond the scope of these notes!
Because permutations are so common, problems involving permutations tend to be very applicable! For example, suppose you have
two hundred students in a class and they all hand in an exam. The stack of exams they give you is a permutation of the students;
most likely, the list of student scores you keep is alphabetical. This suggests a problem: What is the fastest way to sort the exams?
(In fact, sorting is a fundamental problem in computer science.)
How many permutations are there of a set of n objects? Suppose we try to build a permutation by successively choosing objects.
Then there are n choices for the first object, n − 1 choices for the second, and so on, until there is only one choice for the last
object. Then to get the total number of possible permutations, we multiply these numbers together, and get n(n − 1)(n − 2) ⋯ 1 .
This number, if you haven't seen it before, is called n -factorial, written n!.

 Write out all of the permutations of the set {1, 2, 3, 4}. How many are there in all? Find a sensible way to
organize your list!

Suppose we have some initial ordering of our objects. The letters {a, b, c}, for example, can be organized alphabetically. Then
every permutation we can think of as a mixing-up of this initial order. In this sense, the permutation is a special kind of function
from the set of objects back to itself. (By special, I mean it's a bijection, which is to say a one-to-one and onto function.) (TODO:
Wikipedia link) A permutation of these objects is then the list [σ(a), σ(b), σ(c)]; this list is called the one-line notation for σ.
These permutations-as-functions can be composed: if you think of two permutations σ and τ as different ways to mix up the set,
you can mix them up according to σ and then according to τ . Then the composition is specified by the list
[τ (σ(a)), τ (σ(b)), τ (σ(c))].

1.4.1 https://math.libretexts.org/@go/page/32559
For example, if σ = [2, 3, 1, 4] and τ = [3, 4, 1, 2], then τ ∘ σ = [4, 3, 1, 2]. (In particular, σ(1) = 2 , and τ (2) = 4 , so the first
entry of τ ∘ σ is 4. The other three entries are computed similarly.) On the other hand, σ ∘ τ = [3, 1, 4, 2]. This is different from
τ ∘ σ ! So we see that the group of permutations has elements where f ∘ g ≠ g ∘ f ; we say that S is non-commutative. (But
n

remember that nothing in our group definition says that a group needs to be commutative, so this is ok.)
A very nice way to keep track of this mixing-up is the braid notation for a permutation. This simply writes the list of objects in two
lines, and draws a line connecting an object on the top to the object it is sent to under the permutation.
Braid diagrams for some permutations. At this point, we can ask whether the permutations with the composition operation are in
fact a group. In fact, they are! Let's check. Let σ, τ be permutations of the set X = {1, 2, 3, … , n} Then we can specify σ by the
list [σ(1), σ(2), … , σ(n)].
Composition of two permutations is again a permutation. Since each permutation contains every element of X exactly once, the
composition τ ∘ σ must also contain each element of X exactly once. Identity: The permutation [1, 2, … , n] acts as the identity.
Inverses: Roughly speaking, if you can mix things up, you can just as easily sort them back out. The 'sorting permutation' of σ is
exactly σ . Associativity: Suppose we compose three permutations, σ, τ , and ρ. Int he braid notation, this just means placing the
−1

three braids on top of each other top-to-bottom, and then 'forgetting' the two sets of intermediate dots. (TODO: a picture!)
Associativity is tantamount to forgetting the two sets of dots in two different orders; the resulting picture is the same either way, so
composition of permutations is associative!

 Carefully work through the above and check for yourself that permutations satisfy the definition of a group.
For example, where it is stated that the identity permutation has one-line notation [1, 2, … , n] , you should check
that this is actually the identity. Likewise, how can you explicitly compute the inverse of a permutation explicitly?

Contributors and Attributions


Tom Denton (Fields Institute/York University in Toronto)

1.4: Permutations is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

1.4.2 https://math.libretexts.org/@go/page/32559
CHAPTER OVERVIEW

2: Counting
One of the first things you learn in mathematics is how to count. Now we want to count large collections of things quickly and
precisely. For example:
In a group of 10 people, if everyone shakes hands with everyone else exactly once, how many handshakes took place?
How many ways can you distribute 1010 girl scout cookies to 77 boy scouts?
How many anagrams are there of “anagram”?
Before tackling questions like these, let's look at the basics of counting.
2.1: Additive and Multiplicative Principles
2.2: Binomial Coefficients
2.3: Combinations and Permutations
2.4: Combinatorial Proofs
2.5: Stars and Bars
2.6: Advanced Counting Using PIE
2.E: Counting (Exercises)
2.S: Counting (Summary)

This page titled 2: Counting is shared under a CC BY-SA license and was authored, remixed, and/or curated by Oscar Levin.

1
2.1: Additive and Multiplicative Principles
Investigate!
1. A restaurant offers 8 appetizers and 14 entrées. How many choices do you have if:
a. you will eat one dish, either an appetizer or an entrée?
b. you are extra hungry and want to eat both an appetizer and an entrée?
2. Think about the methods you used to solve question 1. Write down the rules for these methods.
3. Do your rules work? A standard deck of playing cards has 26 red cards and 12 face cards.
a. How many ways can you select a card which is either red or a face card?
b. How many ways can you select a card which is both red and a face card?
c. How many ways can you select two cards so that the first one is red and the second one is a face card?

Consider this rather simple counting problem: at Red Dogs and Donuts, there are 14 varieties of donuts, and 16 types of hot dogs.
If you want either a donut or a dog, how many options do you have? This isn't too hard, just add 14 and 16. Will that always work?
What is important here?

Additive Principle
The additive principle states that if event A can occur in m ways, and event B can occur in n disjoint ways, then the event “A
or B ” can occur in m + n ways.

It is important that the events be disjoint: i.e., that there is no way for A and B to both happen at the same time. For example, a
standard deck of 52 cards contains 26 red cards and 12 face cards. However, the number of ways to select a card which is either red
or a face card is not 26 + 12 = 38. This is because there are 6 cards which are both red and face cards.

Example 2.1.1

How many two letter “words” start with either A or B? (A word is just a string of letters; it doesn't have to be English, or even
pronounceable.)

Solution
First, how many two letter words start with A? We just need to select the second letter, which can be accomplished in 26
ways. So there are 26 words starting with A. There are also 26 words that start with B. To select a word which starts with
either A or B, we can pick the word from the first 26 or the second 26, for a total of 52 words.

The additive principle also works with more than two events. Say, in addition to your 14 choices for donuts and 16 for dogs, you
would also consider eating one of 15 waffles? How many choices do you have now? You would have 14 + 16 + 15 = 45 options.

Example 2.1.2

How many two letter words start with one of the 5 vowels?

Solution
There are 26 two letter words starting with A, another 26 starting with E, and so on. We will have 5 groups of 26. So we
add 26 to itself 5 times. Of course it would be easier to just multiply 5 ⋅ 26. We are really using the additive principle again,
just using multiplication as a shortcut.

Example 2.1.3

Suppose you are going for some fro-yo. You can pick one of 6 yogurt choices, and one of 4 toppings. How many choices do
you have?

Solution

2.1.1 https://math.libretexts.org/@go/page/32561
Break your choices up into disjoint events: A are the choices with the first topping, B the choices featuring the second
topping, and so on. There are four events; each can occur in 6 ways (one for each yogurt flavor). The events are disjoint, so
the total number of choices is 6 + 6 + 6 + 6 = 24.

Note that in both of the previous examples, when using the additive principle on a bunch of events all the same size, it is quicker to
multiply. This really is the same, and not just because 6 + 6 + 6 + 6 = 4 ⋅ 6. We can first select the topping in 4 ways (that is, we
first select which of the disjoint events we will take). For each of those first 4 choices, we now have 6 choices of yogurt. We have:

Multiplicative Principle

The multiplicative principle states that if event A can occur in m ways, and each possibility for A allows for exactly n ways
for event B, then the event “A and B ” can occur in m ⋅ n ways.

The multiplicative principle generalizes to more than two events as well.

Example 2.1.4

How many license plates can you make out of three letters followed by three numerical digits?

Solution
Here we have six events: the first letter, the second letter, the third letter, the first digit, the second digit, and the third digit.
The first three events can each happen in 26 ways; the last three can each happen in 10 ways. So the total number of license
plates will be 26 ⋅ 26 ⋅ 26 ⋅ 10 ⋅ 10 ⋅ 10, using the multiplicative principle.
Does this make sense? Think about how we would pick a license plate. How many choices we would have? First, we need
to pick the first letter. There are 26 choices. Now for each of those, there are 26 choices for the second letter: 26 second
letters with first letter A, 26 second letters with first letter B, and so on. We add 26 to itself 26 times. Or quicker: there are
26 ⋅ 26 choices for the first two letters.

Now for each choice of the first two letters, we have 26 choices for the third letter. That is, 26 third letters for the first two
letters AA, 26 choices for the third letter after starting AB, and so on. There are 26 ⋅ 26 of these 26 third letter choices, for a
total of (26 ⋅ 26) ⋅ 26 choices for the first three letters. And for each of these 26 ⋅ 26 ⋅ 26 choices of letters, we have a bunch
of choices for the remaining digits.
In fact, there are going to be exactly 1000 choices for the numbers. We can see this because there are 1000 three-digit
numbers (000 through 999). This is 10 choices for the first digit, 10 for the second, and 10 for the third. The multiplicative
principle says we multiply: 10 ⋅ 10 ⋅ 10 = 1000.
All together, there were 26 choices for the three letters, and
3 3
10 choices for the numbers, so we have a total of 26
3 3
⋅ 10

choices of license plates.

Careful: “and” doesn't mean “times.” For example, how many playing cards are both red and a face card? Not 26 ⋅ 12. The answer
is 6, and we needed to know something about cards to answer that question.
Another caution: how many ways can you select two cards, so that the first one is a red card and the second one is a face card? This
looks more like the multiplicative principle (you are counting two separate events) but the answer is not 26 ⋅ 12 here either. The
problem is that while there are 26 ways for the first card to be selected, it is not the case that for each of those there are 12 ways to
select the second card. If the first card was both red and a face card, then there would be only 11 choices for the second card. 1 To
solve this problem, you could break it into two cases. First, count how many ways there are to select the two cards when the first
card is a red non-face card. Second, count how many ways when the first card is a red face card. Doing so makes the events in each
separate case independent, so the multiplicative principle can be applied.

Counting functions
How many functions f : {1, 2, 3, 4, 5} → {a, b, c, d} are there?

Solution

2.1.2 https://math.libretexts.org/@go/page/32561
Remember that a function sends each element of the domain to exactly one element of the codomain. To determine a
function, we just need to specify the image of each element in the domain. Where can we send 1? There are 4 choices.
Where can we send 2? Again, 4 choices. What we have here is 5 “events” (picking the image of an element in the domain)
each of which can happen in 4 ways (the choices for that image). Thus there are 4 ⋅ 4 ⋅ 4 ⋅ 4 ⋅ 4 = 4 functions.
5

This is more than just an example of how we can use the multiplicative principle in a particular counting question. What we
have here is a general interpretation of certain applications of the multiplicative principle using rigorously defined
mathematical objects: functions. Whenever we have a counting question that asks for the the number of outcomes of a
repeated event, we can interpret that as asking for the number of functions from {1, 2, … , n} (where n is the number of
times the event is repeated) to {1, 2, … , k}(where k is the number of ways that event can occur).

Counting With Sets


Do you believe the additive and multiplicative principles? How would you convince someone they are correct? This is surprisingly
difficult. They seem so simple, so obvious. But why do they work?
To make things clearer, and more mathematically rigorous, we will use sets. Do not skip this section! It might seem like we are just
trying to give a proof of these principles, but we are doing a lot more. If we understand the additive and multiplicative principles
rigorously, we will be better at applying them, and knowing when and when not to apply them at all.
We will look at the additive and multiplicative principles in a slightly different way. Instead of thinking about event A and event B,
we want to think of a set A and a set B. The sets will contain all the different ways the event can happen. (It will be helpful to be
able to switch back and forth between these two models when checking that we have counted correctly.) Here's what we mean:

Example 2.1.6

Suppose you own 9 shirts and 5 pairs of pants.


1. How many outfits can you make?
2. If today is half-naked-day, and you will wear only a shirt or only a pair of pants, how many choices do you have?

Answer
By now you should agree that the answer to the first question is 9 ⋅ 5 = 45 and the answer to the second question is
9 + 5 = 14. These are the multiplicative and additive principles. There are two events: picking a shirt and picking a pair of

pants. The first event can happen in 9 ways and the second event can happen in 5 ways. To get both a shirt and a pair of
pants, you multiply. To get just one article of clothing, you add.
Now look at this using sets. There are two sets, call them S and P . The set S contains all 9 shirts so |S| = 9 while
|P | = 5, since there are 5 elements in the set P (namely your 5 pairs of pants). What are we asking in terms of these sets?

Well in question 2, we really want |S ∪ P |, the number of elements in the union of shirts and pants. This is just |S| + |P |
(since there is no overlap; |S ∩ P | = 0 ). Question 1 is slightly more complicated. Your first guess might be to find |S ∩ P |,
but this is not right (there is nothing in the intersection). We are not asking for how many clothing items are both a shirt and
a pair of pants. Instead, we want one of each. We could think of this as asking how many pairs (x, y) there are, where x is
a shirt and y is a pair of pants. As we will soon verify, this number is |S| ⋅ |P |.

From this example we can see right away how to rephrase our additive principle in terms of sets:

Additive Principle (with sets)


Given two sets A and B, if A ∩ B = ∅ (that is, if there is no element in common to both A and B ), then

|A ∪ B| = |A| + |B| .

This hardly needs a proof. To find A ∪ B, you take everything in A and throw in everything in B. Since there is no element in both
sets already, you will have |A| things and add |B| new things to it. This is what adding does! Of course, we can easily extend this
to any number of disjoint sets.

2.1.3 https://math.libretexts.org/@go/page/32561
From the example above, we see that in order to investigate the multiplicative principle carefully, we need to consider ordered
pairs. We should define this carefully:

Cartesian Product

Given sets A and B, we can form the set A × B = {(x, y) : x ∈ A ∧ y ∈ B} to be the set of all ordered pairs (x, y) where x
is an element of A and y is an element of B. We call A × B the Cartesian product of A and B.

Example 2.1.7

Let A = {1, 2} and B = {3, 4, 5}. Find A × B.

Answer
We want to find ordered pairs (a, b) where a can be either 1 or 2 and b can be either 3, 4, or 5. A×B is the set of all of
these pairs:

A × B = {(1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5)}

The question is, what is |A × B| ? To figure this out, write out A × B. Let A = {a , a , a , … , a } 1 and
2 3 m

B = { b , b , b , … , b } (so |A| = m and |B| = n ). The set A × B contains all pairs with the first half of the pair being some
1 2 3 n

a ∈ A and the second being one of the b ∈ B. In other words:


i j

A × B = { (a1 , b1 ), (a1 , b2 ), (a1 , b3 ), … (a1 , bn ),

(a2 , b1 ), (a2 , b2 ), (a2 , b3 ), … , (a2 , bn ),

(a3 , b1 ), (a3 , b2 ), (a3 , b3 ), … , (a3 , bn ),

(am , b1 ), (am , b2 ), (am , b3 ), … , (am , bn )}.

Notice what we have done here: we made m rows of n pairs, for a total of m ⋅ n pairs.
Each row above is really {a i} ×B for some a i ∈ A. That is, we fixed the A -element. Broken up this way, we have
A × B = ({ a1 } × B) ∪ ({ a2 } × B) ∪ ({ a3 } × B) ∪ ⋯ ∪ ({ am } × B).

So A × B is really the union of m disjoint sets. Each of those sets has n elements in them. The total (using the additive principle)
is n + n + n + ⋯ + n = m ⋅ n.
To summarize:

Multiplicative Principle (with sets)

Given two sets A and B, we have |A × B| = |A| ⋅ |B| .

Again, we can easily extend this to any number of sets.

Principle of Inclusion/Exclusion
Investigate!
A recent buzz marketing campaign for Village Inn surveyed patrons on their pie preferences. People were asked whether they
enjoyed (A) Apple, (B) Blueberry or (C) Cherry pie (respondents answered yes or no to each type of pie, and could say yes to
more than one type). The following table shows the results of the survey.

Pies enjoyed: A B C AB AC BC ABC

Number of
20 13 26 9 15 7 5
people:

How many of those asked enjoy at least one of the kinds of pie? Also, explain why the answer is not 95.

2.1.4 https://math.libretexts.org/@go/page/32561
While we are thinking about sets, consider what happens to the additive principle when the sets are NOT disjoint. Suppose we want
to find |A ∪ B| and know that |A| = 10 and |B| = 8. This is not enough information though. We do not know how many of the 8
elements in B are also elements of A. However, if we also know that |A ∩ B| = 6, then we can say exactly how many elements
are in A, and, of those, how many are in B and how many are not (6 of the 10 elements are in B, so 4 are in A but not in B ). We
could fill in a Venn diagram as follows:

This says there are 6 elements in A ∩ B, 4 elements in A ∖ B and 2 elements in B ∖ A. Now these three sets are disjoint, so we
can use the additive principle to find the number of elements in A ∪ B. It is 6 + 4 + 2 = 12.
This will always work, but drawing a Venn diagram is more than we need to do. In fact, it would be nice to relate this problem to
the case where A and B are disjoint. Is there one rule we can make that works in either case?
Here is another way to get the answer to the problem above. Start by just adding |A| + |B| . This is 10 + 8 = 18, which would be
the answer if |A ∩ B| = 0. We see that we are off by exactly 6, which just so happens to be |A ∩ B| . So perhaps we guess,
|A ∪ B| = |A| + |B| − |A ∩ B| .

This works for this one example. Will it always work? Think about what we are doing here. We want to know how many things are
either in A or B (or both). We can throw in everything in A, and everything in B. This would give |A| + |B| many elements. But
of course when you actually take the union, you do not repeat elements that are in both. So far we have counted every element in
A ∩ B exactly twice: once when we put in the elements from A and once when we included the elements from B. We correct by

subtracting out the number of elements we have counted twice. So we added them in twice, subtracted once, leaving them counted
only one time.
In other words, we have:

Cardinality of a union (2 sets)


For any finite sets A and B,

|A ∪ B| = |A| + |B| − |A ∩ B| .

We can do something similar with three sets.

Example 2.1.8

An examination in three subjects, Algebra, Biology, and Chemistry, was taken by 41 students. The following table shows how
many students failed in each single subject and in their various combinations:

Subject: A B C AB AC BC ABC

Failed: 12 5 8 2 6 3 1

How many students failed at least one subject?

Solution
The answer is not 37, even though the sum of the numbers above is 37. For example, while 12 students failed Algebra, 2 of
those students also failed Biology, 6 also failed Chemestry, and 1 of those failed all three subjects. In fact, that 1 student
who failed all three subjects is counted a total of 7 times in the total 37. To clarify things, let us think of the students who
failed Algebra as the elements of the set A, and similarly for sets B and C . The one student who failed all three subjects is
the lone element of the set A ∩ B ∩ C . Thus, in Venn diagrams:

2.1.5 https://math.libretexts.org/@go/page/32561
Now let's fill in the other intersections. We know A ∩ B contains 2 elements, but 1 element has already been counted. So
we should put a 1 in the region where A and B intersect (but C does not). Similarly, we calculate the cardinality of
(A ∩ C ) ∖ B, and (B ∩ C ) ∖ A:

Next, we determine the numbers which should go in the remaining regions, including outside of all three circles. This last
number is the number of students who did not fail any subject:

We found 5 goes in the “A only” region because the entire circle for A needed to have a total of 12, and 7 were already
accounted for. Similarly, we calculate the “B only” region to contain only 1 student and the “C only” region to contain no
students.
Thus the number of students who failed at least one class is 15 (the sum of the numbers in each of the eight disjoint
regions). The number of students who passed all three classes is 26: the total number of students, 41, less the 15 who failed
at least one class.
Note that we can also answer other questions. For example, now many students failed just Chemistry? None. How many
passed Algebra but failed both Biology and Chemistry? This corresponds to the region inside both B and C but outside of
A, containing 2 students.

Could we have solved the problem above in an algebraic way? While the additive principle generalizes to any number of sets, when
we add a third set here, we must be careful. With two sets, we needed to know the cardinalities of A, B, and A ∩ B in order to find
the cardinality of A ∪ B. With three sets we need more information. There are more ways the sets can combine. Not surprisingly
then, the formula for cardinality of the union of three non-disjoint sets is more complicated:

Cardinality of a union (3 sets)


For any finite sets A, B, and C ,

|A ∪ B ∪ C | = |A| + |B| + |C | − |A ∩ B| − |A ∩ C | − |B ∩ C | + |A ∩ B ∩ C |

To determine how many elements are in at least one of A, B, or C we add up all the elements in each of those sets. However, when
we do that, any element in both A and B is counted twice. Also, each element in both A and C is counted twice, as are elements in
B and C , so we take each of those out of our sum once. But now what about the elements which are in A ∩ B ∩ C (in all three

sets)? We added them in three times, but also removed them three times. They have not yet been counted. Thus we add those
elements back in at the end.
Returning to our example above, we have |A| = 12, |B| = 5, |C | = 8. We also have |A ∩ B| = 2, |A ∩ C | = 6, |B ∩ C | = 3,

and |A ∩ B ∩ C | = 1. Therefore:
|A ∪ B ∪ C | = 12 + 5 + 8 − 2 − 6 − 3 + 1 = 15

This is what we got when we solved the problem using Venn diagrams.
This process of adding in, then taking out, then adding back in, and so on is called the Principle of Inclusion/Exclusion, or simply
PIE. We will return to this counting technique later to solve for more complicated problems (involving more than 3 sets).

This page titled 2.1: Additive and Multiplicative Principles is shared under a CC BY-SA license and was authored, remixed, and/or curated by
Oscar Levin.
1.1: Additive and Multiplicative Principles by Oscar Levin is licensed CC BY-SA 4.0.

2.1.6 https://math.libretexts.org/@go/page/32561
2.2: Binomial Coefficients
Investigate!
In chess, a rook can move only in straight lines (not diagonally). Fill in each square of the chess board below with the number
of different shortest paths the rook, in the upper left corner, can take to get to that square. For example, one square is already
filled in. There are six different paths from the rook to the square: DDRR (down down right right), DRDR, DRRD, RDDR,
RDRD and RRDD.

Here are some apparently different discrete objects we can count: subsets, bit strings, lattice paths, and binomial coefficients. We
will give an example of each type of counting problem (and say what these things even are). As we will see, these counting
problems are surprisingly similar.

Subsets
Subsets should be familiar, otherwise read over Section 0.3 again. Suppose we look at the set A = {1, 2, 3, 4, 5} . How many
subsets of A contain exactly 3 elements?
First, a simpler question: How many subsets of A are there total? In other words, what is |P(A)| (the cardinality of the power set
of A )? Think about how we would build a subset. We need to decide, for each of the elements of A, whether or not to include the
element in our subset. So we need to decide “yes” or “no” for the element 1. And for each choice we make, we need to decide
“yes” or “no” for the element 2. And so on. For each of the 5 elements, we have 2 choices. Therefore the number of subsets is
simply 2 ⋅ 2 ⋅ 2 ⋅ 2 ⋅ 2 = 2 (by the multiplicative principle).
5

Of those 32 subsets, how many have 3 elements? This is not obvious. Note that we cannot just use the multiplicative principle.
Maybe we want to say we have 2 choices (yes/no) for the first element, 2 choices for the second, 2 choices for the third, and then
only 1 choice for the other two. But what if we said “no” to one of the first three elements? Then we would have two choices for
the 4th element. What a mess!
Another (bad) idea: we need to pick three elements to be in our subset. There are 5 elements to choose from. So there are 5 choices
for the first element, and for each of those 4 choices for the second, and then 3 for the third (last) element. The multiplicative
principle would say then that there are a total of 5 ⋅ 4 ⋅ 3 = 60 ways to select the 3 element subset. But this cannot be correct (
60 > 32 for one thing). One of the outcomes we would get from these choices would be the set {3, 2, 5}, by choosing the element

3 first, then the element 2, then the element 5. Another outcome would be {5, 2, 3} by choosing the element 5 first, then the
element 2, then the element 3. But these are the same set! We can correct this by dividing: for each set of three elements, there are 6
outcomes counted amoung our 60 (since there are 3 choices for which element we list first, 2 for which we list second, and 1 for
which we list last). So we expect there to be 10 3-element subsets of A .
Is this right? Well, we could list out all 10 of them, being very systematic in doing so, to make sure we don't miss any or list any
twice. Or we could try to count how many subsets of A don't have 3 elements in them. How many have no elements? Just 1 (the
empty set). How many have 5? Again, just 1. These are the cases in which we say “no” to all elements, or “yes” to all elements.
Okay, what about the subsets which contain a single element? There are 5 of these. We must say “yes” to exactly one element, and
there are 5 to choose from. This is also the number of subsets containing 4 elements. Those are the ones for which we must say
“no” to exactly one element.

2.2.1 https://math.libretexts.org/@go/page/32562
So far we have counted 12 of the 32 subsets. We have not yet counted the subsets with cardinality 2 and with cardinality 3. There
are a total of 20 subsets left to split up between these two groups. But the number of each must be the same! If we say “yes” to
exactly two elements, that can be accomplished in exactly the same number of ways as the number of ways we can say “no” to
exactly two elements. So the number of 2-element subsets is equal to the number of 3-element subsets. Together there are 20 of
these subsets, so 10 each.

Number of
0 1 2 3 4 5
elements:

Number of
1 5 10 10 5 1
subsets:

Bit Strings
“Bit” is short for “binary digit,” so a bit string is a string of binary digits. The binary digits are simply the numbers 0 and 1. All of
the following are bit strings:
1001 0 1111 1010101010

The number of bits (0's or 1's) in the string is the length of the string; the strings above have lengths 4, 1, 4, and 10 respectively. We
also can ask how many of the bits are 1's. The number of 1's in a bit string is the weight of the string; the weights of the above
strings are 2, 0, 4, and 5 respectively.

Definition: Bit Strings


An n -bit string is a bit string of length n . That is, it is a string containing n symbols, each of which is a bit, either 0 or 1.
The weight of a bit string is the number of 1's in it.
B is the set of all n -bit strings.
n

B is the set of all n -bit strings of weight k .


n
k

For example, the elements of the set B2


3
are the bit strings 011, 101, and 110. Those are the only strings containing three bits
exactly two of which are 1's.
The counting questions: How many bit strings have length 5? How many of those have weight 3? In other words, we are asking for
the cardinalities |B | and |B |.
5 5
3

To find the number of 5-bit strings is straight forward. We have 5 bits, and each can either be a 0 or a 1. So there are 2 choices for
the first bit, 2 choices for the second, and so on. By the multiplicative principle, there are 2 ⋅ 2 ⋅ 2 ⋅ 2 ⋅ 2 = 2 = 32 such strings.
5

Finding the number of 5-bit strings of weight 3 is harder. Think about how such a string could start. The first bit must be either a 0
or a 1. In the first case (the string starts with a 0), we must then decide on four more bits. To have a total of three 1's, among those
four remaining bits there must be three 1's. To count all of these strings, we must include all 4-bit strings of weight 3. In the second
case (the string starts with a 1), we still have four bits to choose, but now only two of them can be 1's, so we should look at all the
4-bit strings of weight 2. So the strings in B all have the form 1B (that is, a 1 followed by a string from B ) or 0B . These two
5
3
4
2
4
2
4
3

sets are disjoint, so we can use the additive principle:


5 4 4
| B | = | B | + | B |.
3 2 3

This is an example of a recurrence relation. We represented one instance of our counting problem in terms of two simpler instances
of the problem. If only we knew the cardinalities of B and B . Repeating the same reasoning,
4
2
4
3

4 3 3 4 3 3
| B2 | = | B1 | + | B2 | and | B3 | = | B2 | + | B3 |.

We can keep going down, but this should be good enough. Both B and B contain 3 bit strings: we must pick one of the three bits
3
1
3
2

to be a 1 (three ways to do that) or one of the three bits to be a 0 (three ways to do that). Also, B contains just one string: 111.
3
3

Thus |B | = 6 and |B | = 4, which puts B at a total of 10 strings.


4
2
4
3
5
3

But wait —32 and 10 were the answers to the counting questions about subsets. Coincidence? Not at all. Each bit string can be
thought of as a code for a subset. For the set A = {1, 2, 3, 4, 5}, we would use 5-bit strings, one bit for each element of A . Each bit
in the string is a 0 if its corresponding element of A is not in the subset, and a 1 if the element of A is in the subset. Remember,

2.2.2 https://math.libretexts.org/@go/page/32562
deciding the subset amounted to a sequence of five yes/no votes for the elements of A . Instead of yes, we put a 1; instead of no, we
put a 0.
For example, the bit string 11001 represents the subset {1, 2, 5} since the first, second and fifth bits are 1's. The subset {3, 5}

would be coded by the string 00101. What we really have here is a bijection from P(A) to B . 5

Now for a subset to contain exactly three elements, the corresponding bit string must contain exactly three 1's. In other words, the
weight must be 3. Thus counting the number of 3-element subsets of A is the same as counting the number 5-bit strings of weight
3.

Lattice Paths
The integer lattice is the set of all points in the Cartesian plane for which both the x and y coordinates are integers. If you like to
draw graphs on graph paper, the lattice is the set of all the intersections of the grid lines.
A lattice path is one of the shortest possible paths connecting two points on the lattice, moving only horizontally and vertically. For
example, here are three possible lattice paths from the points (0, 0) to (3, 2):

Notice to ensure the path is the shortest possible, each move must be either to the right or up. Additionally, in this case, note that no
matter what path we take, we must make three steps right and two steps up. No matter what order we make these steps, there will
always be 5 steps. Thus each path has length 5.
The counting question: how many lattice paths are there between (0, 0) and (3, 2)? We could try to draw all of these, or instead of
drawing them, maybe just list which direction we travel on each of the 5 steps. One path might be RRUUR, or maybe UURRR, or
perhaps RURRU (those correspond to the three paths drawn above). So how many such strings of R's and U's are there?
Notice that each of these strings must contain 5 symbols. Exactly 3 of them must be R's (since our destination is 3 units to the
right). This seems awfully familiar. In fact, what if we used 1's instead of R's and 0's instead of U's? Then we would just have 5-bit
strings of weight 3. There are 10 of those, so there are 10 lattice paths from (0,0) to (3,2).
The correspondence between bit strings and lattice paths does not stop there. Here is another way to count lattice paths. Consider
the lattice shown below:

Any lattice path from (0,0) to (3,2) must pass through exactly one of A and B . The point A is 4 steps away from (0,0) and two of
them are towards the right. The number of lattice paths to A is the same as the number of 4-bit strings of weight 2, namely 6. The
point B is 4 steps away from (0,0), but now 3 of them are towards the right. So the number of paths to point B is the same as the
number of 4-bit strings of weight 3, namely 4. So the total number of paths to (3,2) is just 6 + 4 . This is the same way we
calculated the number of 5-bit strings of weight 3. The point: the exact same recurrence relation exists for bit strings and for lattice
paths.

Binomial Coefficients
Binomial coefficients are the coefficients in the expanded version of a binomial, such as (x + y) . What happens when we multiply
5

such a binomial out? We will expand (x + y) for various values of n . Each of these are done by multiplying everything out (i.e.,
n

FOIL-ing) and then collecting like terms.

2.2.3 https://math.libretexts.org/@go/page/32562
1
(x + y ) = x +y

2 2 2
(x + y ) =x + 2xy + y

3 3 2 2 3
(x + y ) =x + 3 x y + 3x y +y

4 4 3 2 2 3 4
(x + y ) =x + 4x y + 6x y + 4x y +y .

In fact, there is a quicker way to expand the above binomials. For example, consider the next one, (x + y)
5
. What we are really
doing is multiplying out,
(x + y)(x + y)(x + y)(x + y)(x + y).

If that looks daunting, go back to the case of (x + y ) = (x + y)(x + y)(x + y) . Why do we only have one x and y but three
3 3 3

x y and xy terms? Every time we distribute over an (x + y) we create two copies of what is left, one multiplied by x, the other
2 2

multiplied by y . To get x , we need to pick the “multiplied by x” side every time (we don't have any y 's in the term). This will only
3

happen once. On the other hand, to get x y we need to select the x side twice and the y side once. In other words, we need to pick
2

one of the three (x + y) terms to “contribute” their y .


Similarly, in the expansion of (x + y ) , there will be only one x term and one y term. This is because to get an x , we need to
5 5 5 5

use the x term in each of the copies of the binomial (x + y), and similarly for y . What about x y? To get terms like this, we need 5 4

to use four x's and one y, so we need exactly one of the five binomials to contribute a y . There are 5 choices for this, so there are 5
ways to get x y, so the coefficient of x y is 5. This is also the coefficient for xy for the same (but opposite) reason: there are 5
4 4 4

ways to pick which of the 5 binomials contribute the single x. So far we have
5 5 4 3 2 2 3 4 5
(x + y ) =x + 5x y + ? x y + ? x y + 5x y +y .
––
– ––

We still need the coefficients of x y and x y . In both cases, we need to pick exactly 3 of the 5 binomials to contribute one
3 2 2 3

variable, the other two to contribute the other. Wait. This sounds familiar. We have 5 things, each can be one of two things, and we
need a total of 3 of one of them. That's just like taking 5 bits and making sure exactly 3 of them are 1's. So the coefficient of x y 3 2

(and also x y ) will be exactly the same as the number of bit strings of length 5 and weight 3, which we found earlier to be 10. So
2 3

we have:
5 5 4 3 2 2 3 4 5
(x + y ) =x + 5 x y + 10 x y + 10 x y + 5x y +y .

These numbers we keep seeing over and over again. They are the number of subsets of a particular size, the number of bit strings of
a particular weight, the number of lattice paths, and the coefficients of these binomial products. We will call them binomial
coefficients. We even have a special symbol for them: ( ). n

Definition: Binomial Coefficients

For each integer n ≥ 0 and integer k with 0 ≤ k ≤ n there is a number


n
( )
k

read “n choose k .” We have:


n
( ) = | Bk |,
k
the number of n -bit strings of weight k .
n

n
( )
k
is the number of subsets of a set of size n each with cardinality k .
) is the number of lattice paths of length n containing k steps to the right.
n
(
k

) is the coefficient of x y in the expansion of (x + y) .


n k n−k n
(
k

) is the number of ways to select k objects from a total of n objects.


n
(
k

The last bullet point is usually taken as the definition of ( ). Out of n objects we must choose k of them, so there are n choose k
n

ways of doing this. Each of our counting problems above can be viewed in this way:
How many subsets of {1, 2, 3, 4, 5}contain exactly 3 elements? We must choose 3 of the 5 elements to be in our subset. There
are ( ) ways to do this, so there are ( ) such subsets.
5

3
5

2.2.4 https://math.libretexts.org/@go/page/32562
How many bit strings have length 5 and weight 3? We must choose 3 of the 5 bits to be 1's. There are ( ) ways to do this, so
5

there are ( ) such bit strings.


5

How many lattice paths are there from (0,0) to (3,2)? We must choose 3 of the 5 steps to be towards the right. There are ( ) 5

ways to do this, so there are ( ) such lattice paths.


5

What is the coefficient of x y in the expansion of (x + y ) ? We must choose 3 of the 5 copies of the binomial to contribute an
3 2 5

x. There are ( ) ways to do this, so the coefficient is ( ).


5 5

3 3

It should be clear that in each case above, we have the right answer. All we had to do is phrase the question correctly and it became
obvious that ( ) is correct. However, this does not tell us that the answer is in fact 10 in each case. We will eventually find a
5

formula for ( ), but for now, look back at how we arrived at the answer 10 in our counting problems above. It all came down to bit
n

strings, and we have a recurrence relation for bit strings:


n n−1 n−1
|B | = |B | + |B |.
k k−1 k

Remember, this is because we can start the bit string with either a 1 or a 0. In both cases, we have n − 1 more bits to pick. The
strings starting with 1 must contain k − 1 more 1's, while the strings starting with 0 still need k more 1's.
Since |B n
k
n
| = ( ),
k
the same recurrence relation holds for binomial coefficients:

Recurrence relation for ( n

k
)

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

Pascal's Triangle
Let's arrange the binomial coefficients ( n

k
) into a triangle like follows:

This can continue as far down as we like. The recurrence relation for ( ) tells us that each entry in the triangle is the sum of the two
n

entries above it. The entries on the sides of the triangle are always 1. This is because ( ) = 1 for all n since there is only one way
n

to pick 0 of n objects and ( ) = 1 since there is one way to select all n out of n objects. Using the recurrence relation, and the fact
n

that the sides of the triangle are 1's, we can easily replace all the entries above with the correct values of ( ). Doing so gives us
n

Pascal's triangle.

2.2.5 https://math.libretexts.org/@go/page/32562
We can use Pascal's triangle to calculate binomial coefficients. For example, using the triangle below, we can find ( 12

6
) = 924 .

This page titled 2.2: Binomial Coefficients is shared under a CC BY-SA license and was authored, remixed, and/or curated by Oscar Levin.
1.2: Binomial Coefficients by Oscar Levin is licensed CC BY-SA 4.0.

2.2.6 https://math.libretexts.org/@go/page/32562
2.3: Combinations and Permutations
Investigate!
You have a bunch of chips which come in five different colors: red, blue, green, purple and yellow.
1. How many different two-chip stacks can you make if the bottom chip must be red or blue? Explain your answer using both
the additive and multiplicative principles.
2. How many different three-chip stacks can you make if the bottom chip must be red or blue and the top chip must be green,
purple or yellow? How does this problem relate to the previous one?
3. How many different three-chip stacks are there in which no color is repeated? What about four-chip stacks?
4. Suppose you wanted to take three different colored chips and put them in your pocket. How many different choices do you
have? What if you wanted four different colored chips? How do these problems relate to the previous one?

A permutation is a (possible) rearrangement of objects. For example, there are 6 permutations of the letters a, b, c:
abc, acb, bac, bca, cab, cba.

We know that we have them all listed above —there are 3 choices for which letter we put first, then 2 choices for which letter
comes next, which leaves only 1 choice for the last letter. The multiplicative principle says we multiply 3 ⋅ 2 ⋅ 1.

Example 2.3.1

How many permutations are there of the letters a, b, c, d, e, f?

Answer
We do NOT want to try to list all of these out. However, if we did, we would need to pick a letter to write down first. There
are 6 choices for that letter. For each choice of first letter, there are 5 choices for the second letter (we cannot repeat the first
letter; we are rearranging letters and only have one of each), and for each of those, there are 4 choices for the third, 3
choices for the fourth, 2 choices for the fifth and finally only 1 choice for the last letter. So there are
6 ⋅ 5 ⋅ 4 ⋅ 3 ⋅ 2 ⋅ 1 = 720 permutations of the 6 letters.

A piece of notation is helpful here: n!, read “n factorial”, is the product of all positive integers less than or equal to n (for reasons
of convenience, we also define 0! to be 1). So the number of permutation of 6 letters, as seen in the previous example is
6! = 6 ⋅ 5 ⋅ 4 ⋅ 3 ⋅ 2 ⋅ 1. This generalizes:

Permutations of n elements

There are n! = n ⋅ (n − 1) ⋅ (n − 2) ⋅ ⋯ ⋅ 2 ⋅ 1 permutations of n (distinct) elements.

Counting Bijective Functions


How many functions f : {1, 2, … , 8} → {1, 2, … , 8} are bijective?

Solution
Remember what it means for a function to be bijective: each element in the codomain must be the image of exactly one
element of the domain. Using two-line notation, we could write one of these bijections as

1 2 3 4 5 6 7 8
f =( )
3 1 5 8 7 6 2 4

What we are really doing is just rearranging the elements of the codomain, so we are creating a permutation of 8 elements.
In fact, “permutation” is another term used to describe bijective functions from a finite set to itself.
If you believe this, then you see the answer must be 8! = 8 ⋅ 7 ⋅ ⋯ ⋅ 1 = 40320. You can see this directly as well: for each
element of the domain, we must pick a distinct element of the codomain to map to. There are 8 choices for where to send 1,
then 7 choices for where to send 2, and so on. We multiply using the multiplicative principle.

2.3.1 https://math.libretexts.org/@go/page/32563
Sometimes we do not want to permute all of the letters/numbers/elements we are given.

Example 2.3.3

How many 4 letter “words” can you make from the letters a through f, with no repeated letters?

Solution
This is just like the problem of permuting 4 letters, only now we have more choices for each letter. For the first letter, there
are 6 choices. For each of those, there are 5 choices for the second letter. Then there are 4 choices for the third letter, and 3
choices for the last letter. The total number of words is \(6\cdot 5\cdot 4 \cdot 3 = 360\text{.}\) This is not \(6!\) because we
never multiplied by 2 and 1. We could start with \(6!\) and then cancel the 2 and 1, and thus write \(\frac{6!}{2!}\text{.}\)
In general, we can ask how many permutations exist of k objects choosing those objects from a larger collection of n
objects. (In the example above, k = 4, and n = 6. ) We write this number P (n, k) and sometimes call it a k -permutation of
n elements. From the example above, we see that to compute P (n, k) we must apply the multiplicative principle to k

numbers, starting with n and counting backwards. For example

P (10, 4) = 10 ⋅ 9 ⋅ 8 ⋅ 7.

Notice again that P (10, 4) starts out looking like 10!, but we stop after 7. We can formally account for this “stopping” by
dividing away the part of the factorial we do not want:
10 ⋅ 9 ⋅ 8 ⋅ 7 ⋅ 6 ⋅ 5 ⋅ 4 ⋅ 3 ⋅ 2 ⋅ 1 10!
P (10, 4) = = .
6⋅5⋅4⋅3⋅2⋅1 6!

Careful: The factorial in the denominator is not 4! but rather (10 − 4)!.

k -permutations of n elements

P (n, k) is the number of k -permutations of n elements, the number of ways to arrange k objects chosen from n distinct
objects.
n!
P (n, k) = .
(n − k)!

Note that when n = k, we have P (n, n) =


n!

(n−n)!
= n! (since we defined 0! to be 1). This makes sense —we already know n!

gives the number of permutations of all n objects.

Counting injective functions


How many functions f : {1, 2, 3} → {1, 2, 3, 4, 5, 6, 7, 8} are injective?

Solution
Note that it doesn't make sense to ask for the number of bijections here, as there are none (because the codomain is larger
than the domain, there are no surjections). But for a function to be injective, we just can't use an element of the codomain
more than once.
We need to pick an element from the codomain to be the image of 1. There are 8 choices. Then we need to pick one of the
remaining 7 elements to be the image of 2. Finally, one of the remaining 6 elements must be the image of 3. So the total
number of functions is 8 ⋅ 7 ⋅ 6 = P (8, 3).
What this demonstrates in general is that the number of injections f : A → B, where |A| = k and |B| = n, is P (n, k).

Here is another way to find the number of k -permutations of n elements: first select which k elements will be in the permutation,
then count how many ways there are to arrange them. Once you have selected the k objects, we know there are k! ways to arrange
(permute) them. But how do you select k objects from the n? You have n objects, and you need to choose k of them. You can do

2.3.2 https://math.libretexts.org/@go/page/32563
that in ( ) ways. Then for each choice of those k elements, we can permute them in k! ways. Using the multiplicative principle, we
n

get another formula for P (n, k):

n
P (n, k) = ( ) ⋅ k!.
k

Now since we have a closed formula for P (n, k) already, we can substitute that in:
n! n
=( ) ⋅ k!.
(n − k)! k

If we divide both sides by k! we get a closed formula for ( n

k
).

Closed formula for ( n

k
)

n n!
( ) =
k (n − k)!k!

We say P (n, k) counts permutations, and ( ) counts combinations. The formulas for each are very similar, there is just an extra k!
n

in the denominator of ( ). That extra k! accounts for the fact that ( ) does not distinguish between the different orders that the k
n

k
n

objects can appear in. We are just selecting (or choosing) the k objects, not arranging them. Perhaps “combination” is a misleading
label. We don't mean it like a combination lock (where the order would definitely matter). Perhaps a better metaphor is a
combination of flavors — you just need to decide which flavors to combine, not the order in which to combine them.
To further illustrate the connection between combinations and permutations, we close with an example.

Example 2.3.5

You decide to have a dinner party. Even though you are incredibly popular and have 14 different friends, you only have enough
chairs to invite 6 of them.
1. How many choices do you have for which 6 friends to invite?
2. What if you need to decide not only which friends to invite but also where to seat them along your long table? How many
choices do you have then?

Solution
1. You must simply choose 6 friends from a group of 14. This can be done in ( ) ways. We can find this number either by
14

using Pascal's triangle or the closed formula: 14!


= 3003.
8!⋅6!

2. Here you must count all the ways you can permute 6 friends chosen from a group of 14. So the answer is P (14, 6),
which can be calculated as 14!

8!
= 2192190.

Notice that we can think of this counting problem as a question about counting functions: how many injective functions are
there from your set of 6 chairs to your set of 14 friends (the functions are injective because you can't have a single chair go
to two of your friends).
How are these numbers related? Notice that P (14, 6) is much larger than ( ). This makes sense. ( ) picks 6 friends, but
14

6
14

P (14, 6) arranges the 6 friends as well as picks them. In fact, we can say exactly how much larger P (14, 6) is. In both

counting problems we choose 6 out of 14 friends. For the first one, we stop there, at 3003 ways. But for the second
counting problem, each of those 3003 choices of 6 friends can be arranged in exactly 6! ways. So now we have 3003 ⋅ 6!
choices and that is exactly 2192190.
Alternatively, look at the first problem another way. We want to select 6 out of 14 friends, but we do not care about the
order they are selected in. To select 6 out of 14 friends, we might try this:

14 ⋅ 13 ⋅ 12 ⋅ 11 ⋅ 10 ⋅ 9.

This is a reasonable guess, since we have 14 choices for the first guest, then 13 for the second, and so on. But the guess is
wrong (in fact, that product is exactly 2192190 = P (14, 6)). It distinguishes between the different orders in which we could

2.3.3 https://math.libretexts.org/@go/page/32563
invite the guests. To correct for this, we could divide by the number of different arrangements of the 6 guests (so that all of
these would count as just one outcome). There are precisely 6! ways to arrange 6 guests, so the correct answer to the first
question is
14 ⋅ 13 ⋅ 12 ⋅ 11 ⋅ 10 ⋅ 9
.
6!

Note that another way to write this is


14!
.
8! ⋅ 6!

which is what we had originally.

This page titled 2.3: Combinations and Permutations is shared under a CC BY-SA license and was authored, remixed, and/or curated by Oscar
Levin.
1.3: Combinations and Permutations by Oscar Levin is licensed CC BY-SA 4.0.

2.3.4 https://math.libretexts.org/@go/page/32563
2.4: Combinatorial Proofs
Investigate!
1. The Stanley Cup is decided in a best of 7 tournament between two teams. In how many ways can your team win? Let's
answer this question two ways:
a. How many of the 7 games does your team need to win? How many ways can this happen?
b. What if the tournament goes all 7 games? So you win the last game. How many ways can the first 6 games go down?
c. What if the tournament goes just 6 games? How many ways can this happen? What about 5 games? 4 games?
d. What are the two different ways to compute the number of ways your team can win? Write down an equation involving
binomial coefficients (that is, ( )'s). What pattern in Pascal's triangle is this an example of?
n

2. Generalize. What if the rules changed and you played a best of 9 tournament (5 wins required)? What if you played an n
game tournament with k wins required to be named champion?

Patterns in Pascal's Triangle


Have a look again at Pascal's triangle. Forget for a moment where it comes from. Just look at it as a mathematical object. What do
you notice?

There are lots of patterns hidden away in the triangle, enough to fill a reasonably sized book. Here are just a few of the most
obvious ones:
1. The entries on the border of the triangle are all 1.
2. Any entry not on the border is the sum of the two entries above it.
3. The triangle is symmetric. In any row, entries on the left side are mirrored on the right side.
4. The sum of all entries on a given row is a power of 2. (You should check this!)
We would like to state these observations in a more precise way, and then prove that they are correct. Now each entry in Pascal's
triangle is in fact a binomial coefficient. The 1 on the very top of the triangle is ( ). The next row (which we will call row 1, even
0

though it is not the top-most row) consists of ( ) and ( ). Row 4 (the row 1, 4, 6, 4, 1) consists of the binomial coefficients
1

0
1

4 4 4 4 4
( ) ( ) ( ) ( ) ( ).
0 1 2 3 4

Given this description of the elements in Pascal's triangle, we can rewrite the above observations as follows:
1. (
n

0
) =1 and ( n

n
) =1 .
2. (
n

k
) =(
n−1

k−1
)+(
n−1

k
) .
3. (
n

k
) =(
n−k
n
) .
4. (
n

0
n
)+( )+( )+⋯ +( ) = 2
1
n

2
n

n
n
.
Each of these is an example of a binomial identity: an identity (i.e., equation) involving binomial coefficients.

2.4.1 https://math.libretexts.org/@go/page/32564
Our goal is to establish these identities. We wish to prove that they hold for all values of n and k . These proofs can be done in
many ways. One option would be to give algebraic proofs, using the formula for ( ): n

n n!
( ) = .
k (n − k)! k!

Here's how you might do that for the second identity above.

Example 2.4.1

Give an algebraic proof for the binomial identity


n n−1 n−1
( ) =( ) +( ).
k k−1 k

Solution
Proof
By the definition of ( ), we have
n

n−1 (n − 1)! (n − 1)!


( ) = =
k−1 (n − 1 − (k − 1))!(k − 1)! (n − k)!(k − 1)!

and

n−1 (n − 1)!
( ) = .
k (n − 1 − k)!k!

Thus, starting with the right-hand side of the equation:

n−1 n−1 (n − 1)! (n − 1)!


( ) +( ) = +
k−1 k (n − k)!(k − 1)! (n − 1 − k)! k!

(n − 1)!k (n − 1)!(n − k)
= +
(n − k)! k! (n − k)! k!

(n − 1)!(k + n − k)
=
(n − k)! k!

n!
=
(n − k)! k!

n
=( ).
k

The second line (where the common denominator is found) works because k(k − 1)! = k! and
(n − k)(n − k − 1)! = (n − k)! .

This is certainly a valid proof, but also is entirely useless. Even if you understand the proof perfectly, it does not tell you why the
identity is true. A better approach would be to explain what ( ) means and then say why that is also what ( ) + ( ) means.
n

k
n−1

k−1
n−1

Let's see how this works for the four identities we observed above.

Example 2.4.2

Explain why ( n

0
) =1 and ( n

n
) =1 .

Solution
What do these binomial coefficients tell us? Well, ( ) gives the number of ways to select 0 objects from a collection of n
n

objects. There is only one way to do this, namely to not select any of the objects. Thus ( ) = 1 . Similarly, ( ) gives the
n

0
n

2.4.2 https://math.libretexts.org/@go/page/32564
number of ways to select n objects from a collection of n objects. There is only one way to do this: select all n objects.
Thus ( ) = 1 .
n

Alternatively, we know that ( ) is the number of n -bit strings with weight 0. There is only one such string, the string of all
n

0's. So ( ) = 1 . Similarly ( ) is the number of n -bit strings with weight n . There is only one string with this property, the
n

0
n

string of all 1's.


Another way: ( ) gives the number of subsets of a set of size n containing 0 elements. There is only one such subset, the
n

empty set. ( ) gives the number of subsets containing n elements. The only such subset is the original set (of all elements).
n

Example 2.4.3

Explain why ( n

k
) =(
n−1

k−1
n−1
)+(
k
) .

Solution
The easiest way to see this is to consider bit strings. ( ) is the number of bit strings of length n containing k 1's. Of all of
n

these strings, some start with a 1 and the rest start with a 0. First consider all the bit strings which start with a 1. After the 1,
there must be n − 1 more bits (to get the total length up to n ) and exactly k − 1 of them must be 1's (as we already have
one, and we need k total). How many strings are there like that? There are exactly ( ) such bit strings, so of all the n−1

k−1

length n bit strings containing k 1's, ( ) of them start with a 1. Similarly, there are ( ) which start with a 0 (we still
n−1

k−1
n−1

need n − 1 bits and now k of them must be 1's). Since there are ( ) bit strings containing n − 1 bits with k 1's, that is
n−1

the number of length n bit strings with k 1's which start with a 0. Therefore ( ) = ( ) + ( ) . n

k
n−1

k−1
n−1

Another way: consider the question, how many ways can you select k pizza toppings from a menu containing n choices?
One way to do this is just ( ). Another way to answer the same question is to first decide whether or not you want
n

anchovies. If you do want anchovies, you still need to pick k − 1 toppings, now from just n − 1 choices. That can be done
in ( ) ways. If you do not want anchovies, then you still need to select k toppings from n − 1 choices (the anchovies are
n−1

k−1

out). You can do that in ( ) ways. Since the choices with anchovies are disjoint from the choices without anchovies, the
n−1

total choices are ( ) + ( ) . But wait. We answered the same question in two different ways, so the two answers must
n−1

k−1
n−1

be the same. Thus ( ) = ( ) + ( ) .


n

k
n−1

k−1
n−1

You can also explain (prove) this identity by counting subsets, or even lattice paths.

Example 2.4.4

Prove the binomial identity


n n
( ) =( ).
k n−k

Solution
Why is this true? ( ) counts the number of ways to select k things from n choices. On the other hand, ( ) counts the
n

k
n

n−k

number of ways to select n − k things from n choices. Are these really the same? Well, what if instead of selecting the
n − k things you choose to exclude them. How many ways are there to choose n − k things to exclude from n choices.

Clearly this is ( ) as well (it doesn't matter whether you include or exclude the things once you have chosen them). And
n−k
n

if you exclude n − k things, then you are including the other k things. So the set of outcomes should be the same.
Let's try the pizza counting example like we did above. How many ways are there to pick k toppings from a list of n
choices? On the one hand, the answer is simply ( ). Alternatively, you could make a list of all the toppings you don't want.
n

To end up with a pizza containing exactly k toppings, you need to pick n − k toppings to not put on the pizza. You have
) choices for the toppings you don't want. Both of these ways give you a pizza with k toppings, in fact all the ways to
n
(
n−k

get a pizza with k toppings. Thus these two answers must be the same: ( ) = ( ) . n

k
n

n−k

2.4.3 https://math.libretexts.org/@go/page/32564
You can also prove (explain) this identity using bit strings, subsets, or lattice paths. The bit string argument is nice: ( ) n

counts the number of bit strings of length n with k 1's. This is also the number of bit string of length n with k 0's (just
replace each 1 with a 0 and each 0 with a 1). But if a string of length n has k 0's, it must have n − k 1's. And there are
exactly ( ) strings of length n with n − k 1's.
n

n−k

Example 2.4.5

Prove the binomial identity


n n n n n
( ) +( ) +( ) +⋯ +( ) = 2 .
0 1 2 n

Solution
Proof
Let's do a “pizza proof” again. We need to find a question about pizza toppings which has 2 as the answer. How about
n

this: If a pizza joint offers n toppings, how many pizzas can you build using any number of toppings from no toppings to
all toppings, using each topping at most once?
On one hand, the answer is 2 . For each topping you can say “yes” or “no,” so you have two choices for each topping.
n

On the other hand, divide the possible pizzas into disjoint groups: the pizzas with no toppings, the pizzas with one topping,
the pizzas with two toppings, etc. If we want no toppings, there is only one pizza like that (the empty pizza, if you will) but
it would be better to think of that number as ( ) since we choose 0 of the n toppings. How many pizzas have 1 topping?
n

We need to choose 1 of the n toppings, so ( ). We have:n

Pizzas with 0 toppings: ( n

0
) Pizzas with 1 topping: ( n

1
) Pizzas with 2 toppings: (
n

2
)

The total number of possible pizzas will be the sum of these, which is exactly the left-hand side of the identity we are trying
to prove.
Again, we could have proved the identity using subsets, bit strings, or lattice paths (although the lattice path argument is a
little tricky).

Pizzas with n toppings: ( ). n

Hopefully this gives some idea of how explanatory proofs of binomial identities can go. It is worth pointing out that more
traditional proofs can also be beautiful. 3 Most every binomial identity can be proved using mathematical induction, using the
recursive definition for ( ). We will discuss induction in Section 2.5. For example, consider the following rather slick proof of the
n

last identity.
Expand the binomial (x + y ) n
:

n
n n
n n−1
n n−2 2
n n
n n
(x + y ) =( )x + ( )x y + ( )x y +⋯ +( )x ⋅ y + ( ) y .
0 1 2 n−1 n

Let x = 1 and y = 1 . We get:


n n n n n
n n n−1 n−2 2 n n
(1 + 1 ) =( )1 + ( )1 1 + ( )1 1 +⋯ +( )1 ⋅ 1 + ( ) 1 .
0 1 2 n−1 n

Of course this simplifies to:

n
n n n n n
(2 ) =( ) +( ) +( ) +⋯ +( ) + ( ).
0 1 2 n−1 n

Something fun to try: Let x = 1 and y = 2 . Neat huh?

2.4.4 https://math.libretexts.org/@go/page/32564
More Proofs
The explanatory proofs given in the above examples are typically called combinatorial proofs. In general, to give a combinatorial
proof for a binomial identity, say A = B you do the following:
1. Find a counting problem you will be able to answer in two ways.
2. Explain why one answer to the counting problem is A .
3. Explain why the other answer to the counting problem is B .
Since both A and B are the answers to the same question, we must have A = B .
The tricky thing is coming up with the question. This is not always obvious, but it gets easier the more counting problems you
solve. You will start to recognize types of answers as the answers to types of questions. More often what will happen is you will be
solving a counting problem and happen to think up two different ways of finding the answer. Now you have a binomial identity and
the proof is right there. The proof is the problem you just solved together with your two solutions.
For example, consider this counting question:

How many 10-letter words use exactly four A's, three B's, two C's and one D?
Let's try to solve this problem. We have 10 spots for letters to go. Four of those need to be A's. We can pick the four A-spots in ( ) 10

ways. Now where can we put the B's? Well there are only 6 spots left, we need to pick 3 of them. This can be done in ( ) ways. 6

The two C's need to go in two of the 3 remaining spots, so we have ( ) ways of doing that. That leaves just one spot of the D, but
3

we could write that 1 choice as ( ). Thus the answer is:


1

10 6 3 1
( )( )( )( ).
4 3 2 1

But why stop there? We can find the answer another way too. First let's decide where to put the one D: we have 10 spots, we need
to choose 1 of them, so this can be done in ( ) ways. Next, choose one of the ( ) ways to place the two C's. We now have 7 spots
10

1
9

left, and three of them need to be filled with B's. There are ( ) ways to do this. Finally the A's can be placed in ( ) (that is, only
7

3
4

one) ways. So another answer to the question is


10 9 7 4
( )( )( )( ).
1 2 3 4

Interesting. This gives us the binomial identity:


10 6 3 1 10 9 7 4
( )( )( )( ) = ( )( )( )( ).
4 3 2 1 1 2 3 4

Here are a couple of other binomial identities with combinatorial proofs.

Example 2.4.6

Prove the identity


n+2
1n + 2(n − 1) + 3(n − 2) + ⋯ + (n − 1)2 + n1 = ( ).
3

Solution
To give a combinatorial proof we need to think up a question we can answer in two ways: one way needs to give the left-
hand-side of the identity, the other way needs to be the right-hand-side of the identity. Our clue to what question to ask
comes from the right-hand side: ( ) counts the number of ways to select 3 things from a group of n + 2 things. Let's
n+2

name those things 1, 2, 3, … , n + 2. In other words, we want to find 3-element subsets of those numbers (since order
should not matter, subsets are exactly the right thing to think about). We will have to be a bit clever to explain why the left-
hand-side also gives the number of these subsets. Here's the proof.
Proof

2.4.5 https://math.libretexts.org/@go/page/32564
Consider the question “How many 3-element subsets are there of the set {1, 2, 3, … , n + 2}? ” We answer this in two
ways:
Answer 1: We must select 3 elements from the collection of n + 2 elements. This can be done in ( n+2

3
) ways.
Answer 2: Break this problem up into cases by what the middle number in the subset is. Say each subset is {a, b, c} written
in increasing order. We count the number of subsets for each distinct value of b. The smallest possible value of b is 2, and
the largest is n + 1 .
When b = 2 , there are 1 ⋅ n subsets: 1 choice for a and n choices (3 through n + 2 ) for c.
When b = 3 , there are 2 ⋅ (n − 1) subsets: 2 choices for a and n − 1 choices for c.
When b = 4 , there are 3 ⋅ (n − 2) subsets: 3 choices for a and n − 2 choices for c.
And so on. When b = n + 1 , there are n choices for a and only 1 choice for c, so n ⋅ 1 subsets.
Therefore the total number of subsets is

1n + 2(n − 1) + 3(n − 2) + ⋯ + (n − 1)2 + n1.

Since Answer 1 and Answer 2 are answers to the same question, they must be equal. Therefore

n+2
1n + 2(n − 1) + 3(n − 2) + ⋯ + (n − 1)2 + n1 = ( ).
3

Example 2.4.7

Prove the binomial identity


2 2 2 2
n n n n 2n
( ) +( ) +( ) +⋯ +( ) =( ).
0 1 2 n n

Solution 1
We will give two different proofs of this fact. The first will be very similar to the previous example (counting subsets). The
second proof is a little slicker, using lattice paths.
Proof
Consider the question: “How many pizzas can you make using n toppings when there are 2n toppings to choose from?”
Answer 1: There are 2n toppings, from which you must choose n . This can be done in ( 2n

n
) ways.
Answer 2: Divide the toppings into two groups of n toppings (perhaps n meats and n veggies). Any choice of n toppings
must include some number from the first group and some number from the second group. Consider each possible number
of meat toppings separately:
0 meats: ( n

0
n
)( )
n
, since you need to choose 0 of the n meats and n of the n veggies.
1 meat: ( n

1
)(
n−1
n
) , since you need 1 of n meats so n − 1 of n veggies.
2 meats: ( n

2
)(
n−2
n
) . Choose 2 meats and the remaining n − 2 toppings from the n veggies.
And so on. The last case is n meats, which can be done in ( n

n
n
)( )
0
ways.
Thus the total number of pizzas possible is
n n n n n n n n
( )( ) + ( )( ) + ( )( ) + ⋯ + ( )( ).
0 n 1 n−1 2 n−2 n 0

This is not quite the left-hand side … yet. Notice that n


( ) =( )
n
n

0
and ( n

n−1
n
) =( )
1
and so on, by the identity in Example
1.4.4. Thus we do indeed get

2.4.6 https://math.libretexts.org/@go/page/32564
2 2 2 2
n n n n
( ) +( ) +( ) +⋯ +( ) .
0 1 2 n

Since these two answers are answers to the same question, they must be equal, and thus
2 2 2 2
n n n n 2n
( ) +( ) +( ) +⋯ +( ) =( ).
0 1 2 n n

For an alternative proof, we use lattice paths. This is reasonable to consider because the right-hand side of the identity
reminds us of the number of paths from (0, 0) to (n, n) .
Proof
Consider the question: How many lattice paths are there from (0, 0) to (n, n)?
Answer 1: We must travel 2n steps, and n of them must be in the up direction. Thus there are ( 2n

n
) paths.
Answer 2: Note that any path from (0, 0) to (n, n) must cross the line x + y = n . That is, any path must pass through
exactly one of the points: (0, n) , (1, n − 1) , (2, n − 2) , …, (n, 0) . For example, this is what happens in the case n = 4:

How many paths pass through (0, n)? To get to that point, you must travel n units, and 0 of them are to the right, so there are ( ) n

ways to get to (0, n). From (0, n) to (n, n) takes n steps, and 0 of them are up. So there are ( ) ways to get from (0, n) to (n, n). n

Therefore there are ( )( ) paths from (0, 0) to (n, n) through the point (0, n).
n

0
n

What about through (1, n − 1) . There are ( ) paths to get there (n steps, 1 to the right) and
n

1
n
( )
1
paths to complete the journey to
(n, n) (n steps, 1 up). So there are ( )( ) paths from (0, 0) to (n, n) through (1, n − 1) .
n n

1 1

In general, to get to (n, n) through the point (k, n − k) we have ( ) paths to the midpoint and then (
n

k
n

k
) paths from the midpoint to
(n, n). So there are ( )( ) paths from (0, 0) to (n, n) through (k, n − k) .
n n

k k

All together then the total paths from (0, 0) to (n, n) passing through exactly one of these midpoints is
2 2 2 2
n n n n
( ) +( ) +( ) +⋯ +( ) .
0 1 2 n

Since these two answers are answers to the same question, they must be equal, and thus
2 2 2 2
n n n n 2n
( ) +( ) +( ) +⋯ +( ) =( ).
0 1 2 n n

This page titled 2.4: Combinatorial Proofs is shared under a CC BY-SA license and was authored, remixed, and/or curated by Oscar Levin.
1.4: Combinatorial Proofs by Oscar Levin is licensed CC BY-SA 4.0.

2.4.7 https://math.libretexts.org/@go/page/32564
2.5: Stars and Bars
Investigate!
Suppose you have some number of identical Rubik's cubes to distribute to your friends. Imagine you start with a single row of
the cubes.
1. Find the number of different ways you can distribute the cubes provided:
a. You have 3 cubes to give to 2 people.
b. You have 4 cubes to give to 2 people.
c. You have 5 cubes to give to 2 people.
d. You have 3 cubes to give to 3 people.
e. You have 4 cubes to give to 3 people.
f. You have 5 cubes to give to 3 people.
2. Make a conjecture about how many different ways you could distribute 7 cubes to 4 people. Explain.
3. What if each person were required to get at least one cube? How would your answers change?

Consider the following counting problem:


You have 7 cookies to give to 4 kids. How many ways can you do this?
Take a moment to think about how you might solve this problem. You may assume that it is acceptable to give a kid no cookies.
Also, the cookies are all identical and the order in which you give out the cookies does not matter.
Before solving the problem, here is a wrong answer: You might guess that the answer should be 4 because for each of the 7
7

cookies, there are 4 choices of kids to which you can give the cookie. This is reasonable, but wrong. To see why, consider a few
possible outcomes: we could assign the first six cookies to kid A, and the seventh cookie to kid B. Another outcome would assign
the first cookie to kid B and the six remaining cookies to kid A. Both outcomes are included in the 4 answer. But for our counting
7

problem, both outcomes are really the same – kid A gets six cookies and kid B gets one cookie.
What do outcomes actually look like? How can we represent them? One approach would be to write an outcome as a string of four
numbers like this:
3112,

which represent the outcome in which the first kid gets 3 cookies, the second and third kid each get 1 cookie, and the fourth kid
gets 2 cookies. Represented this way, the order in which the numbers occur matters. 1312 is a different outcome, because the first
kid gets a one cookie instead of 3. Each number in the string can be any integer between 0 and 7. But the answer is not 7 . We need
4

the sum of the numbers to be 7.


Another way we might represent outcomes is to write a string of seven letters:
ABAADCD,

which represents that the first cookie goes to kid A, the second cookie goes to kid B, the third and fourth cookies go to kid A, and
so on. In fact, this outcome is identical to the previous one—A gets 3 cookies, B and C get 1 each and D gets 2. Each of the seven
letters in the string can be any of the 4 possible letters (one for each kid), but the number of such strings is not 4 , because here
7

order does not matter. In fact, another way to write the same outcome is
AAABCDD.

This will be the preferred representation of the outcome. Since we can write the letters in any order, we might as well write them in
alphabetical order for the purposes of counting. So we will write all the A's first, then all the B's, and so on.
Now think about how you could specify such an outcome. All we really need to do is say when to switch from one letter to the
next. In terms of cookies, we need to say after how many cookies do we stop giving cookies to the first kid and start giving cookies
to the second kid. And then after how many do we switch to the third kid? And after how many do we switch to the fourth? So yet
another way to represent an outcome is like this:
∗ ∗ ∗| ∗ | ∗ | ∗ ∗

2.5.1 https://math.libretexts.org/@go/page/32565
Three cookies go to the first kid, then we switch and give one cookie to the second kid, then switch, one to the third kid, switch,
two to the fourth kid. Notice that we need 7 stars and 3 bars – one star for each cookie, and one bar for each switch between kids,
so one fewer bars than there are kids (we don't need to switch after the last kid – we are done).
Why have we done all of this? Simple: to count the number of ways to distribute 7 cookies to 4 kids, all we need to do is count how
many stars and bars charts there are. But a stars and bars chart is just a string of symbols, some stars and some bars. If instead of
stars and bars we would use 0's and 1's, it would just be a bit string. We know how to count those.
Before we get too excited, we should make sure that really any string of (in our case) 7 stars and 3 bars corresponds to a different
way to distribute cookies to kids. In particular consider a string like this:
| ∗ ∗ ∗ || ∗ ∗ ∗ ∗

Does that correspond to a cookie distribution? Yes. It represents the distribution in which kid A gets 0 cookies (because we switch
to kid B before any stars), kid B gets three cookies (three stars before the next bar), kid C gets 0 cookies (no stars before the next
bar) and kid D gets the remaining 4 cookies. No matter how the stars and bars are arranged, we can distribute cookies in that way.
Also, given any way to distribute cookies, we can represent that with a stars and bars chart. For example, the distribution in which
kid A gets 6 cookies and kid B gets 1 cookie has the following chart:
∗ ∗ ∗ ∗ ∗ ∗ | ∗ ||

After all that work we are finally ready to count. Each way to distribute cookies corresponds to a stars and bars chart with 7 stars
and 3 bars. So there are 10 symbols, and we must choose 3 of them to be bars. Thus:
10
There are ( ) ways to distribute 7 cookies to 4 kids.
3

While we are at it, we can also answer a related question: how many ways are there to distribute 7 cookies to 4 kids so that each kid
gets at least one cookie? What can you say about the corresponding stars and bars charts? The charts must start and end with at
least one star (so that kids A and D) get cookies, and also no two bars can be adjacent (so that kids B and C are not skipped). One
way to assure this is to only place bars in the spaces between the stars. With 7 stars, there are 6 spots between the stars, so we must
choose 3 of those 6 spots to fill with bars. Thus there are ( ) ways to distribute 7 cookies to 4 kids giving at least one cookie to
6

each kid.
Another (and more general) way to approach this modified problem is to first give each kid one cookie. Now the remaining 3
cookies can be distributed to the 4 kids without restrictions. So we have 3 stars and 3 bars for a total of 6 symbols, 3 of which must
be bars. So again we see that there are ( ) ways to distribute the cookies.
6

Stars and bars can be used in counting problems other than kids and cookies. Here are a few examples:

Example 2.5.1

Your favorite mathematical pizza chain offers 10 toppings. How many pizzas can you make if you are allowed 6 toppings? The
order of toppings does not matter but now you are allowed repeats. So one possible pizza is triple sausage, double pineapple,
and onions.

Solution
We get 6 toppings (counting possible repeats). Represent each of these toppings as a star. Think of going down the menu
one topping at a time: you see anchovies first, and skip to the next, sausage. You say yes to sausage 3 times (use 3 stars),
then switch to the next topping on the list. You keep skipping until you get to pineapple, which you say yes to twice.
Another switch and you are at onions. You say yes once. Then you keep switching until you get to the last topping, never
saying yes again (since you already have said yes 6 times. There are 10 toppings to choose from, so we must switch from
considering one topping to the next 9 times. These are the bars.
Now that we are confident that we have the right number of stars and bars, we answer the question simply: there are 6 stars
and 9 bars, so 15 symbols. We need to pick 9 of them to be bars, so there number of pizzas possible is

15
( ).
9

2.5.2 https://math.libretexts.org/@go/page/32565
Example 2.5.2

How many 7 digit phone numbers are there in which the digits are non-increasing? That is, every digit is less than or equal to
the previous one.

Solution
We need to decide on 7 digits so we will use 7 stars. The bars will represent a switch from each possible single digit
number down the next smaller one. So the phone number 866-5221 is represented by the stars and bars chart

| ∗ || ∗ ∗| ∗ ||| ∗ ∗| ∗ |

There are 10 choices for each digit (0-9) so we must switch between choices 9 times. We have 7 stars and 9 bars, so the
total number of phone numbers is

16
( ).
9

Example 2.5.3

How many integer solutions are there to the equation


x1 + x2 + x3 + x4 + x5 = 13.

(An integer solution to an equation is a solution in which the unknown must have an integer value.)
1. where x i ≥0 for each x
i?

2. where x i >0 for each x


i?

3. where x i ≥2 for each x


i?

Solution
This problem is just like giving 13 cookies to 5 kids. We need to say how many of the 13 units go to each of the 5 variables.
In other words, we have 13 stars and 4 bars (the bars are like the “+” signs in the equation).
1. If x can be 0 or greater, we are in the standard case with no restrictions. So 13 stars and 4 bars can be arranged in ( )
i
17

ways.
2. Now each variable must be at least 1. So give one unit to each variable to satisfy that restriction. Now there are 8 stars
left, and still 4 bars, so the number of solutions is ( ). 12

3. Now each variable must be 2 or greater. So before any counting, give each variable 2 units. We now have 3 remaining
stars and 4 bars, so there are ( ) solutions.
7

Counting with Functions


Many of the counting problems in this section might at first appear to be examples of counting functions. After all, when we try to
count the number of ways to distribute cookies to kids, we are assigning each cookie to a kid, just like you assign elements of the
domain of a function to elements in the codomain. However, the number of ways to assign 7 cookies to 4 kids is ( ) = 120, while10

the number of functions f : {1, 2, 3, 4, 5, 6, 7} → {a, b, c, d}is 4 = 16384. What is going on here?
7

When we count functions, we consider the following two functions, for example, to be different:
1 2 3 4 5 6 7 1 2 3 4 5 6 7
f =( ) g =( ). (2.5.1)
a b c c c c c b a c c c c c

But these two functions would correspond to the same cookie distribution: kids a and b each get one cookie, kid c gets the rest (and
none for kid d ).
The point: elements of the domain are distinguished, cookies are indistinguishable. This is analogous to the distinction between
permutations (like counting functions) and combinations (not).

2.5.3 https://math.libretexts.org/@go/page/32565
Contributors and Attributions
Oscar Levin (School of Mathematical Science, University of Northern Colorado)

This page titled 2.5: Stars and Bars is shared under a CC BY-SA license and was authored, remixed, and/or curated by Oscar Levin.
1.5: Stars and Bars by Oscar Levin is licensed CC BY-SA 4.0.

2.5.4 https://math.libretexts.org/@go/page/32565
2.6: Advanced Counting Using PIE
Investigate!
You have 11 identical mini key-lime pies to give to 4 children. However, you don't want any kid to get more than 3 pies. How
many ways can you distribute the pies?
1. How many ways are there to distribute the pies without any restriction?
2. Let's get rid of the ways that one or more kid gets too many pies. How many ways are there to distribute the pies if Al gets
too many pies? What if Bruce gets too many? Or Cat? Or Dent?
3. What if two kids get too many pies? How many ways can this happen? Does it matter which two kids you pick to overfeed?
4. Is it possible that three kids get too many pies? If so, how many ways can this happen?
5. How should you combine all the numbers you found above to answer the original question?
Suppose now you have 13 pies and 7 children. No child can have more than 2 pies. How many ways can you distribute the
pies?

Stars and bars allows us to count the number of ways to distribute 10 cookies to 3 kids and natural number solutions to
x + y + z = 11, for example. A relatively easy modification allows us to put a lower bound restriction on these problems: perhaps

each kid must get at least two cookies or x, y, z ≥ 2. This was done by first assigning each kid (or variable) 2 cookies (or units)
and then distributing the rest using stars and bars.
What if we wanted an upper bound restriction? For example, we might insist that no kid gets more than 4 cookies or that
x, y, z ≤ 4. It turns out this is considerably harder, but still possible. The idea is to count all the distributions and then remove those

that violate the condition. In other words, we must count the number of ways to distribute 11 cookies to 3 kids in which one or
more of the kids gets more than 4 cookies. For any particular kid, this is not a problem; we do this using stars and bars. But how to
combine the number of ways for kid A, or B or C? We must use the PIE.
The Principle of Inclusion/Exclusion (PIE) gives a method for finding the cardinality of the union of not necessarily disjoint sets.
We saw in Subsection how this works with three sets. To find how many things are in one or more of the sets A, B, and C , we
should just add up the number of things in each of these sets. However, if there is any overlap among the sets, those elements are
counted multiple times. So we subtract the things in each intersection of a pair of sets. But doing this removes elements which are
in all three sets once too often, so we need to add it back in. In terms of cardinality of sets, we have
|A ∪ B ∪ C | = |A| + |B| + |C | − |A ∩ B| − |A ∩ C | − |B ∩ C | + |A ∩ B ∩ C |.

Example 2.6.1:

Three kids, Alberto, Bernadette, and Carlos, decide to share 11 cookies. They wonder how many ways they could split the
cookies up provided that none of them receive more than 4 cookies (someone receiving no cookies is for some reason
acceptable to these kids).

Solution
Without the “no more than 4” restriction, the answer would be ( ), using 11 stars and 2 bars (separating the three kids).
13

Now count the number of ways that one or more of the kids violates the condition, i.e., gets at least 4 cookies.
Let A be the set of outcomes in which Alberto gets more than 4 cookies. Let B be the set of outcomes in which Bernadette
gets more than 4 cookies. Let C be the set of outcomes in which Carlos gets more than 4 cookies. We then are looking (for
the sake of subtraction) for the size of the set A ∪ B ∪ C . Using PIE, we must find the sizes of |A|, |B|, |C |, |A ∩ B| and
so on. Here is what we find.
8
|A| = ( ).
2
First give Alberto 5 cookies, then distribute the remaining 6 to the three kids without restrictions, using 6 stars
and 2 bars.
8
|B| = ( ).
2
Just like above, only now Bernadette gets 5 cookies at the start.
|C | = ( ). Carlos gets 5 cookies first.
8

|A ∩ B| = ( ). Give Alberto and Bernadette 5 cookies each, leaving 1 (star) to distribute to the three kids (2 bars).
3

|A ∩ C | = ( ). Alberto and Carlos get 5 cookies first.


3

2.6.1 https://math.libretexts.org/@go/page/32566
3
|B ∩ C | = ( ).
2
Bernadette and Carlos get 5 cookies first.
|A ∩ B ∩ C | = 0. It is not possible for all three kids to get 4 or more cookies.

Combining all of these we see


8 8 8 3 3 3
|A ∪ B ∪ C | = ( ) + ( ) + ( ) − ( ) − ( ) − ( ) + 0 = 75.
2 2 2 2 2 2

Thus the answer to the original question is ( ) − 75 = 78 − 75 = 3. This makes sense now that we see it. The only way
13

to ensure that no kid gets more than 4 cookies is to give two kids 4 cookies and one kid 3; there are three choices for which
kid that should be. We could have found the answer much quicker through this observation, but the point of the example is
to illustrate that PIE works!

For four or more sets, we do not write down a formula for PIE. Instead, we just think of the principle: add up all the elements in
single sets, then subtract out things you counted twice (elements in the intersection of a pair of sets), then add back in elements you
removed too often (elements in the intersection of groups of three sets), then take back out elements you added back in too often
(elements in the intersection of groups of four sets), then add back in, take back out, add back in, etc. This would be very difficult if
it wasn't for the fact that in these problems, all the cardinalities of the single sets are equal, as are all the cardinalities of the
intersections of two sets, and that of three sets, and so on. Thus we can group all of these together and multiply by how many
different combinations of 1, 2, 3, … sets there are.

Example 2.6.2

How many ways can you distribute 10 cookies to 4 kids so that no kid gets more than 2 cookies?

Solution
There are ( ) ways to distribute 10 cookies to 4 kids (using 10 stars and 3 bars). We will subtract all the outcomes in
13

which a kid gets 3 or more cookies. How many outcomes are there like that? We can force kid A to eat 3 or more cookies
by giving him 3 cookies before we start. Doing so reduces the problem to one in which we have 7 cookies to give to 4 kids
without any restrictions. In that case, we have 7 stars (the 7 remaining cookies) and 3 bars (one less than the number of
kids) so we can distribute the cookies in ( ) ways. Of course we could choose any one of the 4 kids to give too many
10

cookies, so it would appear that there are ( )( ) ways to distribute the cookies giving too many to one kid. But in fact, we
4

1
10

have over counted.


We must get rid of the outcomes in which two kids have too many cookies. There are ( ) ways to select 2 kids to give extra
4

cookies. It takes 6 cookies to do this, leaving only 4 cookies. So we have 4 stars and still 3 bars. The remaining 4 cookies
can thus be distributed in ( ) ways (for each of the ( ) choices of which 2 kids to over-feed).
7

3
4

But now we have removed too much. We must add back in all the ways to give too many cookies to three kids. This uses 9
cookies, leaving only 1 to distribute to the 4 kids using stars and bars, which can be done in ( ) ways. We must consider
4

this outcome for every possible choice of which three kids we over-feed, and there are ( ) ways of selecting that set of 3
4

kids.
Next we would subtract all the ways to give four kids too many cookies, but in this case, that number is 0.
All together we get that the number of ways to distribute 10 cookies to 4 kids without giving any kid more than 2 cookies
is:
13 4 10 4 7 4 4
( ) − [( )( ) − ( )( ) + ( )( )]
3 1 3 2 3 3 3

which is

286 − [480 − 210 + 16] = 0.

This makes sense: there is NO way to distribute 10 cookies to 4 kids and make sure that nobody gets more than 2. It is

2.6.2 https://math.libretexts.org/@go/page/32566
slightly surprising that
13 4 10 4 7 4 4
( ) = [( )( ) − ( )( ) + ( )( )]
3 1 3 2 3 3 3

but since PIE works, this equality must hold.

Just so you don't think that these problems always have easier solutions, consider the following example.

Example 2.6.3

Earlier (Example 1.5.3) we counted the number of solutions to the equation


x1 + x2 + x3 + x4 + x5 = 13

where x i ≥0 for each x


i.

How many of those solutions have 0 ≤ x i ≤3 for each x i?

Solution
We must subtract off the number of solutions in which one or more of the variables has a value greater than 3. We will need
to use PIE because counting the number of solutions for which each of the five variables separately are greater than 3
counts solutions multiple times. Here is what we get:
Total solutions: ( 17

4
).

Solutions where x 1 > 3: (


13

4
Give x 4 units first, then distribute the remaining 9 units to the 5 variables.
). 1

Solutions where x 1 >3 and x > 3: ( ). After you give 4 units to x and another 4 to x , you only have 5 units left to
2
9

4 1 2

distribute.
Solutions where x 1 > 3, x2 > 3 and x 3
5
> 3: ( ).
4

Solutions where x 1 > 3, x2 > 3, x3 > 3, and x 4 > 3: 0.


We also need to account for the fact that we could choose any of the five variables in the place of x above (so there will be
1

( ) outcomes like this), any pair of variables in the place of x and x (( ) outcomes) and so on. It is because of this that
5 5
1 2
1 2

the double counting occurs, so we need to use PIE. All together we have that the number of solutions with 0 ≤ x ≤ 3 is i

17 5 13 5 9 5 5
( ) − [( )( ) − ( )( ) + ( )( )] = 15.
4 1 4 2 4 3 4

Counting Derangements
Investigate!

For your senior prank, you decide to switch the nameplates on your favorite 5 professors' doors. So that none of them feel left
out, you want to make sure that all of the nameplates end up on the wrong door. How many ways can this be accomplished?

The advanced use of PIE has applications beyond stars and bars. A derangement of n elements {1, 2, 3, … , n} is a permutation in
which no element is fixed. For example, there are 6 permutations of the three elements {1, 2, 3}:

123 132 213 231 312 321.

but most of these have one or more elements fixed: 123 has all three elements fixed since all three elements are in their original
positions, 132 has the first element fixed (1 is in its original first position), and so on. In fact, the only derangements of three
elements are

231 and 312.

If we go up to 4 elements, there are 24 permutations (because we have 4 choices for the first element, 3 choices for the second, 2
choices for the third leaving only 1 choice for the last). How many of these are derangements? If you list out all 24 permutations

2.6.3 https://math.libretexts.org/@go/page/32566
and eliminate those which are not derangements, you will be left with just 9 derangements. Let's see how we can get that number
using PIE.

Example 2.6.4

How many derangements are there of 4 elements?

Solution
We count all permutations, and subtract those which are not derangements. There are 4! = 24 permutations of 4 elements.
Now for a permutation to not be a derangement, at least one of the 4 elements must be fixed. There are ( ) choices for
4

which single element we fix. Once fixed, we need to find a permutation of the other three elements. There are 3!
permutations on 3 elements. But now we have counted too many non-derangements, so we must subtract those
permutations which fix two elements. There are ( ) choices for which two elements we fix, and then for each pair, 2!
4

permutations of the remaining elements. But this subtracts too many, so add back in permutations which fix 3 elements, all
( )1! of them. Finally subtract the ( )0! permutations (recall 0! = 1 ) which fix all four elements. All together we get that
4 4

3 4

the number of derangements of 4 elements is:


4 4 4 4
4! − [( )3! − ( )2! + ( )1! − ( )0!] = 24 − 15 = 9.
1 2 3 4

Of course we can use a similar formula to count the derangements of any number of elements. However, the more elements we
have, the longer the formula gets. Here is another example:

Example 2.6.5

Five gentlemen attend a party, leaving their hats at the door. At the end of the party, they hastily grab hats on their way out.
How many different ways could this happen so that none of the gentlemen leave with their own hat?

Solution
We are counting derangements on 5 elements. There are 5! ways for the gentlemen to grab hats in any order—but many of
these permutations will result in someone getting their own hat. So we subtract all the ways in which one or more of the
men get their own hat. In other words, we subtract the non-derangements. Doing so requires PIE. Thus the answer is:
5 5 5 5 5
5! − [( )4! − ( )3! + ( )2! − ( )1! + ( )0!] .
1 2 3 4 5

Counting Functions
Investigate!
Consider all functions f : {1, 2, 3, 4, 5} → {1, 2, 3, 4, 5}.How many functions are there all together? How many of those
are injective? Remember, a function is an injection if every input goes to a different output.
Consider all functions f : {1, 2, 3, 4, 5} → {1, 2, 3, 4, 5}.How many of the injections have the property that f (x) ≠ x for
any x ∈ {1, 2, 3, 4, 5}? Your friend claims that the answer is:
5 5 5 5 5
5! − [( )4! − ( )3! + ( )2! − ( )1! + ( )0!] .
1 2 3 4 5

Explain why this is correct.


Recall that a surjection is a function for which every element of the codomain is in the range. How many of the functions
f : {1, 2, 3, 4, 5} → {1, 2, 3, 4, 5}are surjective? Use PIE!

We have seen throughout this chapter that many counting questions can be rephrased as questions about counting functions with
certain properties. This is reasonable since many counting questions can be thought of as counting the number of ways to assign
elements from one set to elements of another.

2.6.4 https://math.libretexts.org/@go/page/32566
Example 2.6.6

You decide to give away your video game collection so to better spend your time studying advance mathematics. How many
ways can you do this, provided:
1. You want to distribute your 3 different PS4 games among 5 friends, so that no friend gets more than one game?
2. You want to distribute your 8 different 3DS games among 5 friends?
3. You want to distribute your 8 different SNES games among 5 friends, so that each friend gets at least one game?
In each case, model the counting question as a function counting question.

Solution
We must use the three games (call them 1, 2, 3) as the domain and the 5 friends (a,b,c,d,e) as the codomain (otherwise the
function would not be defined for the whole domain when a friend didn't get any game). So how many functions are there
with domain {1, 2, 3}and codomain {a, b, c, d, e}? The answer to this is 5 = 125, since we can assign any of 5 elements
3

to be the image of 1, any of 5 elements to be the image of 2 and any of 5 elements to be the image of 3.
1 2 3
But this is not the correct answer to our counting problem, because one of these functions is f =( ); one friend
a a a

can get more than one game. What we really need to do is count injective functions. This gives P (5, 3) = 60 functions,
which is the answer to our counting question.
Again, we need to use the 8 games as the domain and the 5 friends as the codomain. We are counting all functions, so the
number of ways to distribute the games is 5 .
8

This question is harder. Use the games as the domain and friends as the codomain (otherwise an element of the domain
would have more than one image, which is impossible). To ensure that every friend gets at least one game means that every
element of the codomain is in the range. In other words, we are looking for surjective functions. How do you count those?

In Example 1.1.5 we saw how to count all functions (using the multiplicative principle) and in Example 1.3.4 we learned how to
count injective functions (using permutations). Surjective functions are not as easily counted (unless the size of the domain is
smaller than the codomain, in which case there are none).
The idea is to count the functions which are not surjective, and then subtract that from the total number of functions. This works
very well when the codomain has two elements in it:

Example 2.6.7

How many functions f : {1, 2, 3, 4, 5} → {a, b} are surjective?

Solution
There are 2 functions all together, two choices for where to send each of the 5 elements of the domain. Now of these, the
5

functions which are not surjective must exclude one or more elements of the codomain from the range. So first, consider
functions for which a is not in the range. This can only happen one way: everything gets sent to b. Alternatively, we could
exclude b from the range. Then everything gets sent to a, so there is only one function like this. These are the only ways in
which a function could not be surjective (no function excludes both a and b from the range) so there are exactly 2 − 2 5

surjective functions.

When there are three elements in the codomain, there are now three choices for a single element to exclude from the range.
Additionally, we could pick pairs of two elements to exclude from the range, and we must make sure we don't over count these. It's
PIE time!

Example 2.6.8

How many functions f : {1, 2, 3, 4, 5} → {a, b, c} are surjective?

Solution

2.6.5 https://math.libretexts.org/@go/page/32566
Again start with the total number of functions: 3 (as each of the five elements of the domain can go to any of three
5

elements of the codomain). Now we count the functions which are not surjective.
Start by excluding a from the range. Then we have two choices (b or c) for where to send each of the five elements of the
domain. Thus there are 2 functions which exclude a from the range. Similarly, there are 2 functions which exclude b, and
5 5

another 2 which exclude c. Now have we counted all functions which are not surjective? Yes, but in fact, we have counted
5

some multiple times. For example, the function which sends everything to c was one of the 2 functions we counted when
5

we excluded a from the range, and also one of the 2 functions we counted when we excluded b from the range. We must
5

subtract out all the functions which specifically exclude two elements from the range. There is 1 function when we exclude
a and b (everything goes to c ), one function when we exclude a and c, and one function when we exclude b and c.

We are using PIE: to count the functions which are not surjective, we added up the functions which exclude a, b, and c
separately, then subtracted the functions which exclude pairs of elements. We would then add back in the functions which
exclude groups of three elements, except that there are no such functions. We find that the number of functions which are
not surjective is
5 5 5
2 +2 +2 − 1 − 1 − 1 + 0.

Perhaps a more descriptive way to write this is


3 3 3
5 5 5
( )2 − ( )1 + ( )0 .
1 2 3

since each of the 2 's was the result of choosing 1 of the 3 elements of the codomain to exclude from the range, each of the
5

three 1 's was the result of choosing 2 of the 3 elements of the codomain to exclude. Writing 1 instead of 1 makes sense
5 5

too: we have 1 choice of were to send each of the 5 elements of the domain.
Now we can finally count the number of surjective functions:
3 3
5 5 5
3 − [( ) 2 − ( ) 1 ] = 150.
1 2

You might worry that to count surjective functions when the codomain is larger than 3 elements would be too tedious. We need to
use PIE but with more than 3 sets the formula for PIE is very long. However, we have lucked out. As we saw in the example above,
the number of functions which exclude a single element from the range is the same no matter which single element is excluded.
Similarly, the number of functions which exclude a pair of elements will be the same for every pair. With larger codomains, we will
see the same behavior with groups of 3, 4, and more elements excluded. So instead of adding/subtracting each of these, we can
simply add or subtract all of them at once, if you know how many there are. This works just like it did in for the other types of
counting questions in this section, only now the size of the various combinations of sets is a number raised to a power, as opposed
to a binomial coefficient or factorial. Here's what happens with 4 and 5 elements in the codomain.

Example 2.6.9
1. How many functions f : {1, 2, 3, 4, 5} → {a, b, c, d} are surjective?
2. How many functions f : {1, 2, 3, 4, 5} → {a, b, c, d, e} are surjective?

Solution
There are 4 functions all together; we will subtract the functions which are not surjective. We could exclude any one of the
5

four elements of the codomain, and doing so will leave us with 3 functions for each excluded element. This counts too
5

many so we subtract the functions which exclude two of the four elements of the codomain, each pair giving 2 functions. 5

But this excludes too many, so we add back in the functions which exclude three of the four elements of the codomain, each
triple giving 1 function. There are ( ) groups of functions excluding a single element, ( ) groups of functions excluding a
5 4

1
4

pair of elements, and ( ) groups of functions excluding a triple of elements. This means that the number of functions which
4

are not surjective is:


4 4 4
5 5 5
( )3 − ( )2 + ( )1 .
1 2 3

2.6.6 https://math.libretexts.org/@go/page/32566
We can now say that the number of functions which are surjective is:
4 4 4
5 5 5 5
4 − [( )3 − ( )2 + ( )1 ] .
1 2 3

The number of surjective functions is:

5
5 5
5 5
5 5
5 5
5 − [( )4 − ( )3 + ( )2 − ( )1 ] .
1 2 3 4

We took the total number of functions 5 and subtracted all that were not surjective. There were ( ) ways to select a single
5 5

element from the codomain to exclude from the range, and for each there were 4 functions. But this double counts, so we
5

use PIE and subtract functions excluding two elements from the range: there are ( ) choices for the two elements to
5

exclude, and for each pair, 3 functions. This takes out too many functions, so we add back in functions which exclude 3
5

elements from the range: ( ) choices for which three to exclude, and then 2 functions for each choice of elements. Finally
5

3
5

we take back out the 1 function which excludes 4 elements for each of the ( ) choices of 4 elements.
5

If you happen to calculate this number precisely, you will get 120 surjections. That happens to also be the value of 5!. This
might seem like an amazing coincidence until you realize that every surjective function f : X → Y with |X| = |Y | finite
must necessarily be a bijection. The number of bijections is always |X|! in this case. What we have here is a combinatorial
proof of the following identity:
n n n
n n n n
n − [( )(n − 1 ) − ( )(n − 2 ) + ⋯ + ( ) 1 ] = n!.
1 2 n−1

We have seen that counting surjective functions is another nice example of the advanced use of the Principle of
Inclusion/Exclusion. Also, counting injective functions turns out to be equivalent to permutations, and counting all functions has a
solution akin to those counting problems where order matters but repeats are allowed (like counting the number of words you can
make from a given set of letters).
These are not just a few more examples of the techniques we have developed in this chapter. Quite the opposite: everything we
have learned in this chapter are examples of counting functions!

Example 2.6.10

How many 5-letter words can you make using the eight letters a through h? How many contain no repeated letters?

Solution
By now it should be no surprise that there are 8 words, and P (8, 5) words without repeated letters. The new piece here is
5

that we are actually counting functions. For the first problem, we are counting all functions from {1, 2, … , 5} to
{a, b, … , h}. The numbers in the domain represent the position of the letter in the word, the codomain represents the letter

that could be assigned to that position. If we ask for no repeated letters, we are asking for injective functions.
If A and B are any sets with |A| = 5 and |B| = 8, then the number of functions f : A → B is 8 and the number of
5

injections is P (8, 5). So if you can represent your counting problem as a function counting problem, most of the work is
done.

Example 2.6.11

How many subsets are there of {1, 2, … , 9}?How many 9-bit strings are there (of any weight)?

Solution
We saw in Section 1.2 that the answer to both these questions is 2 , as we can say yes or no (or 0 or 1) to each of the 9
9

elements in the set (positions in the bit-string). But 2 also looks like the answer you get from counting functions. In fact, if
9

you count all functions f : A → B with |A| = 9 and |B| = 2, this is exactly what you get.

2.6.7 https://math.libretexts.org/@go/page/32566
This makes sense! Let A = {1, 2, … , 9} and B = {y, n}. We are assigning each element of the set either a yes or a no. Or
in the language of bit-strings, we would take the 9 positions in the bit string as our domain and the set {0, 1} as the
codomain.

So far we have not used a function as a model for binomial coefficients (combinations). Think for a moment about the relationship
between combinations and permutations, say specifically ( ) and P (9, 3). We do have a function model for P (9, 3). This is the
9

number of injective functions from a set of size 3 (say {1, 2, 3} to a set of size 9 (say {1, 2, … , 9}) since there are 9 choices for
where to send the first element of the domain, then only 8 choices for the second, and 7 choices for the third. For example, the
function might look like this:

f (1) = 5 f (2) = 8 f (3) = 4.

This is a different function from:

f (1) = 4 f (2) = 5 f (3) = 8.

Now P (9, 3) counts these as different outcomes correctly, but ( ) will count these (among others) as just one outcome. In fact, in
9

terms of functions ( ) just counts the number of different ranges possible of injective functions. This should not be a surprise since
9

binomial coefficients counts subsets, and the range is a possible subset of the codomain. 4 A more mathematically sophisticated
interpretation of combinations is that we are defining two injective functions to be equivalent if they have the same range, and then
counting the number of equivalence classes under this notion of equivalence.
While it is possible to interpret combinations as functions, perhaps the better advice is to instead use combinations (or stars and
bars) when functions are not quite the right way to interpret the counting question.

This page titled 2.6: Advanced Counting Using PIE is shared under a CC BY-SA license and was authored, remixed, and/or curated by Oscar
Levin.
1.6: Advanced Counting Using PIE by Oscar Levin is licensed CC BY-SA 4.0.

2.6.8 https://math.libretexts.org/@go/page/32566
2.E: Counting (Exercises)
1.1: Additive and Multiplicative Principles
1
Your wardrobe consists of 5 shirts, 3 pairs of pants, and 17 bow ties. How many different outfits can you make?

Answer
There are 255 outfits. Use the multiplicative principle.

2
For your college interview, you must wear a tie. You own 3 regular (boring) ties and 5 (cool) bow ties.
a. How many choices do you have for your neck-wear?
b. You realize that the interview is for clown college, so you should probably wear both a regular tie and a bow tie. How many
choices do you have now?
c. For the rest of your outfit, you have 5 shirts, 4 skirts, 3 pants, and 7 dresses. You want to select either a shirt to wear with a skirt
or pants, or just a dress. How many outfits do you have to choose from?

Answer
a. 8 ties. Use the additive principle.
b. 15 ties. Use the multiplicative principle
c. 5 ⋅ (4 + 3) + 7 = 42 outfits.

3
Your Blu-ray collection consists of 9 comedies and 7 horror movies. Give an example of a question for which the answer is:
a. 16.
b. 63.

Answer
a. For example, 16 is the number of choices you have if you want to watch one movie, either a comedy or horror flick.
b. For example, 63 is the number of choices you have if you will watch two movies, first a comedy and then a horror.

4
We usually write numbers in decimal form (or base 10), meaning numbers are composed using 10 different “digits” {0, 1, … , 9}.
Sometimes though it is useful to write numbers hexadecimal or base 16. Now there are 16 distinct digits that can be used to form
numbers: {0, 1, … , 9, A, B, C, D, E, F}.So for example, a 3 digit hexadecimal number might be 2B8.
a. How many 2-digit hexadecimals are there in which the first digit is E or F? Explain your answer in terms of the additive
principle (using either events or sets).
b. Explain why your answer to the previous part is correct in terms of the multiplicative principle (using either events or sets).
Why do both the additive and multiplicative principles give you the same answer?
c. How many 3-digit hexadecimals start with a letter (A-F) and end with a numeral (0-9)? Explain.
d. How many 3-digit hexadecimals start with a letter (A-F) or end with a numeral (0-9) (or both)? Explain.

5
Suppose you have sets A and B with |A| = 10 and |B| = 15.
a. What is the largest possible value for |A ∩ B| ?
b. What is the smallest possible value for |A ∩ B| ?
c. What are the possible values for |A ∪ B| ?

Answer
a. To maximize the number of elements in common between A and B, make A ⊂ B. This would give |A ∩ B| = 10.

2.E.1 https://math.libretexts.org/@go/page/32567
b. A and B might have no elements in common, giving |A ∩ B| = 0.
c. 15 ≤ |A ∪ B| ≤ 25. In fact, when |A ∩ B| = 0 then |A ∪ B| = 25 and when |A ∩ B| = 10 then |A ∪ B| = 15.

6
If |A| = 8 and |B| = 5, what is |A ∪ B| + |A ∩ B| ?

Answer
|A ∪ B| + |A ∩ B| = 13. Use PIE: we know |A ∪ B| = 8 + 5 − |A ∩ B| .

7
A group of college students were asked about their TV watching habits. Of those surveyed, 28 students watch The Walking Dead,
19 watch The Blacklist, and 24 watch Game of Thrones. Additionally, 16 watch The Walking Dead and The Blacklist, 14 watch The
Walking Dead and Game of Thrones, and 10 watch The Blacklist and Game of Thrones. There are 8 students who watch all three
shows. How many students surveyed watched at least one of the shows?

Answer
39 students. Use PIE or a Venn diagram.

8
In a recent survey, 30 students reported whether they liked their potatoes Mashed, French-fried, or Twice-baked. 15 liked them
mashed, 20 liked French fries, and 9 liked twice baked potatoes. Additionally, 12 students liked both mashed and fried potatoes, 5
liked French fries and twice baked potatoes, 6 liked mashed and baked, and 3 liked all three styles. How many students hate
potatoes? Explain why your answer is correct.

9
For how many n ∈ {1, 2, … , 500} is n a multiple of one or more of 5, 6, or 7?

Hint:
To find out how many numbers are divisible by 6 and 7, for example, take 500/42and round down.

10
Let A, B, and C be sets.
a. Find |(A ∪ C ) ∖ B| provided |A| = 50, |B| = 45, |C | = 40, |A ∩ B| = 20, |A ∩ C | = 15, |B ∩ C | = 23, and
|A ∩ B ∩ C | = 12.

b. Describe a set in terms of A, B, and C with cardinality 26.

11
Consider all 5 letter “words” made from the letters a through h. (Recall, words are just strings of letters, not necessarily actual
English words.)
a. How many of these words are there total?
b. How many of these words contain no repeated letters?
c. How many of these words start with the sub-word “aha”?
d. How many of these words either start with “aha” or end with “bah” or both?
e. How many of the words containing no repeats also do not contain the sub-word “bad”?

Answer
a. 8
5
= 32768 words, since you select from 8 letters 5 times.
b. 8 ⋅ 7 ⋅ 6 ⋅ 5 ⋅ 4 = 6720 words. After selecting a letter, you have fewer letters to select for the next one.

c. 8 ⋅ 8 = 64 words: you need to select the 4th and 5th letters.

d. 64 + 64 − 0 = 128 words. There are 64 words which start with “aha” and another 64 words that end with “bah.” Perhaps

we over counted the words that both start with “aha” and end with “bah”, but since the words are only 5 letters long, there
are no such words.

2.E.2 https://math.libretexts.org/@go/page/32567
e. (8 ⋅ 7 ⋅ 6 ⋅ 5 ⋅ 4) − 3 ⋅ (5 ⋅ 4) = 6660 words. All the words minus the bad ones. The taboo word can be in any of three
positions (starting with letter 1, 2, or 3) and for each position we must choose the other two letters (from the remaining 5
letters).

12
For how many three digit numbers (100 to 999) is the sum of the digits even? (For example, 343 has an even sum of digits:
3 + 4 + 3 = 10 which is even.) Find the answer and explain why it is correct in at least two different ways.

13
The number 735000 factors as 2
3
⋅3⋅5
4 2
⋅7 . How many divisors does it have? Explain your answer using the multiplicative
principle.

1.2: Binomial Coefficients


1
Let S = {1, 2, 3, 4, 5, 6}
a. How many subsets are there total?
b. How many subsets have {2, 3, 5} as a subset?
c. How many subsets contain at least one odd number?
d. How many subsets contain exactly one even number?

Answer
a. 2
6
subsets. We need to select yes/no for each of the six elements.
= 64

b. 2
3
subsets. We need to select yes/no for each of the remaining three elements.
=8

c. 2 − 2 = 56 subsets. There are 8 subsets which do not contain any odd numbers (select yes/no for each even number).
6 3

d. 3 ⋅ 2 = 24 subsets. First pick the even number. Then say yes or no to each of the odd numbers.
3

2
Let S = {1, 2, 3, 4, 5, 6}
a. How many subsets are there of cardinality 4?
b. How many subsets of cardinality 4 have {2, 3, 5} as a subset?
c. How many subsets of cardinality 4 contain at least one odd number?
d. How many subsets of cardinality 4 contain exactly one even number?

Answer
a. 6
( ) = 15
4
subsets.
b. (
3

1
) = 3 subsets. We need to select 1 of the 3 remaining elements to be in the subset.

c. (
6

4
) = 15 subsets. All subsets of cardinality 4 must contain at least one odd number.

d. (
3

1
) = 3 subsets. Select 1 of the 3 even numbers. The remaining three odd numbers of S must all be in the set.

3
Let A = {1, 2, 3, … , 9}.
a. How many subsets of A are there? That is, find |P(A)|. Explain.
b. How many subsets of A contain exactly 5 elements? Explain.
c. How many subsets of A contain only even numbers? Explain.
d. How many subsets of A contain an even number of elements? Explain.

4
How many 9-bit strings (that is, bit strings of length 9) are there which:
a. Start with the sub-string 101? Explain.
b. Have weight 5 (i.e., contain exactly five 1's) and start with the sub-string 101? Explain.

2.E.3 https://math.libretexts.org/@go/page/32567
c. Either start with 101 or end with 11 (or both)? Explain.
d. Have weight 5 and either start with 101 or end with 11 (or both)? Explain.

5
You break your piggy-bank to discover lots of pennies and nickels. You start arranging these in rows of 6 coins.
a. You find yourself making rows containing an equal number of pennies and nickels. For fun, you decide to lay out every possible
such row. How many coins will you need?
b. How many coins would you need to make all possible rows of 6 coins (not necessarily with equal number of pennies and
nickels)?

Answer
a. We can think of each row as a 6-bit string of weight 3 (since of the 6 coins, we require 3 to be pennies). Thus there are
( ) = 20 rows possible. Each row requires 6 coins, so if we want to make all the rows at the same time, we will need 120
6

coins (60 of each).


b. Now there are 2 = 64 rows possible, which is also ( ) + ( ) + ( ) + ( ) + ( ) + ( ) + ( ),
6 6

0
6

1
6

2
if you break them up into
6

3
6

4
6

5
6

rows containing 0, 1, 2, etc. pennies. Thus we need 6 ⋅ 64 = 384 coins (192 of each).

6
How many 10-bit strings contain 6 or more 1's?

Answer
(
10

6
)+(
10

7
)+(
10

8
)+(
10

9
)+(
10
) = 386
10
strings. Count the number of strings with each permissible number of 1's separately,
then add them up.

7
How many subsets of {0, 1, … , 9} have cardinality 6 or more?

Hint:
Break the question into five cases.

8
What is the coefficient of x 12
in (x + 2)
15
?

Answer
To get an x , we must pick 12 of the 15 factors to contribute an x, leaving the other 3 to contribute a 2. There are ( ) ways to
12 15

12

select these 12 factors. So the term containing an x will be ( )x 2 . In other words, the coefficient of x
12 15

12
12 3
is 12

15 3
( )2 = 3640.
12

9
What is the coefficient of x in the expansion of (x + 1)
9 14 3
+ x (x + 2 )
15
?

10
How many shortest lattice paths start at (3,3) and
a. end at (10,10)?
b. end at (10,10) and pass through (5,7)?
c. end at (10,10) and avoid (5,7)?

Answer
a. (
14

7
) = 3432 paths. The paths all have length 14 (7 steps up and 7 steps right), we just select which 7 of those 14 should be
up.
b. 6

2
8
( )( ) = 840
5
paths. First travel to (5,7), and then continue on to (10,10).

2.E.4 https://math.libretexts.org/@go/page/32567
c. (
14

7
6
) − ( )( )
2
8

5
paths. Remove all the paths that you found in part (b).

11
Gridtown USA, besides having excellent donut shoppes, is known for its precisely laid out grid of streets and avenues. Streets run
east-west, and avenues north-south, for the entire stretch of the town, never curving and never interrupted by parks or schools or the
like.
Suppose you live on the corner of 1st and 1st and work on the corner of 12th and 12th. Thus you must travel 22 blocks to get to
work as quickly as possible.
a. How many different routes can you take to work, assuming you want to get there as quickly as possible?
b. Now suppose you want to stop and get a donut on the way to work, from your favorite donut shoppe on the corner of 8th st and
10th ave. How many routes to work, via the donut shoppe, can you take (again, ensuring the shortest possible route)?
c. Disaster Strikes Gridtown: there is a pothole on 4th avenue between 5th and 6th street. How many routes to work can you take
avoiding that unsightly (and dangerous) stretch of road?
d. How many routes are there both avoiding the pothole and visiting the donut shoppe?

12
Suppose you are ordering a large pizza from D.P. Dough. You want 3 distinct toppings, chosen from their list of 11 vegetarian
toppings.
a. How many choices do you have for your pizza?
b. How many choices do you have for your pizza if you refuse to have pineapple as one of your toppings?
c. How many choices do you have for your pizza if you insist on having pineapple as one of your toppings?
d. How do the three questions above relate to each other?

13
Explain why the coefficient of x 5
y
3
the same as the coefficient of x
3
y
5
in the expansion of (x + y )
8
?

1.3: Combinations and Permutations


1
A pizza parlor offers 10 toppings.
a. How many 3-topping pizzas could they put on their menu? Assume double toppings are not allowed.
b. How many total pizzas are possible, with between zero and ten toppings (but not double toppings) allowed?
c. The pizza parlor will list the 10 toppings in two equal-sized columns on their menu. How many ways can they arrange the
toppings in the left column?

Answer
a. (
10

3
pizzas. We must choose (in no particular order) 3 out of the 10 toppings.
) = 120

b. 2
10
pizzas. Say yes or no to each topping.
= 1024

c. P (10, 5) = 30240ways. Assign each of the 5 spots in the left column to a unique pizza topping.

2
A combination lock consists of a dial with 40 numbers on it. To open the lock, you turn the dial to the right until you reach a first
number, then to the left until you get to second number, then to the right again to the third number. The numbers must be distinct.
How many different combinations are possible?

Answer
Despite its name, we are not looking for a combination here. The order in which the three numbers appears matters. There are
P (40, 3) = 40 ⋅ 39 ⋅ 38 different possibilities for the “combination”. This is assuming you cannot repeat any of the numbers (if

you could, the answer would be 40 ). 3

2.E.5 https://math.libretexts.org/@go/page/32567
3
Using the digits 2 through 8, find the number of different 5-digit numbers such that:
a. Digits can be used more than once.
b. Digits cannot be repeated, but can come in any order.
c. Digits cannot be repeated and must be written in increasing order.
d. Which of the above counting questions is a combination and which is a permutation? Explain why this makes sense.

4
How many triangles are there with vertices from the points shown below? Note, we are not allowing degenerate triangles - ones
with all three vertices on the same line, but we do allow non-right triangles. Explain why your answer is correct.

Hint:
You need exactly two points on either the x - or y-axis, but don't over-count the right triangles.

5
How many quadrilaterals can you draw using the dots below as vertices (corners)?

Answer
7 7
( )( ) = 441
2 2
quadrilaterals. We must pick two of the seven dots from the top row and two of the seven dots on the bottom row.
However, it does not make a difference which of the two (on each row) we pick first because once these four dots are selected,
there is exactly one quadrilateral that they determine.

6
How many of the quadrilaterals possible in the previous problem are:
a. Squares?
b. Rectangles?
c. Parallelograms?
d. Trapezoids? 2 Here, as in calculus, a trapezoid is defined as a quadrilateral with at least one pair of parallel sides. In particular,
parallelograms are trapezoids.
e. Trapezoids that are not parallelograms?

Answer
a. 5 squares. You need to skip exactly one dot on the top and on the bottom to make the side lengths equal. Once you pick a dot
on the top, the other three dots are determined.
b. ( ) rectangles. Once you select the two dots on the top, the bottom two are determined.
7

c. This is tricky since you need to worry about running out of space. One way to count: break into cases by the location of the
top left corner. You get ( ) + (( ) − 1) + (( ) − 3) + (( ) − 6) + (( ) − 10) + (( ) − 15) = 91
7

2
7

2
7

2
7

2
7

2
7

2
parallelograms.
d. All of them
e. 7

2
7

2
7

2
7

2
7

2
7

2
7

2
7
( )( ) − [( ) + (( ) − 1) + (( ) − 3) + (( ) − 6) + (( ) − 10) + (( ) − 15)] .
2
All of them, except the parallelograms.

7
An anagram of a word is just a rearrangement of its letters. How many different anagrams of “uncopyrightable” are there? (This
happens to be the longest common English word without any repeated letters.)

8
How many anagrams are there of the word “assesses” that start with the letter “a”?

Answer
After the first letter (a), we must rearrange the remaining 7 letters. There are only two letters (s and e), so this is really just a bit-
string question (think of s as 1 and e as 0). Thus there ( ) = 21 anagrams starting with “a”.
7

2.E.6 https://math.libretexts.org/@go/page/32567
9
How many anagrams are there of “anagram”?

10
On a business retreat, your company of 20 businessmen and businesswomen go golfing.
a. You need to divide up into foursomes (groups of 4 people): a first foursome, a second foursome, and so on. How many ways
can you do this?
b. After all your hard work, you realize that in fact, you want each foursome to include one of the five Board members. How many
ways can you do this?

Answer
a. (
20

4
)(
16

4
)(ways. Pick 4 out of 20 people to be in the first foursome, then 4 of the remaining 16 for the second
12

4
8
)( )( )
4
4

foursome, and so on (use the multiplicative principle to combine).


b. 5!( )( )( )( )( ) ways. First determine the tee time of the 5 board members, then select 3 of the 15 non board members
15

3
12

3
9

3
6

3
3

to golf with the first board member, then 3 of the remaining 12 to golf with the second, and so on.

11
How many different seating arrangements are possible for King Arthur and his 9 knights around their round table?

Answer
9! (there are 10 people seated around the table, but it does not matter where King Arthur sits, only who sits to his left, two seats
to his left, and so on).

12
Consider sets A and B with |A| = 10 and |B| = 17.
a. How many functions f : A → B are there?
b. How many functions f : A → B are injective?

Answer
a. 17 functions. There are 17 choices for the image of each element in the domain.
10

b. P (17, 10) injective functions. There are 17 choices for image of the first element of the domain, then only 16 choices for the

second, and so on.

13
Consider functions f : {1, 2, 3, 4} → {1, 2, 3, 4, 5, 6}.

a. How many functions are there total?


b. How many functions are injective?
c. How many of the injective functions are increasing? To be increasing means that if a < b then f (a) < f (b), or in other words,
the outputs get larger as the inputs get larger.

14
n!
We have seen that the formula for P (n, k) is . Your task here is to explain why this is the right formula.
(n − k)!

a. Suppose you have 12 chips, each a different color. How many different stacks of 5 chips can you make? Explain your answer
and why it is the same as using the formula for P (12, 5).
b. Using the scenario of the 12 chips again, what does 12! count? What does 7! count? Explain.
c. Explain why it makes sense to divide 12! by 7! when computing P (12, 5) (in terms of the chips).
d. Does your explanation work for numbers other than 12 and 5? Explain the formula P (n, k) = using the variables n and n!

(n−k)!

k.

2.E.7 https://math.libretexts.org/@go/page/32567
1.4: Combinatorial Proofs
1
Prove the identity ( n

k
n−1
) =(
k−1
n−1
)+(
k
) using a question about subsets.

Answer
Proof
Question: How many subsets of size k are there of the set {1, 2, … , n}?
Answer 1: You must choose k out of n elements to put in the set, which can be done in ( n

k
) ways.
Answer 2: First count the number of k -element subsets of {1, 2, … , n}which contain the number n. We must choose k − 1 of
the n − 1 other element to include in this set. Thus there are ( ) such subsets. We have not yet counted all the k -element
n−1

k−1

subsets of {1, 2, … , n} though. In fact, we have missed exactly those subsets which do NOT contain n. To form one of these
subsets, we need to choose k of the other n − 1 elements, so this can be done in ( ) ways. Thus the answer to the question is
n−1

k
n−1 n−1
( )+( ).
k−1 k

Since the two answers are both answers tot eh same question, they are equal, establishing the identity ( n

k
n−1
) =(
k−1
n−1
)+(
k
).

2
Give a combinatorial proof of the identity 2 + 2 + 2 = 3 ⋅ 2.

Answer
Proof
Question: How many 2-letter words start with a, b, or c and end with either y or z?
Answer 1: There are two words that start with a, two that start with b, two that start with c, for a total of 2 + 2 + 2.
Answer 2: There are three choices for the first letter and two choices for the second letter, for a total of 3 ⋅ 2.
Since the two answers are both answers to the same question, they are equal. Thus 2 + 2 + 2 = 3 ⋅ 2.

3
Give a combinatorial proof for the identity 1 + 2 + 3 + ⋯ + n = ( n+1

2
).

Answer
Proof
Question: How many subsets of A = 1, 2, 3, … , n + 1 contain exactly two elements?
Answer 1: We must choose 2 elements from n + 1 choices, so there are ( n+1

2
) subsets.
Answer 2: We break this question down into cases, based on what the larger of the two elements in the subset is. The larger
element can't be 1, since we need at least one element smaller than it.
Larger element is 2: there is 1 choice for the smaller element.
Larger element is 3: there are 2 choices for the smaller element.
Larger element is 4: there are 3 choices for the smaller element.
And so on. When the larger element is n + 1, there are n choices for the smaller element. Since each two element subset must
be in exactly one of these cases, the total number of two element subsets is 1 + 2 + 3 + ⋯ + n.
Answer 1 and answer 2 are both correct answers to the same question, so they must be equal. Therefore,

2.E.8 https://math.libretexts.org/@go/page/32567
n+1
1 +2 +3 +⋯ +n = ( )
2

4
A woman is getting married. She has 15 best friends but can only select 6 of them to be her bridesmaids, one of which needs to be
her maid of honor. How many ways can she do this?
a. What if she first selects the 6 bridesmaids, and then selects one of them to be the maid of honor?
b. What if she first selects her maid of honor, and then 5 other bridemaids?
c. Explain why 6( ) = 15( ).
15

6
14

Answer
a. She has ( ) ways to select the 6 bridesmaids, and then for each way, has 6 choices for the maid of honor. Thus she has
15

( )6 choices.
15

b. She has 15 choices for who will be her maid of honor. Then she needs to select 5 of the remaining 14 friends to be
bridesmaids, which she can do in ( ) ways. Thus she has 15( ) choices.
14

5
14

c. We have answered the question (how many wedding parties can the bride choose from) in two ways. The first way gives the
left-hand side of the identity and the second way gives the right-hand side of the identity. Therefore the identity holds.

5
Give a combinatorial proof of the identity ( n

2
)(
n−2

k−2
n k
) = ( )( ).
k 2

Answer
Proof
Question: You have a large container filled with ping-pong balls, all with a different number on them. You must select k of the
balls, putting two of them in a jar and the others in a box. How many ways can you do this?
Answer 1: First select 2 of the n balls to put in the jar. Then select k − 2 of the remaining n − 2 balls to put in the box. The
first task can be completed in ( ) different ways, the second task in ( ) ways. Thus there are ( )( ) ways to select the
n

2
n−2

k−2
n

2
n−2

k−2

balls.
Answer 2: First select k balls from the n in the container. Then pick 2 of the k balls you picked to put in the jar, placing the
remaining k − 2 in the box. The first task can be completed in ( ) ways, the second task in ( ) ways. Thus there are ( )( )
n

k
k

2
n

k
k

ways to select the balls.


Since both answers count the same thing, they must be equal and the identity is established.

6
Consider the bit strings in B (bit strings of length 6 and weight 2).
6
2

a. How many of those bit strings start with 1?


b. How many of those bit strings start with 01?
c. How many of those bit strings start with 001?
d. Are there any other strings we have not counted yet? Which ones, and how many are there?
e. How many bit strings are there total in B ? 6
2

f. What binomial identity have you just given a combinatorial proof for?

Answer
a. After the 1, we need to find a 5-bit string with one 1. There are ( ) ways to do this.
5

b. ( ) strings (we need to pick 1 of the remaining 4 slots to be the second 1).
4

c. ( ) strings.
3

2.E.9 https://math.libretexts.org/@go/page/32567
d. Yes. We still need strings starting with 0001 (there are ( 2

1
) of these) and strings starting 00001 (there is only ( 1

1
) =1 of
these).
e. ( ) strings
6

f. An example of the Hockey Stick Theorem:


1 2 3 4 5 6
( ) +( ) +( ) +( ) +( ) = ( )
1 1 1 1 1 2

7
Let's count ternary digit strings, that is, strings in which each digit can be 0, 1, or 2.
a. How many ternary digit strings contain exactly n digits?
b. How many ternary digit strings contain exactly n digits and n 2's.
c. How many ternary digit strings contain exactly n digits and n − 1 2's. (Hint: where can you put the non-2 digit, and then what
could it be?)
d. How many ternary digit strings contain exactly n digits and n − 2 2's. (Hint: see previous hint)
e. How many ternary digit strings contain exactly n digits and n − k 2's.
f. How many ternary digit strings contain exactly n digits and no 2's. (Hint: what kind of a string is this?)
g. Use the above parts to give a combinatorial proof for the identity
n n n n n
2 3 n n
( ) + 2( ) + 2 ( ) + 2 ( ) + ⋯ + 2 ( ) = 3 .
0 1 2 3 n

Answer
a. 3 strings, since there are 3 choices for each of the n digits.
n

b. 1 string, since all the digits need to be 2's. However, we might write this as ( ) strings. n

c. There are ( ) places to put the non-2 digit. That digit can be either a 0 or a 1, so there are 2( ) such strings.
n

1
n

d. We must choose two slots to fill with 0's or 1's. There are ( ) ways to do that. Once the slots are picked, we have two
n

choices for the first slot (0 or 1) and two choices for the second slot (0 or 1). So there are a total of 2 ( ) such strings.
2 n

e. There are ( ) ways to pick which slots don't have the 2's. Then those slots can be filled in 2 ways (0 or 1 for each slot). So
n

k
k

there are 2 ( ) such strings.


k n

f. These strings contain just 0's and 1's, so they are bit strings. There are 2 bit strings. But keeping with the pattern above, we
n

might write this as 2 ( ) strings.


n n

g. We answer the question of how many length n ternary digit strings there are in two ways. First, each digit can be one of
three choices, so the total number of strings is 3 . On the other hand, we could break the question down into cases by how
n

many of the digits are 2's. If they are all 2's, then there are ( ) strings. If all but one is a 2, then there are 2( ) strings. If all
n

0
n

but 2 of the digits are 2's, then there are 2 ( ) strings. We choose 2 of the n digits to be non-2, and then there are 2 choices
2 n

for each of those digits. And so on for every possible number of 2's in the string. Therefore
n n 2 n 3 n n n n
( ) + 2( ) + 2 ( ) + 2 ( ) + ⋯ + 2 ( ) = 3 .
0 1 2 3 n

8
How many ways are there to rearrange the letters in the word “rearrange”? Answer this question in at least two different ways to
establish a binomial identity.

Answer
The word contains 9 letters: 3 “r”s, 2 “a”s and 2 “e”s, along with an “n” and a “g”. We could first select the positions for the
“r”s in ( ) ways, then the “a”s in ( ) ways, the “e”s in ( ) ways and then select one of the remaining two spots to put the “n”
9

3
6

2
4

(placing the “g” in the last spot). This gives the answer
9 6 4 2 1
( )( )( )( )( ).
3 2 2 1 1

Alternatively, we could select the positions of the letters in the opposite order, which would give an answer

2.E.10 https://math.libretexts.org/@go/page/32567
9 8 7 5 3
( )( )( )( )( ).
1 1 2 2 3

(where the 3 “r”s go in the remaining 3 spots). These two expressions are equal:

9
Give a combinatorial proof for the identity P (n, k) = ( n

k
)k!

Answer
Proof
Question: How many k -letter words can you make using n different letters without repeating any letter?
Answer 1: There are n choices for the first letter, n − 1 choices for the second letter, n − 2 choices for the third letter, and so
on until n − (k − 1) choices for the k th letter (since k − 1 letters have already been assigned at that point). The product of
these numbers can be written n!
which is P (n, k). Therefore there are P (n, k) words.
(n−k)!

Answer 2: First pick k letters to be in the word from the n choices. This can be done in ( ) ways. Now arrange those letters
n

into a word. There are k choices for the first letter, k − 1 choices for the second, and so on, for a total of k! arrangements of the
k letters. Thus the total number of words is ( )k!.
n

Since the two answers are correct answers to the same question, we have established that P (n, k) = ( n

k
)k!.

10
Establish the identity below using a combinatorial proof.
2 n 3 n−1 4 n−2 n 2 n+3
( )( ) + ( )( ) + ( )( ) + ⋯ + ( )( ) = ( ).
2 2 2 2 2 2 2 2 5

Answer
Proof
Question: How many 5-element subsets are there of the set {1, 2, … , n + 3}.
Answer 1: We choose 5 out of the n + 3 elements, so ( n+3

5
) subsets.
Answer 2: Break this up into cases by what the “middle” (third smallest) element of the 5 element subset is. The smallest this
could be is a 3. In that case, we have ( ) choices for the numbers below it, and ( ) choices for the numbers above it.
2

2
n

Alternatively, the middle number could be a 4. In this case there are ( ) choices for the bottom two numbers and ( ) choices
3

2
n−1

for the top two numbers. If the middle number is 5, then there are ( ) choices for the bottom two numbers and ( ) choices
4

2
n−2

for the top two numbers. An so on, all the way up to the largest the middle number could be, which is n + 1. In that case there
are ( ) choices for the bottom two numbers and ( ) choices for the top number. Thus the number of 5 element subsets is
n

2
2

2 n 3 n−1 4 n−2 n 2
( )( ) + ( )( ) + ( )( ) + ⋯ + ( )( ).
2 2 2 2 2 2 2 2

Since the two answers correctly answer the same question, we have

2 n 3 n−1 4 n−2 n 2 n+3


( )( ) + ( )( ) + ( )( ) + ⋯ + ( )( ) = ( ).
2 2 2 2 2 2 2 2 5

1.5: Stars and Bars


1
A multiset is a collection of objects, just like a set, but can contain an object more than once (the order of the elements still doesn't
matter). For example, {1, 1, 2, 5, 5, 7}is a multiset of size 6.
a. How many sets of size 5 can be made using the 10 numeric digits 0 through 9?

2.E.11 https://math.libretexts.org/@go/page/32567
b. How many multisets of size 5 can be made using the 10 numeric digits 0 through 9?

Answer
a. ( ) sets. We must select 5 of the 10 digits to put in the set.
10

b. Use stars and bars: each star represents one of the 5 elements of the set, each bar represents a switch between digits. So there
are 5 stars and 9 bars, giving us ( ) sets.
14

2
Each of the counting problems below can be solved with stars and bars. For each, say what outcome the diagram

∗ ∗ ∗| ∗ || ∗ ∗|

represents, if there are the correct number of stars and bars for the problem. Otherwise, say why the diagram does not represent any
outcome, and what a correct diagram would look like.
a. How many ways are there to select a handful of 6 jellybeans from a jar that contains 5 different flavors?
b. How many ways can you distribute 5 identical lollipops to 6 kids?
c. How many 6-letter words can you make using the 5 vowels?
d. How many solutions are there to the equation x + x + x + x = 6.
1 2 3 4

Answer
a. You take 3 strawberry, 1 lime, 0 licorice, 2 blueberry and 0 bubblegum.
b. This is backwards. We don't want the stars to represent the kids because the kids are not identical, but the stars are. Instead
we should use 5 stars (for the lollipops) and use 5 bars to switch between the 6 kids. For example,

∗ ∗ || ∗ ∗ ∗ |||

would represent the outcome with the first kid getting 2 lollipops, the third kid getting 3, and the rest of the kids getting
none.
c. This is the word AAAEOO.
d. This doesn't represent a solution. Each star should represent one of the 6 units that add up to 6, and the bars should switch
between the different variables. We have one too many bars. An example of a correct diagram would be

∗| ∗ ∗|| ∗ ∗∗,

representing that x 1 = 1, x2 = 2, x3 = 0, and x


4 = 3.

3
After gym class you are tasked with putting the 14 identical dodgeballs away into 5 bins.
a. How many ways can you do this if there are no restrictions?
b. How many ways can you do this if each bin must contain at least one dodgeball?

Answer
a. (
18

4
) ways. Each outcome can be represented by a sequence of 14 stars and 4 bars.
b. (
13

4
) ways. First put one ball in each bin. This leaves 9 stars and 4 bars.

4
How many integer solutions are there to the equation x + y + z = 8 for which
a. x, y, and z are all positive?
b. x, y, and z are all non-negative?
c. x, y, and z are all greater than −3.

Answer
a. 7
( )
2
solutions. After each variable gets 1 star for free, we are left with 5 stars and 2 bars.
b. (
10

2
) solutions. We have 8 stars and 2 bars.

2.E.12 https://math.libretexts.org/@go/page/32567
c. (
19
solutions. This problem is equivalent to finding the number of solutions to x + y + z = 17 where x , y and z are
2
)
′ ′ ′ ′ ′ ′

non-negative. (In fact, we really just do a substitution. Let x = x − 3, y = y − 3 and z = z − 3 ).


′ ′ ′

5
Using the digits 2 through 8, find the number of different 5-digit numbers such that:
a. Digits cannot be repeated and must be written in increasing order. For example, 23678 is okay, but 32678 is not.
b. Digits can be repeated and must be written in non-decreasing order. For example, 24448 is okay, but 24484 is not.

Answer
a. There are ( ) numbers. We simply choose five of the seven digits and once chosen put them in increasing order.
7

b. This requires stars and bars. Use a star to represent each of the 5 digits in the number, and use their position relative to the
bars to say what numeral fills that spot. So we will have 5 stars and 6 bars, giving ( ) numbers.
11

6
When playing Yahtzee, you roll five regular 6-sided dice. How many different outcomes are possible from a single roll? The order
of the dice does not matter.

7
Your friend tells you she has 7 coins in her hand (just pennies, nickels, dimes and quarters). If you guess how many of each kind of
coin she has, she will give them to you. If you guess randomly, what is the probability that you will be correct?

8
How many integer solutions to x 1 + x2 + x3 + x4 = 25 are there for which x
1 ≥ 1, x2 ≥ 2, x3 ≥ 3 and x
4 ≥ 4?

9
Solve the three counting problems below. Then say why it makes sense that they all have the same answer. That is, say how you
can interpret them as each other.
a. How many ways are there to distribute 8 cookies to 3 kids?
b. How many solutions in non-negative integers are there to x + y + z = 8?
c. How many different packs of 8 crayons can you make using crayons that come in red, blue and yellow?

10
Consider functions f : {1, 2, 3, 4, 5} → {0, 1, 2, … , 9}.

a. How many of these functions are strictly increasing? Explain. (A function is strictly increasing provided if a < b, then
f (a) < f (b). )

b. How many of the functions are non-decreasing? Explain. (A function is non-decreasing provided if a < b, then f (a) ≤ f (b). )

11
Conic, your favorite math themed fast food drive-in offers 20 flavors which can be added to your soda. You have enough money to
buy a large soda with 4 added flavors. How many different soda concoctions can you order if:
a. You refuse to use any of the flavors more than once?
b. You refuse repeats but care about the order the flavors are added?
c. You allow yourself multiple shots of the same flavor?
d. You allow yourself multiple shots, and care about the order the flavors are added?

Answer
a. (
20
sodas (order does not matter and repeats are not allowed).
4
)

b. sodas (order matters and repeats are not allowed).


P (20, 4) = 20 ⋅ 19 ⋅ 18 ⋅ 17

c. ( ) sodas (order does not matter and repeats are allowed; 4 stars and 19 bars).
23

19

d. 20 sodas (order matters and repeats are allowed; 20 choices 4 times).


4

2.E.13 https://math.libretexts.org/@go/page/32567
1.6: Advanced Counting Using PIE
1
The dollar menu at your favorite tax-free fast food restaurant has 7 items. You have $10 to spend. How many different meals can
you buy if you spend all your money and:
a. Purchase at least one of each item.
b. Possibly skip some items.
c. Don't get more than 2 of any particular item.

Answer a
9
( )
6
meals.

Answer b
(
16

6
) meals.

Answer c

(
16

6
) − [( )(
7

1
13

6
7
) − ( )(
2
10

6
7 7
) + ( )( )]
3 6
me als. Use PIE to subtract all the meals in which you get 3 or more of a particular item.

2
After a late night of math studying, you and your friends decide to go to your favorite tax-free fast food Mexican restaurant, Burrito
Chime. You decide to order off of the dollar menu, which has 7 items. Your group has $16 to spend (and will spend all of it).
a. How many different orders are possible? Explain. (The order in which the order is placed does not matter - just which and how
many of each item that is ordered.)
b. How many different orders are possible if you want to get at least one of each item? Explain.
c. How many different orders are possible if you don't get more than 4 of any one item? Explain.

3
After another gym class you are tasked with putting the 14 identical dodgeballs away into 5 bins. This time, no bin can hold more
than 6 balls. How many ways can you clean up?

Solution

(
18

4
) − [( )(
5

1
11

4
5
) − ( )( )] .
2
4

4
Subtract all the distributions for which one or more bins contain 7 or more balls.

4
Consider the equation x 1 + x2 + x3 + x4 = 15. How many solutions are there with 2 ≤ x i ≤5 for all i ∈ {1, 2, 3, 4}?

Solution
The easiest way to solve this is to instead count the solutions to y + y + y + y = 7 with 0 ≤ y
1 2 3 4 i ≤ 3. By taking
x = y + 2, each solution to this new equation corresponds to exactly one solution to the original equation.
i i

Now all the ways to distribute the 7 units to the four y variables can be found using stars and bars, specifically 7 stars and 3
i

bars, so ( ) ways. But this includes the ways that one or more y variables can be assigned more than 3 units. So subtract,
10

3
i

using PIE. We get


10 4 6
( ) − ( )( ).
3 1 3

The ( ) counts the number of ways to pick one variable to be over-assigned, the ( ) is the number of ways to assign the
4

1
6

remaining 3 units to the 4 variables. Note that this is the final answer because it is not possible to have two variables both get 4
units.

2.E.14 https://math.libretexts.org/@go/page/32567
5
Suppose you planned on giving 7 gold stars to some of the 13 star students in your class. Each student can receive at most one star.
How many ways can you do this? Use PIE, and also an easier method, and compare your results.

6
Based on the previous question, give a combinatorial proof for the identity:
n
n n+k−1 j+1
n n + k − (2j + 1)
( ) =( ) − ∑(−1 ) ( )( ).
k k j k
j=1

7
Illustrate how the counting of derangements works by writing all permutations of {1, 2, 3, 4} and the crossing out those which are
not derangements. Keep track of the permutations you cross out more than once, using PIE.

Solution
The 9 derangements are: 2143, 2341, 2413, 3142, 3412, 3421, 4123, 4312, 4321.

8
How many permutations of {1, 2, 3, 4, 5}leave exactly 1 element fixed?

Solution
First pick one of the five elements to be fixed. For each such choice, derange the remaining four, using the standard advanced
PIE formula. We get ( 5

1
4 4 4
) (4! − [( )3! − ( )2! + ( )1! − ( )0!])
1 2 3
4

4
permutations.

9
Ten ladies of a certain age drop off their red hats at the hat check of a museum. As they are leaving, the hat check attendant gives
the hats back randomly. In how many ways can exactly six of the ladies receive their own hat (and the other four not)? Explain.

10
The Grinch sneaks into a room with 6 Christmas presents to 6 different people. He proceeds to switch the name-labels on the
presents. How many ways could he do this if:
a. No present is allowed to end up with its original label? Explain what each term in your answer represents.
b. Exactly 2 presents keep their original labels? Explain.
c. Exactly 5 presents keep their original labels? Explain.

11
Consider functions f : {1, 2, 3, 4} → {a, b, c, d, e, f }. How many functions have the property that f (1) ≠ a or f (2) ≠ b, or both?

Solution
There are 5 ⋅ 6 functions for which f (1) ≠ a and another 5 ⋅ 6 functions for which f (2) ≠ b. There are 5 ⋅ 6 functions for
3 3 2 2

which both f (1) ≠ a and f (2) ≠ b. So the total number of functions for which f (1) ≠ a or f (2) ≠ b or both is
3 3 2 2
5⋅6 +5 ⋅ 6 −5 ⋅6 = 1260.

12
Consider sets A and B with |A| = 10 and |B| = 5. How many functions f : A → B are surjective?

Solution
5
10 5
− [( )4
1
10 5
− ( )3
2
10 5
+ ( )2
3
10
functions. The 5 is all the functions from A to B. We subtract those that aren't
5
− ( )1
4
10
]
10

surjective. Pick one of the five elements in B to not have in the range (in ( ) ways) and count all those functions (4 ). But this
5

1
10

overcounts the functions where two elements from B are excluded from the range, so subtract those. And so on, using PIE.

2.E.15 https://math.libretexts.org/@go/page/32567
13
Let A = {1, 2, 3, 4, 5}. How many injective functions f : A → A have the property that for each x ∈ A, f (x) ≠ x?

14
Let d be the number of derangements of n objects. For example, using the techniques of this section, we find
n

3 3 3
d3 = 3! − (( )2! − ( )1! + ( )0!)
1 2 3

We can use the formula for ( n

k
) to write this all in terms of factorials. After simplifying, for d we would get
3

1 1 1
d3 = 3! (1 − + − )
1 2 6

Generalize this to find a nicer formula for d . Bonus: For large


n n, approximately what fraction of all permutations are
derangements? Use your knowledge of Taylor series from calculus.

2.E: Counting (Exercises) is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.
1.E: Counting (Exercises) has no license indicated.

2.E.16 https://math.libretexts.org/@go/page/32567
2.S: Counting (Summary)
Investigate!
Suppose you have a huge box of animal crackers containing plenty of each of 10 different animals. For the counting questions
below, carefully examine their similarities and differences, and then give an answer. The answers are all one of the following:
10 6 15
P (10, 6) ( ) 10 ( ).
6 9

1. How many animal parades containing 6 crackers can you line up?
2. How many animal parades of 6 crackers can you line up so that the animals appear in alphabetical order?
3. How many ways could you line up 6 different animals in alphabetical order?
4. How many ways could you line up 6 different animals if they can come in any order?
5. How many ways could you give 6 children one animal cracker each?
6. How many ways could you give 6 children one animal cracker each so that no two kids get the same animal?
7. How many ways could you give out 6 giraffes to 10 kids?
8. Write a question about giving animal crackers to kids that has the answer ( ).
10

With all the different counting techniques we have mastered in this last chapter, it might be difficult to know when to apply which
technique. Indeed, it is very easy to get mixed up and use the wrong counting method for a given problem. You get better with
practice. As you practice you start to notice some trends that can help you distinguish between types of counting problems. Here
are some suggestions that you might find helpful when deciding how to tackle a counting problem and checking whether your
solution is correct.
Remember that you are counting the number of items in some list of outcomes. Write down part of this list. Write down an
element in the middle of the list – how are you deciding whether your element really is in the list. Could you get this element
more than once using your proposed answer?
If generating an element on the list involves selecting something (for example, picking a letter or picking a position to put a
letter, etc), can the things you select be repeated? Remember, permutations and combinations select objects from a set without
repeats.
Does order matter? Be careful here and be sure you know what your answer really means. We usually say that order matters
when you get different outcomes when the same objects are selected in different orders. Combinations and “Stars & Bars” are
used when order does not matter.
There are four possibilities when it comes to order and repeats. If order matters and repeats are allowed, the answer will look
like n . If order matters and repeats are not allowed, we have P (n, k). If order doesn't matter and repeats are allowed, use stars
k

and bars. If order doesn't matter and repeats are not allowed, use ( ). But be careful: this only applies when you are selecting
n

things, and you should make sure you know exactly what you are selecting before determining which case you are in.
Think about how you would represent your counting problem in terms of sets or functions. We know how to count different
sorts of sets and different types of functions.
As we saw with combinatorial proofs, you can often solve a counting problem in more than one way. Do that, and compare your
numerical answers. If they don't match, something is amiss.
While we have covered many counting techniques, we have really only scratched the surface of the large subject of enumerative
combinatorics. There are mathematicians doing original research in this area even as you read this. Counting can be really hard.
In the next chapter, we will approach counting questions from a very different direction, and in doing so, answer infinitely many
counting questions at the same time. We will create sequences of answers to related questions.

Chapter Review
1
You have 9 presents to give to your 4 kids. How many ways can this be done if:
a. The presents are identical, and each kid gets at least one present?
b. The presents are identical, and some kids might get no presents?
c. The presents are unique, and some kids might get no presents?

2.S.1 https://math.libretexts.org/@go/page/32568
d. The presents are unique and each kid gets at least one present?

Answer
a. 8
ways, after giving one present to each kid, you are left with 5 presents (stars) which need to be divide among the 4 kids
( )
3

(giving 3 bars).
b. ( ) ways. You have 9 stars and 3 bars.
12

c. 4 . You have 4 choices for whom to give each present. This is like making a function from the set of presents to the set of
9

kids.
d. 4
9 4
− [( )3
1
9 4
− ( )2
2
9 4 9
+ ( )1 ]
3
ways. Now the function from the set of presents to the set of kids must be surjective.

2
For each of the following counting problems, say whether the answer is ( 10

4
), P (10, 4), or neither. If you answer is “neither,” say
what the answer should be instead.
a. How many shortest lattice paths are there from (0, 0) to (10, 4)?
b. If you have 10 bow ties, and you want to select 4 of them for next week, how many choices do you have?
c. Suppose you have 10 bow ties and you will wear one on each of the next 4 days. How many choices do you have?
d. If you want to wear 4 of your 10 bow ties next week (Monday through Sunday), how many ways can this be accomplished?
e. Out of a group of 10 classmates, how many ways can you rank your top 4 friends?
f. If 10 students come to their professor's office but only 4 can fit at a time, how different combinations of 4 students can see the
prof first?
g. How many 4 letter words can be made from the first 10 letters of the alphabet?
h. How many ways can you make the word “cake” from the first 10 letters of the alphabet?
i. How many ways are there to distribute 10 apples among 4 children?
j. If you have 10 kids (and live in a shoe) and 4 types of cereal, how many ways can your kids eat breakfast?
k. How many ways can you arrange exactly 4 ones in a string of 10 binary digits?
l. You want to select 4 single digit numbers as your lotto picks. How many choices do you have?
m. 10 kids want ice-cream. You have 4 varieties. How many ways are there to give the kids as much ice-cream as they want?
n. How many 1-1 functions are there from {1, 2, … , 10}to {a, b, c, d}?
o. How many surjective functions are there from {1, 2, … , 10}to {a, b, c, d}?
p. Each of your 10 bow ties match 4 pairs of suspenders. How many outfits can you make?
q. After the party, the 10 kids each choose one of 4 party-favors. How many outcomes?
r. How many 6-elements subsets are there of the set {1, 2, … , 10}
s. How many ways can you split up 11 kids into 5 teams?
t. How many solutions are there to x + x + ⋯ + x = 6 where each x is non-negative?
1 2 5 i

u. Your band goes on tour. There are 10 cities within driving distance, but only enough time to play 4 of them. How many choices
do you have for the cities on your tour?
v. In how many different ways can you play the 4 cities you choose?
w. Out of the 10 breakfast cereals available, you want to have 4 bowls. How many ways can you do this?
x. There are 10 types of cookies available. You want to make a 4 cookie stack. How many different stacks can you make?
y. From your home at (0,0) you want to go to either the donut shop at (5,4) or the one at (3,6). How many paths could you take?
z. How many 10-digit numbers do not contain a sub-string of 4 repeated digits?

Answer
a. Neither. ( ) paths.
14

b. ( ) bow ties. P (10, 4), since order is important.


10

c. Neither. Assuming you will wear each of the 4 ties on just 4 of the 7 days, without repeats: ( )P (7, 4). 10

d. P (10, 4). ( ). 10

e. Neither. Since you could repeat letters: 10 . If no repeats are allowed, it would be P (10, 4).
4

f. Neither. Actually, “k” is the 11th letter of the alphabet, so the answer is 0. If “k” was among the first 10 letters, there would
only be 1 way - write it down.
g. Neither. Either ( ) (if every kid gets an apple) or ( ) (if appleless kids are allowed).
9

3
13

2.S.2 https://math.libretexts.org/@go/page/32568
h. Neither. Note that this could not be ( ) since the 10 things and 4 things are from different groups. 4 .
10

4
10

i. ( ) - don't be fooled by the “arrange” in there - you are picking 4 out of 10 spots to put the 1's. ( ) (assuming order is
10

4
10

irrelevant).
j. Neither. 16 (each kid chooses yes or no to 4 varieties).
10

k. Neither. 0.
l. Neither. 4 − [( )3 − ( )2 + ( )1 ].
10 4

1
10 4

2
10 4

3
10

m. Neither. 10 ⋅ 4.
n. Neither. 4 . 10

o. ( ) (which is the same as ( ) ).


10

4
10

p. Neither. If all the kids were identical, and you wanted no empty teams, it would be ( ). Instead, this will be the same as the
10

number of surjective functions from a set of size 11 to a set of size 5.


q. ( ). ( ).
10

4
10

r. Neither. 4!.
s. Neither. It's ( ) if you won't repeat any choices. If repetition is allowed, then this becomes x + x + ⋯ + x = 4,
10

4
1 2 10

which has ( ) solutions in non-negative integers.


13

t. Neither. Since repetition of cookie type is allowed, the answer is 10 . Without repetition, you would have P (10, 4).
4

u. ( ) since that is equal to ( ) + ( ).


10

4
9

4
9

v. Neither. It will be a complicated (possibly PIE) counting problem.

3
Recall, you own 3 regular ties and 5 bow ties. You realize that it would be okay to wear more than two ties to your clown college
interview.
a. You must select some of your ties to wear. Everything is okay, from no ties up to all ties. How many choices do you have?
b. If you want to wear at least one regular tie and one bow tie, but are willing to wear up to all your ties, how many choices do you
have for which ties to wear?
c. How many choices do you have if you wear exactly 2 of the 3 regular ties and 3 of the 5 bow ties?
d. Once you have selected 2 regular and 3 bow ties, in how many orders could you put the ties on, assuming you must have one of
the three bow ties on top?

Answer
a. 2 = 256 choices. You have two choices for each tie: wear it or don't.
8

b. You have 7 choices for regular ties (the 8 choices less the “no regular tie” option) and 31 choices for bow ties (32 total
minus the “no bow tie” option). Thus total you have 7 ⋅ 31 = 217 choices.
c. ( )( ) = 30 choices.
3

2
5

d. Select one of the 3 bow ties to go on top. There are then 4 choices for the next tie, 3 for the tie after that, and so on. Thus
3 ⋅ 4! = 72 choices.

4
Give a counting question where the answer is 8 ⋅ 3 ⋅ 3 ⋅ 5. Give another question where the answer is 8 + 3 + 3 + 5.

Answer
You own 8 purple bow ties, 3 red bow ties, 3 blue bow ties and 5 green bow ties. How many ways can you select one of each
color bow tie to take with you on a trip? 8 ⋅ 3 ⋅ 3 ⋅ 5 ways. How many choices do you have for a single bow tie to wear
tomorrow? 8 + 3 + 3 + 5 choices.

5
Consider five digit numbers α = a 1 a2 a3 a4 a5 , with each digit from the set {1, 2, 3, 4}.
a. How many such numbers are there?
b. How many such numbers are there for which the sum of the digits is even?
c. How many such numbers contain more even digits than odd digits?

2.S.3 https://math.libretexts.org/@go/page/32568
Answer
a. 5
4numbers.
b. 4
4 numbers (choose any digits for the first four digits - then pick either an even or an odd last digit to make the sum
⋅2

even).
c. We need 3 or more even digits. 3 even digits: ( )2 2 . 4 even digits: ( )2 2. 5 even digits: ( )2 . So all together:
5

3
3 2 5

4
4 5

5
5

3
3 2 5

4
4
( )2 2 + ( )2 2 + ( )2
5

5
numbers.
5

6
In a recent small survey of airline passengers, 25 said they had flown American in the last year, 30 had flown Jet Blue, and 20 had
flown Continental. Of those, 10 reported they had flown on American and Jet Blue, 12 had flown on Jet Blue and Continental, and
7 had flown on American and Continental. 5 passengers had flown on all three airlines.
How many passengers were surveyed? (Assume the results above make up the entire survey.)

Answer
51 passengers.

7
Recall, by 8-bit strings, we mean strings of binary digits, of length 8.
a. How many 8-bit strings are there total?
b. How many 8-bit strings have weight 5?
c. How many subsets of the set {a, b, c, d, e, f , g, h} contain exactly 5 elements?
d. Explain why your answers to parts (b) and (c) are the same. Why are these questions equivalent?

Answer
a. 2 strings.
8

b. ( ) strings.
8

c. ( ) strings.
8

d. There is a bijection between subsets and bit strings: a 1 means that element in is the subset, a 0 means that element is not in
the subset. To get a subset of an 8 element set we have a 8-bit string. To make sure the subset contains exactly 5 elements,
there must be 5 1's, so the weight must be 5.

8
What is the coefficient of x 10
in the expansion of (x + 1) 13 2
+ x (x + 1 )
17
?

Answer
13 17
( )+( ).
10 8

9
How many 8-letter words contain exactly 5 vowels (a,e,i,o,u)? What if repeated letters were not allowed?

Answer
With repeated letters allowed: ( 8

5
5
)5 21
3
words. Without repeats: ( 8
)5!P (21, 3)
5
words.

10
For each of the following, find the number of shortest lattice paths from (0, 0) to (8, 8) which:
a. pass through the point (2, 3).
b. avoid (do not pass through) the point (7, 5).
c. either pass through (2, 3) or (5, 7) (or both).

Answer

2.S.4 https://math.libretexts.org/@go/page/32568
a. 5
( )(
2
11

6
) paths.
b. (
16

8
)−(
12

7
)( )
4

1
paths.
c. 5
( )(
2
11

6
)+(
12

5
4 5 7
)( ) − ( )( )( )
3 2 3
4

3
paths.

11
You live in Grid-Town on the corner of 2nd and 3rd, and work in a building on the corner of 10th and 13th. How many routes are
there which take you from home to work and then back home, but by a different route?

Answer
(
18

8
) ((
18

8
) − 1) routes.

12
How many 10-bit strings start with 111 or end with 101 or both?

Answer
2
7
+2
7
−2
4
strings (using PIE).

13
How many 10-bit strings of weight 6 start with 111 or end with 101 or both?

Answer
7
( )+( )−( )
3
7

4
4

1
strings.

14
How many 6 letter words made from the letters a, b, c, d, e, f without repeats do not contain the sub-word “bad” in (a) consecutive
letters? or (b) not-necessarily consecutive letters (but in order)?

Answer
(a) 6! − 4 ⋅ 3! words. (b) 6! − ( 6
)3!
3
words.

15
Explain using lattice paths why ∑ n

k=0
n
( ) =2 .
k
n

Answer
2 is the number of lattice paths which have length n, since for each step you can go up or right. Such a path would end along
n

the line x + y = n. So you will end at (0, n), or (1, n − 1) or (2, n − 2) or … or (n, 0). Counting the paths to each of these
points separately, give ( ), ( ), ( ), …, ( ) (each time choosing which of the n steps to be to the right). These two methods
n

0
n

1
n

2
n

count the same quantity, so are equal.

16
Suppose you have 20 one-dollar bills to give out as prizes to your top 5 discrete math students. How many ways can you do this if:
a. Each of the 5 students gets at least 1 dollar?
b. Some students might get nothing?
c. Each student gets at least 1 dollar but no more than 7 dollars?

Hint
Stars and bars.

Answer
a. (
19

4
) ways.
b. (
24

4
) ways.

2.S.5 https://math.libretexts.org/@go/page/32568
c. (
19

4
) − [( )(
5

1
12

4
5
) − ( )( )]
2
5

4
ways.

17
How many functions f : {1, 2, 3, 4, 5} → {a, b, c, d, e} are there satisfying:
a. f (1) = a or f (2) = b (or both)?
b. f (1) ≠ a or f (2) ≠ b (or both)?
c. f (1) ≠ a and f (2) ≠ b, and f is injective?
d. f is surjective, but f (1) ≠ a, f (2) ≠ b, f (3) ≠ c, f (4) ≠ d and f (5) ≠ e?

Answer
a. 5 + 5 − 5 functions.
4 4 3

b. 4 ⋅ 5 + 5 ⋅ 4 ⋅ 5 − 4 ⋅ 4 ⋅ 5 functions.
4 3 3

c. 5! − [4! + 4! − 3!] functions. Note we use factorials instead of powers because we are looking for injective functions.
d. Note that being surjective here is the same as being injective, so we can start with all 5! injective functions and subtract
those which have one or more “fixed point”. We get 5! − [( )4! − ( )3! + ( )2! − ( )1! + ( )0!] functions.
5

1
5

2
5

3
5

4
5

18
How many functions map {1, 2, 3, 4, 5, 6}onto {a, b, c, d} (i.e., how many surjections are there)?

Answer
6 4 6 4 6 4 6
4 − [( )3 − ( )2 + ( )1 ] .
1 2 3

19
To thank your math professor for doing such an amazing job all semester, you decide to bake Oscar cookies. You know how to
make 10 different types of cookies.
a. If you want to give your professor 4 different types of cookies, how many different combinations of cookie type can you select?
Explain your answer.
b. To keep things interesting, you decide to make a different number of each type of cookie. If again you want to select 4 cookie
types, how many ways can you select the cookie types and decide for which there will be the most, second most, etc. Explain
your answer.
c. You change your mind again. This time you decide you will make a total of 12 cookies. Each cookie could be any one of the 10
types of cookies you know how to bake (and it's okay if you leave some types out). How many choices do you have? Explain.
d. You realize that the previous plan did not account for presentation. This time, you once again want to make 12 cookies, each
one could be any one of the 10 types of cookies. However, now you plan to shape the cookies into the numerals 1, 2, …, 12
(and probably arrange them to make a giant clock, but you haven't decided on that yet). How many choices do you have for
which types of cookies to bake into which numerals? Explain.
e. The only flaw with the last plan is that your professor might not get to sample all 10 different varieties of cookies. How many
choices do you have for which types of cookies to make into which numerals, given that each type of cookie should be present
at least once? Explain.

Answer
a. (
10
combinations. You need to choose 4 of the 10 cookie types. Order doesn't matter.
4
)

b. ways. You are choosing and arranging 4 out of 10 cookies. Order matters now.
P (10, 4) = 10 ⋅ 9 ⋅ 8 ⋅ 7

c. ( ) choices. You must switch between cookie type 9 times as you make your 12 cookies. The cookies are the stars, the
21

switches between cookie types are the bars.


d. 10 choices. You have 10 choices for the “1” cookie, 10 choices for the “2” cookie, and so on.
12

e. 10 − [( )9 − ( )8 + ⋯ − ( )0 ] choices. We must use PIE to remove all the ways in which one or more cookie
12 10

1
12 10

2
12 10

10
12

type is not selected.

2.S.6 https://math.libretexts.org/@go/page/32568
20
For which of the parts of the previous problem (Exercise 1.7.19) does it make sense to interpret the counting question as counting
some number of functions? Say what the domain and codomain should be, and whether you are counting all functions, injections,
surjections, or something else.

Answer
a. You are giving your professor 4 types of cookies coming from 10 different types of cookies. This does not lend itself well to
a function interpretation. We could say that the domain contains the 4 types you will give your professor and the codomain
contains the 10 you can choose from, but then counting injections would be too much (it doesn't matter if you pick type 3
first and type 2 second, or the other way around, just that you pick those two types).
b. We want to consider injective functions from the set {most, second most, second least, least} to the set of 10 cookie types.
We want injections because we cannot pick the same type of cookie to give most and least of (for example).
c. This is not a good problem to interpret as a function. The problem is that the domain would have to be the 12 cookies you
bake, but these elements are indistinguishable (there is not a first cookie, second cookie, etc.).
d. The domain should be the 12 shapes, the codomain the 10 types of cookies. Since we can use the same type for different
shapes, we are interested in counting all functions here.
e. Here we insist that each type of cookie be given at least once, so now we are asking for the number of surjections of those
functions counted in the previous part.

This page titled 2.S: Counting (Summary) is shared under a CC BY-SA license and was authored, remixed, and/or curated by Oscar Levin.
1.S: Counting (Summary) by Oscar Levin is licensed CC BY-SA 4.0.

2.S.7 https://math.libretexts.org/@go/page/32568
Index
A D L
additive principle derangement lattice path
2.1: Additive and Multiplicative Principles 2.6: Advanced Counting Using PIE 2.2: Binomial Coefficients
disjoint
B 2.1: Additive and Multiplicative Principles P
binomial coefficients Pascal's Triangle
2.2: Binomial Coefficients F 2.2: Binomial Coefficients
factorial 2.4: Combinatorial Proofs
C 2.3: Combinations and Permutations permutations
2.3: Combinations and Permutations
Combinations
2.3: Combinations and Permutations I Principle of Inclusion/Exclusion (PIE)
2.6: Advanced Counting Using PIE
integer lattice
2.2: Binomial Coefficients

1 https://math.libretexts.org/@go/page/37992
Glossary
Sample Word 1 | Sample Definition 1

1 https://math.libretexts.org/@go/page/51345
Detailed Licensing
Overview
Title: Supplements for Discrete Judy Dean
Webpages: 23
All licenses found:
Undeclared: 65.2% (15 pages)
CC BY-SA 4.0: 34.8% (8 pages)

By Page
Supplements for Discrete Judy Dean - Undeclared 2.S: Counting (Summary) - CC BY-SA 4.0
Front Matter - Undeclared 2.1: Additive and Multiplicative Principles - CC BY-
TitlePage - Undeclared SA 4.0
InfoPage - Undeclared 2.2: Binomial Coefficients - CC BY-SA 4.0
Table of Contents - Undeclared 2.3: Combinations and Permutations - CC BY-SA 4.0
Licensing - Undeclared 2.4: Combinatorial Proofs - CC BY-SA 4.0
2.5: Stars and Bars - CC BY-SA 4.0
1: Groups I - Undeclared
2.6: Advanced Counting Using PIE - CC BY-SA 4.0
1.1: Definition of a Group - Undeclared
Back Matter - Undeclared
1.3: Integers Modulo n - Undeclared
1.4: Permutations - Undeclared Index - Undeclared
Glossary - Undeclared
2: Counting - CC BY-SA 4.0
Detailed Licensing - Undeclared
2.E: Counting (Exercises) - Undeclared

1 https://math.libretexts.org/@go/page/115738

You might also like