RZC Chp4 Combinatorics Slides
RZC Chp4 Combinatorics Slides
RZC Chp4 Combinatorics Slides
Dr J Frost ([email protected])
www.drfrostmaths.com
All Maths Challenge and Olympiad problems are ©
UK Mathematics Trust (www.ukmt.org.uk)
a. Compositions
b. Partitions
Part 1: Fundamentals
Here, we look at the some of the basics of combinatorics, and
fundamental combinatoric operators that are commonly used.
What is combinatorics?
This is closely related to probability, since we often have to consider combinations and
permutations of things to determine the exact probability. But combinatorics arises in many
mathematical fields – you may have encountered it in Algebra for Binomial Expansion.
Fundamentals #1: Slot Filling
Example: How many outcomes are there when we simultaneously roll 5 dice?
6 x 6 x 6 x 6 x 6 = 65
There are 5 slots for the 5 dice. In each slot,
there are 6 outcomes.
4 x 3 x 2 x 1 = 4!
We could pick any of the 4 pieces We have 3 remaining fruits to And so on
of fruit for the first slot. choose from for the second slot.
Fundamentals #2: The Factorial Function
The particular point of interest here is that we’ve turned an unordered problem (i.e. the ordering
of the dice doesn’t matter) into an ordered one (i.e. we considered ‘ordered slots’). We’ll consider
unordered vs ordered problems later.
Question: Simplify ( 𝑛− 1 ) !
𝑛!
( 𝑛− 1 ) ! ( 𝑛 −1 ) × ( 𝑛 −2 ) × … 𝟏
𝑛 × ( 𝑛 −1?) × ( 𝑛 −2 ) × … 𝒏
= =
𝑛!
Fundamentals #2: The Factorial Function
0 !=1
Base case
(For example
Recursive case
4! = 4 x 3! )
The factorial function works only on non-negative integers. There’s a function called the gamma function
that generalises factorial to all numbers (including decimal, negative and complex numbers!). The gamma
function is offset from the factorial function by 1. It is used for example in Number Theory and Statistics.
5 x 4 x 3 = 5! = 5P3
2!
We could pick any of the 5 pieces The difference from earlier is that we only have
of fruit for the first slot. 3 slots, and thus don’t use all the fruit.
Fundamentals #3: The Permutation Function nPk
A: 1
in 2 B: 1
in 8 C: 1
in 16
D: 1
in 24 E: 1
in 36
Like the factorial function, you can find this on your calculator (usually
you need to press the ‘2nd Function’ button first).
We could use 5P3 to give the number of ways of picking 3 pieces of fruit
from 5, where the order in which we picked them mattered.
But we wish to disregard the order: for example, Orange-Lemon-Lime is
equivalent to a selection of Lemon-Lime-Orange. Thus each 3!
possibilities only represents one unordered selection. Thus:
𝑛!
n
Ck ¿
(𝑛 − 𝑘 ) !𝑘 !
We rarely write nCk in practice – instead we’d write
n n
( ) 0 = 1? ( )
1 = n?
n n(n-1) n
( ) 2 =
2
? ( )
n = 1?
Fundamentals #4: The ‘Choose’ Function nCk
Its use in Binomial Expansion
You may have encountered the use of the ‘choose’ function as a Binomial
Coefficient – the coefficients of each term in a polynomial resulting from the
expansion of a bracket with two items in it and to some power.
4 4 4 3 4 2 4 4
(1+x) = (
4
0 )x
+ ( + ( 1 )x 2 )x + ( 3)x +( 4)1
= x4 + 4x3 + 6x2 + 4x + 1
If we consider all the brackets and what happens when we expand, how many x 2
terms will we see? Recall that to expand brackets, we consider all possible choices
when we pick 1 item from each bracket.
These four items multiplied
together will give an x2 term.
(1+x)4 = (1+x)(1+x)(1+x)(1+x)
Similarly, these will give an x2
term.
Fundamentals #4: The ‘Choose’ Function nCk
Its use in Binomial Expansion
(1+x)4 = (1+x)(1+x)(1+x)(1+x)
There’s 4 brackets from which we could choose the two x terms needed to make x2
(and from the brackets we don’t choose from, we use a 1), so we’ll end up with ( 42)
x2 terms in the expansion!
#5: Distinguishable vs Undistinguishable
Consider 3 blue balls and 4 orange. How many ways are there of arranging
them in a line?
If the balls are all Then we can tell them all apart. And thus, there’s
distinguishable... simply 7! ways of arranging them.
If the balls are Then we can’t tell balls of the same colour apart.
indistinguishable... Then the problem is slightly more complicated...
Sometimes, a question will explicitly state whether objects are distinguishable or not.
If not, then use your common sense. For this particular example, the fact it’s
mentioned groups of balls that share a property (i.e. colour) suggests you can’t tell
them apart within that group.
#6: Ordered vs Unordered
Recall that ‘ordering’ relates to whether the order in which the items are
selected matter. The ‘choose’ function was the unordered cousin of the
‘permutation’ function for example.
Sometimes problems have multiple approaches:
p(win) = 1_ _
49
C6
#6: Ordered vs Unordered
Question: Calculate the probability of winning the UK lottery, where you choose 6 distinct
numbers from 1 to 49 for your ticket.
These approaches are subtly different, even if they end up with the same probability.
While in this particular case, approach (a) seems simpler, in combinatoric problems where
we have a mixture of ordered and unordered items, or distinguishable and
indistinguishable, then the latter ‘ordered’ approach might be required.
#7: Probabilistic vs Combinatoric Approaches
6 1
4
_18_
p(different numbers) = ?
25
#7: Probabilistic vs Combinatoric Approaches
The probabilistic approach The combinatoric approach
You have a bowl of 3 pieces of fruit. How many ways are there of
making a selection of fruits from the bowl (you can include the
possibility that you pick no fruit).
Answer = 8?
Tip #1: Converting problems into slot filling ones
The ‘choose’ approach The slot filling approach
( 31 ) = 3
Or we can choose 2 pieces of fruit:
3
( )=3
2 Give each piece of fruit a ‘slot’.
Each fruit can either:
Or we can choose all 3 pieces of fruit:
a) Be chosen
3 b) Not be chosen
( )=1
3
Or choose none of them: Thus each slot has 2 possible states.
This identity can also be seen by looking at the sum of each row in Pascal’s triangle:
2 2 2
( ) ( ) ( )
0 1 2
1 Sum = 1 = 20
1 1 Sum = 2 = 21
1 2 1 Sum = 4 = 22
1 3 3 1 Sum = 8 = 23
1 4 6 4 1
1 5 10 10 5 1
Tip #1: Converting problems into slot filling ones
?
for the number of oranges.
We can have 0-5 apples (6 possibilities) and 0-3
oranges (4 possibilities).
Question: How many ways can we pick at least 2 different kinds of fruit from a bowl,
given there are 3 apples, 2 oranges, 1 plum and 9 limes?
x3 x2 x1 x9
Answer = 224
?
Tip #2: Purposely overcounting
Question: How many ways can we pick at least 2 different kinds of fruit from a bowl?
x3 x2 x1 x9
Horrendously cumbersome approach ‘Overcounting’ approach
To Kill a Mockingbird
Sense and Sensibility
Pride and Predudice
Bradley Wiggins: My
Catcher in the Rye
Grapes of Wrath
Time
?
Answer: 10,080
Explanation:
There’s 7 ways in which the two red books can appear together. Then, we can arrange the 2 red books in 2!
ways, and the 6 non-red books in 6! ways. That gives 7 x 2! x 6! = 10,080 ways. ?
Tip #3: Typed objects
?
Answer: 14,400
Explanation:
Put the non-sisters in a line first. There’s 6 possible positions the 3 sisters can slot themselves into to avoid sitting next
to each other. That’s 6C3 = 20 possible ways we can allocate the sister seats. Then there’s 3! arrangements of sisters in
these seats, and 5! arrangements of the non-sisters in their non-sister seats. 20 x 3! x 5! = 14,400
Tip #3: Typed objects
BEWARE!
If we worked out the number of ways in which the sisters ARE allowed to
all sit together (i.e. 6 x 3! x 5!), you might think we can subtract this from
all possible arrangements (8!) to get the arrangements in which they
don’t sit together. But that would only give us the arrangement in which
they don’t ALL sit together, not the arrangements in which NONE of them
sit together.
Tip #3: Typed objects
Explanation: Observe that of the 8 slots to put the balls into, we choose 3 of them to
be red slots. Or equivalently, there’s 8! ways to arrange the 8 balls, but the red are
indistinguishable so we divide by 3!, and the yellows are indistinguishable, so we
divide by 5!
Unlike the previous problem where the sisters/red books were distinguishable, here
they are not.
Tip #4: Objects in a ring
When objects are put in the circle, this affects problems involving objects
being adjacent/not adjacent, since the line no longer has ends.
Answer (b): ?
It’s more complicated to allocate non-sister seats now. We can’t just place
the 5 non-sister seats then insert the sister seats around them, because we
don’t end up with a clear ‘orientation’ of the circle. There are 16 ways to
allocate sister and non-sister seats. See the next slide for a nicer approach
(courtesy of a Year 11 student!)
Tip #4: Objects in a ring
When objects are put in the circle, this affects problems involving objects
being adjacent/not adjacent, since the line no longer has ends.
Question: There are 8 seats in a circle,
with 3 sisters. Find the number of
arrangements when the sisters:
S (a) want to sit next to each
N (b) don’t want to sit next to each
N
other.
If
we used our usual ‘assign categories to objects first’
approach, it’s slightly harder to count the 16 ways to
allocate sister/non-sister seats (but there are various
approaches).
An alternative approach is to first ‘fix’ the circle
orientation by placing a specific sister in one of the 8 seats
(without loss of generality, say at the top). We need to
place a non-sister either side. Then using a similar
approach we used for the line, we can insert extra seats
for the sisters in one of 4 available slots around the non-
sister seats: we have 4 choices for the second sister and 3
for the first. This gives places for the specific sisters. We
then clearly have 5! ways of allocating non-sisters to their
seats.
Tip #5: Currency Problems
A particular favourite in IMC/SMC papers is determining how many ways an
amount can be made up using certain coinage.
A: 1326
B: 2500
C: 2601
D: 5050
E: 10000
Strategy: Fix the number of say £2
coins, and then consider how many
ways there are of making up the
remaining amount using £1 and 50p
coins using the same method. Try to
spot the pattern as we increase the
number of £2 coins.
Tip #5: Currency Problems
A particular favourite in IMC/SMC papers is determining how many ways an
amount can be made up using certain coinage.
£0 left to make
X 20 up with £1 and 1 way.
50p coins.
1 + 3 + 5 + ... + 99 + 101
This is an arithmetic series with a = 1, d = 2, n = 51, so Sn = ½ x 51 x (2 + 50 x 2) = 2601
Be careful about getting n right: notice that if we added 1 to all the terms and divided
by 2, we’d have the numbers 1, 2, 3, ..., 50, 51, so n = 51.
Important note: Notice that we never even had to consider the 50p coins, since by
fixing the number of £2 and £1 coins, the number of 50p coins is therefore
determined from the remaining amount. We therefore just concentrate on making
up amounts LESS OR EQUAL TO £100 with just £2 and £1 coins*, making the problem
less daunting.
* This would only not work if the remaining amount to make up with the smallest value coin is not a
multiple of the coin’s value. e.g. If the coins were just 3p and 2p and the total to make up was 15p, then
it’s not enough to just consider fixing the number of 3p coins as two and making up the rest with 2p
coins, because it can’t be done!
Tip #6: Multi-step combinatoric problems
For arrangement problems involving multiple steps:
(a) Have a clear starting point. (b) Be careful not to overcount/undercount.
Answer (i):32 ?
Adrian teaches a class of six pairs of twins. He wishes to set up teams for a quiz, but
wants to avoid putting any pair of twins into the same team. Subject to this condition:
i) In how many ways can he split them into two teams of six?
ii) In how many ways can he split them into three teams of four?
i) Starting Point: Team 1 must contain one of each of the twins (since we can’t
have both of any pair of twins). For each of the twins we
have 2 choices, so that’s 26 ways of picking.
Further manipulation The teams are indistinguishable (i.e. we don’t have have
to avoid overcounting: team names ‘Team 1’ and ‘Team 2’ – if all of Team 1 moved
to Team 2 and vice versa, it would be considered the same
possibility). So each 2 possibilities only counts as 1.
That gives 26 / 2 = 25 = 32 possibilities.
Tip #6: Multi-step combinatoric problems
For arrangement problems involving multiple steps:
(a) Have a clear starting point. (b) Be careful not to overcount/undercount.
Answer:
(2n)!
? n
n! 2
h i s i s p art of a
Yes, t uestion
!
n d 2 q
Rou
anic!
Don’t p
BMO
Round 2
Round 1
Tip #6: Multi-step combinatoric problems
For arrangement problems involving multiple steps:
(a) Have a clear starting point. (b) Be careful not to overcount/undercount.
Question: How many ways 2n people can be paired off to form n teams of 2.
Starting Point: Of the 2n people, pick n of them to form the first person in
each team. There’s 2nCn ways of picking them.
There are 3 fundamental steps to solving such problems. The first is as such:
1. Identifying the State What variables can we use to define the current
and Actions situation? (known as the current ‘state’)
What actions are available in a given state, and
what states do each of them they lead to?
#1 – Identifying the State and Actions
1. Identifying the State What variables can we use to define the current
and Actions situation? (known as the current ‘state’)
What actions are available in a given state, and
what states do each of these options lead to?
State: The number of lily pads in front of the frog. Let’s represent this using
a variable n.
?
Actions: 2 possible actions:
? there’s n-1 lily pads remaining.
a. Hop: We’re now in a state where
b. Skip: We’re now in a state where there’s n-2 lily pads remaining.
#1 – Identifying the State and Actions
State: The number of lily pads in front of the frog. Let’s represent this using
a variable n.
Actions: 2 possible actions:
a. Hop: We’re now in a state where there’s n-1 lily pads remaining.
b. Skip: We’re now in a state where there’s n-2 lily pads remaining.
Hop Hop
Pads left Pads left
Hop = n-1
Skip =0
ip
Sk
Pads left
=n Skip Hop This states/action graph is known
Pads left formally as a Deterministic Finite
= n-2 Automaton. The double border of
Skip the state on the right indicates it’s
a ‘final state’ where we can stop.
#2 – Forming a Recurrence
Using our knowledge of how different actions affect the state, it’s possible to
define some combinatorial property of the problem in terms of another
(typically smaller) problem.
Let’s define a function F which defines the number of hops based on the
current state.
These are known as the base cases (i.e. considering the smallest version of the
F(0) = 1? problem, in this case when we have 0 or 1 lily pads in front). It might seem odd
that there’s 1 way to get to the final lily pad when we’re already at the final lily
F(1) = 1? pad! But we’ll see in a second that this makes things work out.
We need base cases when one or more of the actions are no longer available,
e.g. when there’s 1 lily pad left, we can no longer skip.
#2 – Forming a Recurrence
Now we form a recursive relation, where we define F(n) in terms of smaller problem(s).
Since we’re considering both the possibilities that we start with a skip and the
possibilities where we start with a hop, we add these possibilities together.
#3 – Dynamic Programming
We’ve now got a recurrence relation (with base case) from which we can work out the
number of ways of getting to the last lily pad:
We’ve now got a recurrence relation (with base case) from which we can work out the
number of ways of getting to the last lily pad:
F(0) = 1
F(0) = 1 F(1) = 1 F(1) = 1
F(2) = F(0) + F(1) = 2
F(n) = F(n-1) + F(n-2) F(3) = F(2) + F(1) = 3
F(4) = F(3) + F(2) = 5
F(5) = F(4) + F(3) = 8
Note that it’s sometimes (but not always) possible to form a position-to-term formula. The Fibonacci
Sequence (which is what we found for this problem!) has a formula involving the golden ratio.
Summary
BMO
(If you’re uncomfortable defining a base case when there’s no
questions, you could have instead used F(n,1) = n+1 since for Round 2
the 1 question we could have scored between 0 and n marks,
Round 1
i.e. n+1 different marks)
BMO Question
Now we need to compute F(10,6) since there’s a maximum of 10 F(2,2) for example is
marks and 6 questions. calculated using
F(0,1)+F(1,1)+F(2,1).
Since there’s two variables here instead of one, let’s form a table: But notice that because
F k=0 1 2 3 4 5 6 F(1,2) = F(0,1)+F(1,1), we
can calculate F(2,2) using
n=0 1 1 1 1 1 1 1 F(2,1)+F(1,2), i.e. adding
1 2 3 4 5 6 7 the values above and to
1 the left.
2 1 3 6 10 15 21 28
We can therefore rewrite
3 1 4 10 20 35 56 84 the recurrence as:
1 5 15 35 70 126 210 F(n,k) = F(n-1,k)+F(n,k-1).
4
5 1 6 21 56 126 252 462 (Interesting note – if you tilt your
head left, notice you get Pascal’s
6 1 7 28 84 210 462 924 Triangle! Therefore 16C6 would
quickly yield the correct answer
7 1 8 36 120 330 792 1716 of 8008)
4
?
And how many such paths are
3 there?
(Hint: think of each path as a sequence of
2 moves. What’s the length of all such
sequences? What are we arranging?)
1
0 ?
ζ
Topic 4 – Combinatorics
Compositions of 5:
Notice that we’ve been systematic in writing out the possibilities to ensure we
don’t accidentally miss any (by dealing with an increasingly small first number).
Partition
In contrast, with a partition, the order of the numbers doesn’t matter.
We’ve again been systematic in listing these! One of your homework questions will
be to try and form a recurrence relation for the number of partitions.
Composition
It’s possible to give an expression for the number of compositions of n. This
technique can be used for related problems which we’ll explore.
1 1 1 1 1
Fill each box with either a comma (,) or a plus (+). The comma
represents starting a new number in the composition. Then:
, ,
1 1 1 1
+ + 1
would represent 2, 1, 1, 2, i.e. 5 = 2+1+1+2. This technique covers all
possible compositions.
𝑛 (𝑛 −1)
If there’s n boxes and n balls and only one box
¿
Answer 2 𝑛− 1 is empty, then all other boxes have 1 ball
e.g. You want to buy 4 tins of drink. There’s 3 different types of drink you
can buy (Fanta, Sprite, Coke). The shop has unlimited stock of each.
Possible selection
Possible selection
Possible selection
Combinations with Repetition
We could model this using boxes and balls.
OO|O|O
combinations for
So 𝒏+𝒌 − 𝟏
objects and types: ( 𝒏
? )
Rings Revisited!
Ring problems involving indistinguishable objects tend to be quite
cumbersome, since there’s often no ‘closed form’ formula for the solution.
[SMC] How many ways are there of arrangement 4 red beads and 4
yellow beads on a bracelet*.
Answer: 8?
Similarly to the sisters problem, we place the
beads of one colour on the bracelet first, then
consider how we can add the other beads in
between.
If we start with the 4 red beads then we can fit
the yellow beads into the gaps, either 3 all in
one gap, 2 is one gap and 1 in another, or 1 in
each of the four gaps.
* Convention is that ‘bracelet’ implies that the arrangement is considered the same when we flip the bracelet
over, whereas a necklace tends to be one way up, so the arrangements would be considered distinct.
Rings Revisited!
Ring problems involving indistinguishable objects tend to be quite
cumbersome, since there’s often no ‘closed form’ formula for the solution.
[SMC] How many ways are there of arrangement 4 red beads and 4
yellow beads on a bracelet.
(4, 0, 0, 0) (2, 0, 2, 0)
This corresponds
(3, 1, 0, 0) (2, 1, 1, 0) to the diagram on
(3, 0, 1, 0) (2, 1, 0, 1) the left
(2, 2, 0, 0) (1, 1, 1, 1)
Note: The possible (a,b,c,d) look a bit like the partition of the number 4 (subject to some restrictions),
which is why having a general closed-form formula for n beads is not possible. Damn!
ζ
Topic 4 – Combinatorics
Answer: 30?
1
Answer: 6
n(n+1)(2n+1)
?
1 x 1 squares: n2 2x2 squares: (n-1)2 ... n x n squares: 1
This is the sum of the first n square numbers, which is a standard result that you
should absolutely remember!
Counting Internal Shapes
Sometimes, you get different sequences for odd and even n.
n=4
10 + 6 + 3 + 1 = 20 6+1=7
n=5 15 + 10 + 6 + 3 + 1 10 + 3 = 13
= 35
n=6
21 + 15 + 10 + 6 + 3 + 1 15 + 6 + 1 = 22
= 56
Counting Internal Shapes
Since these numbers involve the sum of triangular numbers, and the formula for
triangular numbers is quadratic, it suggests that our overall formula will be cubic.
We can use the numbers we have so far to work out the coefficients (we have 4
unknowns, so require 4 of the numbers in the sequence).
n 2 4 6 8 n 1 3 5 7
F(n) 6 27 78 170 F(n) 1 13 48 118
...
This gives
The Catalan Numbers
The Catalan Numbers are useful in solving a number of combinatorial
problems involving both shapes and trees.
XXYXYY
A prefix of a word is any sequence of letters from
the start of the word. Here the Y’s don’t
outnumber the X’s.
XXYXYY (()())
We could replace the X’s by opening brackets and Y’s by closing brackets. Thus,
the Catalan numbers also give us the number of possible valid bracketings.
Other applications: