78
Topic 4: Combinatorics Dr J Frost ([email protected]) Last modified: 4 th August 2013

Topic 4: Combinatorics

  • Upload
    harmon

  • View
    40

  • Download
    3

Embed Size (px)

DESCRIPTION

Topic 4: Combinatorics. Dr J Frost ([email protected]) . Last modified: 4 th August 2013. Slide Guidance. Key to question types:. SMC. Senior Maths Challenge. Uni. University Interview. Questions used in university interviews (possibly Oxbridge). - PowerPoint PPT Presentation

Citation preview

Page 1: Topic 4:  Combinatorics

Topic 4: CombinatoricsDr J Frost ([email protected])

Last modified: 4th August 2013

Page 2: Topic 4:  Combinatorics

Key to question types:

SMC Senior Maths Challenge

BMO British Maths Olympiad

The level, 1 being the easiest, 5 the hardest, will be indicated.

Those with high scores in the SMC qualify for the BMO Round 1. The top hundred students from this go through to BMO Round 2.Questions in these slides will have their round indicated.

Frost A Frosty SpecialQuestions from the deep dark recesses of my head.

Uni University InterviewQuestions used in university interviews (possibly Oxbridge).

Classic ClassicWell known problems in maths.

MAT Maths Aptitude TestAdmissions test for those applying for Maths and/or Computer Science at Oxford University.

STEP STEP ExamExam used as a condition for offers to universities such as Cambridge and Bath.

Slide Guidance

Page 3: Topic 4:  Combinatorics

? Any box with a ? can be clicked to reveal the answer (this works particularly well with interactive whiteboards!).Make sure you’re viewing the slides in slideshow mode.

A: London B: Paris C: Madrid

For multiple choice questions (e.g. SMC), click your choice to reveal the answer (try below!)

Question: The capital of Spain is:

Slide Guidance

Page 4: Topic 4:  Combinatorics

Topic 4: CombinatoricsUnit 1 - Fundamentals

a. Slot Filling

b. The Factorial Function – n!

c. The Permutation Function – nPk

d. The Choose Function – nCk

e. Distinguishable vs Indistinguishable Objects

f. Ordered vs Unordered Objects

g. Probabilistic vs Combinatoric Approaches

Page 5: Topic 4:  Combinatorics

Topic 4: CombinatoricsUnit 2 – More on Counting Problems

a. Converting Problems into Slot-Filling Ones

b. Purposely Overcounting

c. Typed Problems

d. Objects in a Ring

e. Currency Problems

f. Multi-Step problems

Page 6: Topic 4:  Combinatorics

Topic 4: CombinatoricsUnit 3 – Recurrence Relations

Unit 4 – Compositions and Partitions

a. Identifying the State and Actions

b. Forming the Recurrence

c. Dynamic Programming

a. Compositions

b. Partitions

Epilogue – Geometric Arrangements

Page 7: Topic 4:  Combinatorics

ζPart 1: FundamentalsTopic 4 – Combinatorics

Here, we look at the some of the basics of combinatorics, and fundamental combinatoric operators that are commonly used.

Page 8: Topic 4:  Combinatorics

Broadly, the ‘number of ways’ of arranging things according to some structure and constraints.

“How many ways are there of matching 3 numbers on the lottery?”

“How many ways of making a selection of fruit from a bowl of 10 items?”

“How many ways can 10 people in a circle shake hands simultaneously such that no handshake crosses?”

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.

What is combinatorics?

Page 9: Topic 4:  Combinatorics

When considering the number of possible combinations, it’s often helpful to think of ordered ‘slots’ in a line that we can fill.

Example: How many outcomes are there when we simultaneously roll 5 dice?

There are 5 slots for the 5 dice. In each slot, there are 6 outcomes.

6 6 6 6 6

We just multiply the possible outcomes in each slot to get the total number of combinations.

x x x x = 65

Fundamentals #1: Slot Filling

Page 10: Topic 4:  Combinatorics

When considering the number of possible combinations, it’s often helpful to think of ordered ‘slots’ in a line that we can fill.

a) The number of ways of picking 1 card from each of 20 different packs (of standard playing cards)? 5220?

b) The number of outcomes from the throw of a die and the toss of a coin?

(Click question marks to reveal answer)

6 x 2 = 12?

c) The number of outcomes from 5 coins and 5 dice flipped/thrown simultaneously? 25 x 65 = 125?

Fundamentals #1: Slot Filling

Page 11: Topic 4:  Combinatorics

Perhaps the most key operator in combinatorics is the factorial function, where n! means “n factorial”. It tells us the number of ways of arranging distinct objects in a line.

Q: How many ways of ordering these pieces of fruit?

We use a slot filling approach:

4We could pick any of the 4 pieces of fruit for the first slot.

3We have 3 remaining fruits to choose from for the second slot.

2 1And so on

x x x = 4!

Fundamentals #2: The Factorial Function

Page 12: Topic 4:  Combinatorics

(𝑛−1 )!𝑛! =

(𝑛−1 )× (𝑛−2 )×…𝑛× (𝑛−1 )× (𝑛−2 )×…

=𝟏𝒏

Puzzle: If I throw six dice simultaneously, what’s the probability that I get a full run of 1, 2, 3, 4, 5, 6 (where the ordering of the dice does not matter).

Hint: Recall from basic probability that:

p(event) = outcomes in which this event occurstotal outcomes

p(full run) =

6!66?

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 )!𝑛!

?

Fundamentals #2: The Factorial Function

Page 13: Topic 4:  Combinatorics

0! = 1(n+1)! = (n+1)n!

Formal definition of factorial function:

Base case

Recursive case

Just for your interest...

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.

Г(6) = 5! Г(22) = 21! Г(3.5) = 3.3234 (which is between 2! and 3!)

Г(i) = -0.1549

(For example 4! = 4 x 3! )

(Note that by combining the above, 1! = 1 x 0! = 1 x 1 = 1)

Fundamentals #2: The Factorial Function

Page 14: Topic 4:  Combinatorics

Before, we were interested in how to order n things in a line.But suppose now that we’re interested in how to order k things in a line, when we can choose from n objects.

Example: How many ways to pick 3 items of fruit from amongst 5, and put them on a shelf?

5

We could pick any of the 5 pieces of fruit for the first slot.

4

The difference from earlier is that we only have 3 slots, and thus don’t use all the fruit.

3 x x = = 5P3 5!2!

Fundamentals #3: The Permutation Function nPk

Page 15: Topic 4:  Combinatorics

The cards in a set of 36 are numbered 1 to 36. The cards are shuffled and four cards are dealt. What are the chances of them being dealt in descending order?

Level 2

Level 1

Level 4

Level 5

Level 3

SMC

A: 1 in 2

B: 1 in 8 C: 1 in 16

D: 1 in 24 E: 1 in 36

Notes: If 4 (distinguishable) objects are chosen, there are 4! = 24 ways to arrange them. Only one of these possibilities has them in descending order.

(Click your choice of answer)

Fundamentals #3: The Permutation Function nPk

Page 16: Topic 4:  Combinatorics

It gives us the number of ways of putting n items into k slots.

Like the factorial function, you can find this on your calculator (usually you need to press the ‘2nd Function’ button first).

This combinatoric function tends to be seen less frequently. But we can modify it to give us something much much more common...

Fundamentals #3: The Permutation Function nPk

𝒏𝑷𝒌=𝒏!

(𝒏−𝒌 ) !

Page 17: Topic 4:  Combinatorics

Suppose again we pick k items from n, but now, the order in which we pick them doesn’t matter.

With our fruit example, we might consider how many ways we can make a selection of 3 pieces of fruit from 5.

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:

Ways of making a selection of 3 fruits

Fundamentals #4: The ‘Choose’ Function nCk

Page 18: Topic 4:  Combinatorics

nCk =

( ) ≈ 14 million. Of the 49 numbers, 6 can be chosen for a ticket, where the ordering of the numbers doesn’t matter.

Question: How many possible lottery tickets are there, if there’s 49 possible numbers a ticket consists of 6 distinct numbers?

__n!__(n-k)!k!

This is known as the ‘choose’ function, because it gives us the number of ways of ‘choosing’ k items from n. (You can again find it on a standard scientific calculator)

We rarely write nCk in practice – instead we’d write ( )nk

496 ?

Fundamentals #4: The ‘Choose’ Function nCk

Page 19: Topic 4:  Combinatorics

( )n0 = 1 ( )n

1 = n

( )n2 = n(n-1)

2

You ought to remember these special cases:(they can all be worked out using the definition of nCk)

( )nn = 1

? ?

? ?

Fundamentals #4: The ‘Choose’ Function nCk

Page 20: Topic 4:  Combinatorics

Fundamentals #4: The ‘Choose’ Function nCk Its use in Binomial Expansion

(1+x)4 = ( )x4 + ( )x3 + ( )x2 + ( )x + ( )1 = x4 + 4x3 + 6x2 + 4x + 1

40

41

42

43

44

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.

If we consider all the brackets and what happens when we expand, how many x2 terms will we see? Recall that to expand brackets, we consider all possible choices when we pick 1 item from each bracket.

(1+x)4 = (1+x)(1+x)(1+x)(1+x)

These four items multiplied together will give an x2 term.

Similarly, these will give an x2 term.

Page 21: Topic 4:  Combinatorics

Fundamentals #4: The ‘Choose’ Function nCk Its use in Binomial Expansion

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 ( ) x2 terms in the expansion!

(1+x)4 = (1+x)(1+x)(1+x)(1+x)

42

Page 22: Topic 4:  Combinatorics

Consider 3 blue balls and 4 orange. How many ways are there of arranging them in a line?

If the balls are all distinguishable...

Then we can tell them all apart. And thus, there’s simply 7! ways of arranging them.

If the balls are indistinguishable...

Then we can’t tell balls of the same colour apart. 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.

#5: Distinguishable vs Undistinguishable

Page 23: Topic 4:  Combinatorics

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:

Question: Calculate the probability of winning the UK lottery, where you choose 6 distinct numbers from 1 to 49 for your ticket, and 6 numbers are drawn from the machine (i.e. Ignoring the ‘bonus ball’).

a) The unordered approachIf at no point do we consider the balls ordered, then:

p(win) =

Total possible tickets 49C6Winning outcomes 1 (because only one unordered choice of numbers can win)

_1_49C6

#6: Ordered vs Unordered

Page 24: Topic 4:  Combinatorics

#6: Ordered vs Unordered

b) The ordered approach

Question: Calculate the probability of winning the UK lottery, where you choose 6 distinct numbers from 1 to 49 for your ticket.

p(win) = = = =

Consider the numbers on a lottery ticket as ordered (since the balls from the machine are drawn in a particular order!). Then:

Total possible tickets 49P6 (because we’re considering ordering)Winning outcomes 6! (because if the winning numbers were 13-3-9-40-24-1 in the

order that they were drawn, then any of the 6! arrangements of these would win)

_6!_49P6

_6!_49!/43!

_1_49C6

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.

_43!6!_49

Page 25: Topic 4:  Combinatorics

Question: 3 men each independently pick a number between 1 and 10. What’s the probability that their numbers are different?

4 6 1

p(different numbers) =

_18_25?

#7: Probabilistic vs Combinatoric Approaches

Page 26: Topic 4:  Combinatorics

#7: Probabilistic vs Combinatoric ApproachesThe probabilistic approach The combinatoric approach

Consider the men one at a time, and consider the probability that their number doesn’t clash with the previous men’s choice.

Hammond goes first:

p(number doesn’t clash) = 1

Because there’s no previous men!

May goes second:

p(number doesn’t clash) = 910

Clarkson goes last:

p(number doesn’t clash) = 810

9 of the 10 numbers won’t be the same as Hammond’s

p(all numbers different) = 1 x x = 910

810

1825

(We’re of course making an independence assumption here: i.e. the men’s choices of numbers didn’t influence the others.)

Total outcomes: 103

Note that this is the total number of ordered

choices.

Outcomes in which numbers are different:The number of ways of choosing 3 numbers from 10 (but to be consistent, we have to consider their order), i.e. 10P3

p(all numbers different) =10𝑃3103

=1825

Note: Whenever we want to consider distinct choices of items, you should always immediately think to use the ‘choose’ function.

Page 27: Topic 4:  Combinatorics

ζPart 2: More on Counting ProblemsTopic 4 – Combinatorics

Here, we drill in to the types of counting problems that are frequently seen, and strategies to deal with each one.

Page 28: Topic 4:  Combinatorics

Answer = 8

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).

?

Tip #1: Converting problems into slot filling ones

Page 29: Topic 4:  Combinatorics

The ‘choose’ approach The slot filling approach

In our selection, we can just choose 1 piece of fruit:

( ) = 3Or we can choose 2 pieces of fruit:

Or we can choose all 3 pieces of fruit:

Or choose none of them:

Give each piece of fruit a ‘slot’. Each fruit can either:a) Be chosenb) Not be chosen

Thus each slot has 2 possible states.

This gives 23 = 8 possibilities.

31

( ) = 332

( ) = 133

( ) = 130

This approach is clearly much simpler!

Tip #1: Converting problems into slot filling ones

Page 30: Topic 4:  Combinatorics

The fact either approach to this fruit problem gives the same answer yields a nice identity!

Using ‘slot based’ approach for n fruits.

Using ‘choose’ approach for n fruits.

This identity can also be seen by looking at the sum of each row in Pascal’s triangle:

11 1

1 2 11 3 3 1

1 4 6 4 11 5 10 10 5 1

Sum = 1 = 20

Sum = 2 = 21

Sum = 4 = 22

Sum = 8 = 23

21( )2

0( ) 22( )

Tip #1: Converting problems into slot filling ones

Page 31: Topic 4:  Combinatorics

Answer = 24

How many ways of making a selection of fruits from 5 apples and 3 oranges?

This time, anything other than a ‘slot based’ approach will cause a massive amount of headache.Have a slot for the number of apples, and a slot for the number of oranges.We can have 0-5 apples (6 possibilities) and 0-3 oranges (4 possibilities).

So 6 x 4 = 24 possibilities (or 23 if we exclude the case where we pick no fruit)

?

Tip #1: Converting problems into slot filling ones

Page 32: Topic 4:  Combinatorics

Tip #2: Purposely overcounting

x 3 x 2 x 1 x 9

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?

Answer = 224 ?

Sometimes it’s easier to consider more possibilities than we initially need (because the result is easy to calculate) before eliminating possibilities we don’t want.

Page 33: Topic 4:  Combinatorics

x 3 x 2 x 1 x 9

Horrendously cumbersome approach

Question: How many ways can we pick at least 2 different kinds of fruit from a bowl?

‘Overcounting’ approach

Work out number of ways of picking:a) 2 types of fruitb) 3 types of fruitc) 4 types of fruitAnd add together.

e.g. Ways of picking 2 types:• Only apples & oranges: 3 x 2 = 6• Only apples & plums: 3 x 1 = 3• ...Which gives 65 ways.For 3 types of fruit, it’s 105 ways.For 4 types of fruit, it’s 54 ways.Total = 65 + 105 + 54 = 224.

Consider ALL possible selections first:4 x 3 x 2 x 10 = 240

Exclude selections involving 1 type of fruit:3 + 2 + 1 + 9 = 15

Exclude selections involve no fruit:1

Total = 240 – 15 – 1 = 224

Tip #2: Purposely overcounting

Page 34: Topic 4:  Combinatorics

Tip #3: Typed objects

Question: How many ways of arranging 8 books, if you must keep the two red ones next to each other?

Answer: 10,080 ?

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.?Explanation:

Frequently, objects have certain types, e.g:Red and blue, boys and girls, sisters and non-sisters, etc.

Page 35: Topic 4:  Combinatorics

The strategy for these kinds of problems is therefore:

1. Consider the possible ways in which the slots can be assigned a particular ‘type’ (e.g. where the red books can occur according to some constraint).

2. Multiply this by the number of ways in which the objects can be arranged within these slots.

Tip #3: Typed objects

Page 36: Topic 4:  Combinatorics

Here’s a harder one:

Question: 8 people go to a cinema and sit in line. 3 of them are sisters who tend to chat if put together. How many ways are there of seating the 8 people if the sisters aren’t allowed to sit together?

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

Page 37: Topic 4:  Combinatorics

Here’s a harder one:

Question: 8 people go to a cinema and sit in line. 3 of them are sisters who tend to chat if put together. How many ways are there of seating the 8 people if the sisters aren’t allowed to sit together?

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

Page 38: Topic 4:  Combinatorics

Answer: 8C3 = 56

Question: How many ways if arranging 3 (indistinguishable) red balls and 5 (indistinguishable) yellow balls?

?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 #3: Typed objects

Page 39: Topic 4:  Combinatorics

Tip #4: Objects in a ringWhen 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:(a) want to sit next to each (b) don’t want to sit next to each other.

Answer (a): 5760This is exactly the same as the sisters in a line problem, except the block of 3 girls can now be in 8 different positions, giving 8 x 3! x 5!

Answer (b): 7200As before, we allocate non-sister seats first, but now there’s 5C3 ways to allocate the sister seats.

?

?

Page 40: Topic 4:  Combinatorics

Tip #5: Currency ProblemsA particular favourite in IMC/SMC papers is determining how many ways an amount can be made up using certain coinage.

Question: Given an unlimited supply of 50p, £1 and £2 coins, in how many different ways is it possible to make a sum of £100?

Level 2

Level 1

Level 4

Level 3

Level 5

SMC

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.

Page 41: Topic 4:  Combinatorics

Tip #5: Currency Problems

Question: Given an unlimited supply of 50p, £1 and £2 coins, in how many different ways is it possible to make a sum of £100?

X 20£0 left to make up with £1 and 50p coins.

1 way.

X 19 £2 left to make up Can have between 0 and 2 £1 coins.

3 ways.

X 18 £4 left to make up Can have between 0 and 4 £1 coins.

5 ways.

X 0 £100 left to make up Can have between 0 and 100 £1 coins.

101 ways.

...

A particular favourite in IMC/SMC papers is determining how many ways an amount can be made up using certain coinage.

Page 42: Topic 4:  Combinatorics

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 #5: Currency Problems

Page 43: Topic 4:  Combinatorics

Tip #6: Multi-step combinatoric problems

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?

For arrangement problems involving multiple steps:(a) Have a clear starting point. (b) Be careful not to overcount/undercount.

Round 2

Round 1

BMO

Answer (i): 32

Answer (ii): 960

?

?

Page 44: Topic 4:  Combinatorics

Tip #6: Multi-step combinatoric problems

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?

For arrangement problems involving multiple steps:(a) Have a clear starting point. (b) Be careful not to overcount/undercount.

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 to avoid overcounting:

The teams are indistinguishable (i.e. we don’t have have 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.

Page 45: Topic 4:  Combinatorics

(2n)!n! 2n

Tip #6: Multi-step combinatoric problems

Question: How many ways 2n people can be paired off to form n teams of 2.

For arrangement problems involving multiple steps:(a) Have a clear starting point. (b) Be careful not to overcount/undercount.

Round 1

Round 2

BMO

Answer: ?

Yes, this is part of a

Round 2 question!

Don’t panic!

Page 46: Topic 4:  Combinatorics

Tip #6: Multi-step combinatoric problems

Question: How many ways 2n people can be paired off to form n teams of 2.

For arrangement problems involving multiple steps:(a) Have a clear starting point. (b) Be careful not to overcount/undercount.

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.

Further manipulation to avoid overcounting:

As a second step, we have n! ways of allocating the remaining people to these teams.But we’ve overcounted, because in each team, it doesn’t matter which person was picked first, so for each team there’s 2 equivalent arrangements. Since there’s n teams, we must divide by 2n. This gives us:

(2n)!n! 2n

2nCn

n! 2n=

Note: If we initially numbered the teams 1 to n as if they were distinguishable and in a line, there would be 2nPn ways of putting n of the 2n people into these slots, then again n! ways of allocating the remaining people to these slots. But then we’d have to both divide by 2n (because of the duplication described above), but also by n!, since the teams are in fact not distinguishable, and any way we’d relabel the team names would be equivalent. This gives the same result as above.

Page 47: Topic 4:  Combinatorics

ζPart 3: Recurrence RelationsTopic 4 – Combinatorics

Here, we explore problems that can be defined in terms of another related problem (usually a smaller problem).

Page 48: Topic 4:  Combinatorics

A frog has 5 lily pads in front of him in a line. He needs to get to the final lily pad, and can do so by either by ‘hopping’ to the next lily pad, or ‘skipping’ to a lily pad 2 ahead. How many ways are there for the frog to get to the final lily pad?

There are 3 fundamental steps to solving such problems. The first is as such:

1. Identifying the State and Actions

What variables can we use to define the current situation? (known as the current ‘state’)What actions are available in a given state, and what states do each of them they lead to?

Introduction

Page 49: Topic 4:  Combinatorics

State:

1. Identifying the State and Actions

What variables can we use to define the current situation? (known as the current ‘state’)What actions are available in a given state, and what states do each of these options lead to?

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.

The number of lily pads in front of the frog. Let’s represent this using a variable n.

Actions:

#1 – Identifying the State and Actions

Page 50: Topic 4:  Combinatorics

State:

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.

The number of lily pads in front of the frog. Let’s represent this using a variable n.

Actions:

It’s possible to represent these transitions between states as a ‘state diagram’:

Pads left = n

Pads left = n-1

Pads left = n-2

Hop

Skip

Hop

Skip

Hop

Skip

Pads left = 0

Hop

Skip

This states/action graph is known formally as a Deterministic Finite Automaton. The double border of the state on the right indicates it’s a ‘final state’ where we can stop.

#1 – Identifying the State and Actions

Page 51: Topic 4:  Combinatorics

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.

F(0) = 1? These are known as the base cases (i.e. considering the smallest version of the 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 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.

F(1) = 1?

#2 – Forming a Recurrence

Page 52: Topic 4:  Combinatorics

F(n) = F(n-1) + F(n-2)?If we’d hopped, we’d be in a state where there’s n-1 lily pads, with F(n-1) ways of getting to the end (by definition of F).If we’d skipped, similarly we’d have F(n-2) ways of getting to the end.

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.

Now we form a recursive relation, where we define F(n) in terms of smaller problem(s).

Forming a recurrence is usually a case of adding together the number of ways associated with each of the subsequent states, i.e.F(current state) = F(possible next states)

#2 – Forming a Recurrence

Page 53: Topic 4:  Combinatorics

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(n) = F(n-1) + F(n-2)

F(1) = 1 We need F(5). Using our recurrence:

F(5) = F(4) + F(3) = F(3) + F(2) + F(2) + F(1) = F(2) + F(1) + F(1) + F(0) + F(1) + F(0) + F(1) = F(1) + F(0) + F(1) + F(1) + F(0) + F(1) + F(0) + F(1) = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 8

This method is computing the result is quite wasteful, because we’re having to work out F(2) multiple times for example. Instead of starting from F(5) and using our recurrence to work down, perhaps we can start from the base case(s) and work our way up?

#3 – Dynamic Programming

Page 54: Topic 4:  Combinatorics

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(n) = F(n-1) + F(n-2)

F(1) = 1 F(0) = 1F(1) = 1F(2) = F(0) + F(1) = 2F(3) = F(2) + F(1) = 3F(4) = F(3) + F(2) = 5F(5) = F(4) + F(3) = 8

By working from the bottom-up, each F(n) only had to be calculated once. This technique is known in the computing biz as dynamic programming.

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.

#3 – Dynamic Programming

Page 55: Topic 4:  Combinatorics

1. Identify the State and Actions

State: Number of lily pads left.Actions available: Hop (where in new state, we have 1 lily pad less) or skip (where we have 2 lily pads less)

2. Forming a recurrence Define a function F(state)F(current state) = F(possible next states)

Base cases: F(1) = 1, F(0) = 1Recurrence: F(n) = F(n-1) + F(n-2)

For problems of size 0 (e.g. no lily pads left), the number of ways tends to be 1.

3. Computing the desired value.

Find F(state described in problem)Work out the value for problems of ascending size (i.e. working from the ‘bottom up’). If the state has two variables, form a table.

F(0) = 1, F(1) = 1, F(2) = 2, F(3) = 3, F(4) = 5, F(5) = 8.

Summary

Page 56: Topic 4:  Combinatorics

Isaac attempts all six questions on an Olympiad paper in order. Each question is marked on a scale from 0 to 10. He never scores more in a later question than in any earlier question. How many different possible sequences of six marks can he achieve?

Round 2

Round 1

BMO

State:

•For the next question, score the maximum of n marks. We’re left in a state where we have k-1 questions left, and the maximum mark is still n.•Or for the next question, score n-1 marks. We’re left in a state where we have k-1 questions left, and the maximum mark is now k-1 (because we’re not allowed to score higher than the previous question).•...and so on...•Or for the next question, we score 0 marks. For the remaining k-1 questions, the maximum mark is now 0 for the remaining questions.

Consider the state just before you answer a question:n – the maximum mark for the remaining questions.k – the number of questions left

Actions:

?

?

BMO Question

Page 57: Topic 4:  Combinatorics

Isaac attempts all six questions on an Olympiad paper in order. Each question is marked on a scale from 0 to 10. He never scores more in a later question than in any earlier question. How many different possible sequences of six marks can he achieve?

Round 2

Round 1

BMO

Step 2 is to convert this information into a recurrence relation.

F(n,k) = F(n, k-1) We include all the possibilities where we lose no marks on the next question. Then we’re interested in the number of ways of scoring up to n marks for the remaining k-1 questions.

+ F(n-1, k-1) We also include the possibilities where we get one less than the maximum mark on the next question. Then for the remaining k-1 questions, we’re not allowed to exceed n-1 marks.

+ F(0, k-1)And so on...+ ...

BMO Question

Page 58: Topic 4:  Combinatorics

Isaac attempts all six questions on an Olympiad paper in order. Each question is marked on a scale from 0 to 10. He never scores more in a later question than in any earlier question. How many different possible sequences of six marks can he achieve?

Round 2

Round 1

BMO

Now deal with base cases...

F(n,0) = 1 When there’s 0 questions left, we say there’s 1 way of doing this (as we usually say for ‘empty’ problems).

(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 the 1 question we could have scored between 0 and n marks, i.e. n+1 different marks)

F(0,k) = 1 If the maximum mark is 0, there’s only 1 possible set of marks we can get: a string of 0s!

?

?

BMO Question

Page 59: Topic 4:  Combinatorics

Round 2

Round 1

BMO

Now we need to compute F(10,6) since there’s a maximum of 10 marks and 6 questions.Since there’s two variables here instead of one, let’s form a table:

F k=0 1 2 3 4 5 6

n=0 1 1 1 1 1 1 1

1 1 2 3 4 5 6 7

2 1 3 6 10 15 21 28

3 1 4 10 20 35 56 84

4 1 5 15 35 70 126 210

5 1 6 21 56 126 252 462

6 1 7 28 84 210 462 924

7 1 8 36 120 330 792 1716

8 1 9 45 165 495 1287 3003

9 1 10 55 220 715 2002 5005

10 1 11 66 286 1001 3003 8008

F(2,2) for example is calculated using F(0,1)+F(1,1)+F(2,1).But notice that because F(1,2) = F(0,1)+F(1,1), we can calculate F(2,2) using F(2,1)+F(1,2), i.e. adding the values above and to the left.

We can therefore rewrite the recurrence as:F(n,k) = F(n-1,k)+F(n,k-1).

(Interesting note – if you tilt your head left, notice you get Pascal’s Triangle! Therefore 16C6 would quickly yield the correct answer of 8008)

These are the triangular numbers!

These are the tetrahedric numbers!

These are the pentatope numbers!

BMO Question

Page 60: Topic 4:  Combinatorics

BMO Question

10

9

8

7

6

5

4

3

2

1

0

Score

Question0 1 2 3 4 5 6

But there’s a ridiculously elegant alternative that uses a more combinatorial approach.

Imagine a path through a network like on the left, where only right and down movements are allowed.

What question scores does this path represent?

And how many such paths are there? (Hint: think of each path as a sequence of moves. What’s the length of all such

sequences? What are we arranging?)

?

?

Page 61: Topic 4:  Combinatorics

ζPart 4: Compositions and PartitionsTopic 4 – Combinatorics

Some problems concern how many ways we can divide something up into parts. For example, how many ways can we express the number 4 as the sum of positive integers? (e.g. 3 + 1, 1 + 2 + 1, ...)

Page 62: Topic 4:  Combinatorics

CompositionA composition of an integer n is the number of ways of expressing it as a sum of (strictly) positive integers.

Compositions of 5:

54+13+23+1+12+32+2+12+1+22+1+1+1

1+41+3+11+2+21+2+1+11+1+31+1+2+11+1+1+21+1+1+1+1

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).

The order of the numbers matters, so 4+1 is a distinct composition from 1+4.

Page 63: Topic 4:  Combinatorics

PartitionIn contrast, with a partition, the order of the numbers doesn’t matter.

Partitions of 5:

54+13+23+1+12+2+12+1+1+11+1+1+1+1

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.

The order of the numbers matters, so 4+1 is a distinct composition from 1+4.

There’s no ‘closed form’ expression that will give the number of partitions for a number n. This means there’s no expression in terms of common mathematical operations and functions: addition, multiplication, exponentiation, log, sin, etc.

Page 64: Topic 4:  Combinatorics

CompositionIt’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

If we’re considering the compositions of 5, which out five 1s separated by spaces:

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.

There’s n-1 gaps (or ‘slots’), so there’s 2n-1 compositions of n.

Page 65: Topic 4:  Combinatorics

n(n-1)2n-1Cn

CompositionWe can use a similar technique to represent the ‘wall boundaries’ between boxes and related problems.

Question: Suppose that n balls are placed at random into n boxes. Find the probability that there is exactly one empty box.Big Hint: This above diagram could be represented as O|OO||O, where we have n “O” symbols and n-1 “|” wall boundary symbols.

Answer = ?

?Number of possible assignments to boxes.

Number of box assignments in which exactly one box is empty.

Page 66: Topic 4:  Combinatorics

n(n-1)2n-1Cn

CompositionWe can use a similar technique to represent the ‘wall boundaries’ between boxes and related problems.

Answer =

The above arrangement could be represented as O|OO||O by representing the box boundaries using the symbol |. Then it’s just the case of finding the number of ways of arranging n ‘O’ symbols and n-1 ‘|’ symbol. In the n+(n-1) total symbol slots, we have n positions to choose for the ‘O’s.

If there’s n boxes and n balls and only one box is empty, then all other boxes have 1 ball except for one which has 2. There’s n boxes the empty one could be, and n-1 remaining boxes the one with 2 balls could be.

Page 67: Topic 4:  Combinatorics

Combinations with RepetitionSuppose you want to choose objects where you have different types of objects to choose from, where you have an unlimited supply of each type.

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

Page 68: Topic 4:  Combinatorics

We could model this using boxes and balls.

The boxes would represent each type of drinkThe balls would represent a choice of drink

??

OO|O|OSo combinations for objects and types: (𝒏+𝒌−𝟏

𝒏 )?

Combinations with Repetition

Page 69: Topic 4:  Combinatorics

Rings Revisited!

Question: How many ways are there of arrangement 4 red beads and 4 yellow beads on a bracelet*.

* 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.

Answer: 8Similarly 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.

Ring problems involving indistinguishable objects tend to be quite cumbersome, since there’s often no ‘closed form’ formula for the solution.

?

Page 70: Topic 4:  Combinatorics

Rings Revisited!

Question: How many ways are there of arrangement 4 red beads and 4 yellow beads on a bracelet.

Let (a,b,c,d) represent the number of yellow beads in each of the four gaps. Then distinct arrangements (when we consider equivalent ones due to rotation/reflection) are:

Ring problems involving indistinguishable objects tend to be quite cumbersome, since there’s often no ‘closed form’ formula for the solution.

(4, 0, 0, 0)(3, 1, 0, 0)(3, 0, 1, 0)(2, 2, 0, 0)

(2, 0, 2, 0)(2, 1, 1, 0)(2, 1, 0, 1)(1, 1, 1, 1)

This corresponds to the diagram on the left

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!

Page 71: Topic 4:  Combinatorics

ζEpilogue: Geometric ArrangementsTopic 4 – Combinatorics

Finally, we look at problems involving shapes, and other visual structures such as trees.

Page 72: Topic 4:  Combinatorics

Counting Internal Shapes

Answer: 30

Classic Question: How many squares (of any size) are in this diagram?

When asked to find smaller shapes within a larger shape, make sure your counting is structured, in order to identify a pattern.

?

More generally, what about an n x n grid?

Answer: n(n+1)(2n+1)16 ?

1 x 1 squares: n2 2x2 squares: (n-1)2 ... n x n squares: 1This is the sum of the first n square numbers, which is a standard result that you should absolutely remember!

Page 73: Topic 4:  Combinatorics

Counting Internal ShapesSometimes, you get different sequences for odd and even n.

How many triangles?

Page 74: Topic 4:  Combinatorics

Counting Internal Shapes

1

3 + 1 = 5

6 + 3 + 1 = 10

10 + 6 + 3 + 1 = 20

1

3

6 + 1 = 7

15 + 10 + 6 + 3 + 1 = 35

10 + 3 = 13

21 + 15 + 10 + 6 + 3 + 1 = 56

-

15 + 6 + 1 = 22

Up triangles Down triangles

Notice that a new size of triangle appears every other figure. This suggests we’ll need separate formulae for odd and even n.

n=1

n=2

n=3

n=4

n=5

n=6

Page 75: Topic 4:  Combinatorics

Counting Internal Shapes

n 2 4 6 8

F(n) 6 27 78 170

n 1 3 5 7

F(n) 1 13 48 118

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).

F(n) = ax3 + bx2 + cx + d

6 = 8a + 4b + 2c + d27 = 64a + 16b + 4c + d...Solving these simultaneous equations gives us a, b, c and d.

This gives F(n) = n(n+2)(2n+1)

18

1 = a + b + c + d13 = 27a + 9b + 3c + d...

This gives F(n) = [n(n+2)(2n+1) – 1]

18

Page 76: Topic 4:  Combinatorics

The Catalan Numbers

Imagine a string of n X’s and n Y’s (giving a word of length 2n), such that for any prefix of the word, the Y’s never outnumber the X’s.

The Catalan Numbers are useful in solving a number of combinatorial problems involving both shapes and trees.

X X Y X Y Y

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.

Then the nth ‘Catalan number’ is the number of such possible words of length 2n.

Page 77: Topic 4:  Combinatorics

The Catalan Numbers

The nth Catalan number is given by:

The Catalan Numbers are useful in solving a number of combinatorial problems involving both shapes and trees.

Cn =

First few Catalan numbers:

1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, ...

_1_n+1

2nn( )

Page 78: Topic 4:  Combinatorics

The Catalan Numbers

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:

X X Y X Y Y ( ( ) ( ) )

The number of ways a convex polygon with n+2 sides can be cut into triangles:

The number of binary trees with n+1 leaves (binary meaning that each parent has 2 children):

Problem 4 on Worksheet 3 (involving non-overlapping handshakes across a table) also yields the Catalan numbers!