You are on page 1of 13

Donate

Stay safe, friends. Learn to code from home. Use our free 2,000 hour
curriculum.

23 APRIL 2020 / #MATHEMATICS

Permuta on and
Combina on: The Difference
Explained with Formula
Examples
Alexander Arobelidze
The fascina on with the world of Mathema cs provides a great service in my journey of
becoming a successful developer. I am excited about the idea of helping others acquire
high quality resources.
Donate

Permuta ons and Combina ons are super useful in


so many applica ons – from Computer Programming
to Probability Theory to Gene cs.

I'm going to introduce you to these two concepts side-by-side, so


you can see how useful they are.

The key difference between these two concepts is ordering. With


Permuta ons, you focus on lists of elements where their order
ma ers.

For example, I was born in 1977. That's number 1 followed by


number 9, followed by number 7, followed by number 7. In that
par cular order.

If I change the order to 7917 instead, that would be a completely


different year. Thus, the order ma ers. Donate

With Combina ons on the other hand, the focus is on groups of


elements where the order does not ma er.

Like my cup of coffee is a combina on of coffee, sugar and water.


It doesn't ma er which order I add these ingredients are in. There
may as well be water, sugar and coffee, it's s ll the same cup of
coffee. Thus, the order does not ma er.

Now let's take a closer look at these concepts.

Part 1: Permutations
Permutations Where Repetition is
Allowed
Imagine you got a new phone. As you start using this new phone, at
some point you will be asked to set up a password.

Image of a smartphone screen


The password must consist of 4 digits. Any 4 digits. And they may Donate
be repeated.

There are 10 digits in total to begin with. Those are: 0, 1, 2, 3, 4, 5,


6, 7, 8, 9. So for the first digit of your password, you have 10
choices.

Since you may use the same digit again, the number of choices for
the second digit of our password will be 10 again! Thus, choosing
two of the password digits so far, the permuta ons are 10 mes
10, or 10 x 10 = 100 or 102.

The same thinking goes for the third digit of your password. You
get to choose from the same 10 choices again. This me you will
have 10 mes 10 mes 10, or 10 x 10 x 10 = 1,000 or 103
permuta ons.

At last, for the fourth digit of the password and the same 10 digits
to choose from, we end up with 10 mes 10 mes 10 mes 10, or
10 x 10 x 10 x 10 = 10,000 or 104 permuta ons.

As you probably no ced, you had 4 choices to make and you


mul plied 10 four mes (10 x 10 x 10 x 10) to arrive at a total
number of permuta ons (10,000). If you had to choose 3 digits for
your password, you would mul ply 10 three mes. If 7, you would
do it seven mes, and so on.

But life isn't all about passwords with digits to choose from. What
if you have a birthday party and need to choose 5 colored balloons
from 20 different colors available?
Donate

Since you have 20 different colors to choose from and may choose
the same color again, forimage
eachofballoon
colored balloons
you have 20 choices. The
first balloon is 20, the second balloon is 20 mes 20, or 20 x 20 =
400 etc. For the fi h balloon you get 20 x 20 x 20 x 20 x 20 =
3,200,000 or 205 permuta ons.

Let's summarize with the general rule: when order ma ers and
repe on is allowed, if n is the number of things to choose from
(balloons, digits etc), and you choose r of them (5 balloons for the
party, 4 digits for the password, etc.), the number of permuta ons
will equal P = nr.

Permutations Where Repetition Isn't


Allowed
Next, let's consider the case where repe on is not allowed. As an
example, we will look at the planets of our solar system.
Donate

image of solar system planets


How many different ways can you arrange these 8 planets? The
planets are: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus
and Neptune. A er choosing, say, Mercury you can't choose it
again. Thus, you have to reduce the number of available choices
each me the planet is chosen.

The first choice will have 8 possibili es. The second choice will
have 8 minus 1 equals 7 possibili es, then 6, followed by 5,
followed by 4, un l we have 1 planet le in the list.

Following the logic from the previous scenario, the total number of
permuta ons is: P = 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = 40,320.

In other words, this is a product of integer 8 and all the posi ve


integers below it. This product is called Factorial and is denoted
with an exclama on point, like this: 8!

The number of permuta ons equals P = 8! or more generally P = n!


What if you only need to arrange, say, 5 out of these 8 planets Donate
instead of all of them? Then you only take the first 5 steps in our
method. Namely, P = 8 x 7 x 6 x 5 x 4 = 6,720 will be how many
ways you can arrange 5 planets out of 8.

But why stop here? Why not apply our logic to come up with a
more general formula? To make the above nota on easy to
remember for any numbers of objects, we will use a trick. In a
frac on, mul plying both numerator and denominator by the same
number (except zero), does not affect that frac on. Thus:

P(n, r) = n! / (n - r)!

Number of planets to choose from n = 8, you choose r = 5 of them.


Subs tu ng the numbers into above formula gives us P = 8! / (8 -
5)! = 8! / 3!. Same as 8 x 7 x 6 x 5 x 4 = 6,720.

From here, the result from earlier example can be derived. There,
you arranged all 8 out of 8 available planets. Using the new
formula, P = 8! / (8 - 8)! = 8! / 0!. Since, factorial of zero is agreed
to equal 1, P = 8! / 1 = 8!. Or more generally:

P = n! / (n - n)! = n! / 0! = n!.

One short and convenient nota on o en used is: P(n, r) = n! / (n -


r)! Donate

Remembering formulas is important. But what's more important for


solving real life problems is to know which formulas to use in each
situa on. Prac ce helps.

Pop quiz:

The tournament is on and six teams are


competing. First place gets gold and
second place gets silver medals. How
many distinct ways can medals be
awarded to these teams?
Choose 1 answer

30

360

720

15

Submit

Explana on: you have 6 teams to choose from. Thus n = 6. Gold


and silver together give you 2 medals to award. Thus r = 2.
Subs tu ng these numbers into your formula gives us P(6, 2) = 6! Donate
/
(6 - 2)! = 6! / 4! = 6 x 5 = 30.

Part 2. Combinations
Combinations Without Repetition
To make the comparison more vivid, let's revisit our planet
selec on example. What if you want to know just which planets
are chosen and not their order of appearance?

There you had 6,720 dis nct ways of arranging 5 out of 8 planets.
But since the order of appearance does not ma er now, many of
these ways are redundant. They are the same to us.

A group of Venus, Earth, Mars, Jupiter, Saturn is the same group as


Mars, Jupiter, Venus, Earth, Saturn and the group as Saturn, Mars,
Earth, Jupiter, Venus. These are just different sequences of the
same 5 planets.

How many groups do you have that are the same? If you choose r
planets per group, you get r! groups. For r = 5, you get r! = 5! = 120
groups.

Thus, to eliminate the unnecessary groups that are the same, you
divide the number of original 6,720 Permuta ons by 5!. The result
is 6,720 / 120 = 56.

To generalize, in order to arrive at the number of Combina ons,


you need to figure out all the Permuta ons and divide by all the
Redundancies.

Using short and convenient nota on: C(n, r) = P(n, r) / r! = n! / (r!(n


- r)!)
Donate

C(n, r) = n! / (r!(n - r)!)

And this assumes that order does not ma er and there are no
repe ons (that is – there is only one Jupiter to choose from).

Let's revisit the tournament example:

The tournament is on and six teams are


competing. First place gets gold and
second place gets silver medals. How
many groups of medal winners are
possible? Order of teams doesn't matter
Choose 1 answer

360

15

30

720

Submit
Donate

As before, you have 6 teams. Thus, n = 6. There are two medals


awarded, so r = 2. However, this me it doesn't ma er who wins
gold and who wins silver. Team gold and team silver is the same as
team silver and team gold. Subs tu ng these numbers into your
formula gives us C(6, 2) = 6! / (2!(6 - 2)!) = 6! / 2! 4! = 15.

Combinations with Repetition


To complete this ar cle, there is one case that requires special
a en on. So far in our Combina ons we assumed there was no
repe on. No two items were the same.

What if we can have repe ons? What if, as in our earlier example,
we can choose more than one balloon of the same color? If the
number of balloons to choose from is n and we choose r of them
while allowing for same colors and disregarding the order of
arrangement, we will end up with (n + r - 1)! / (r!(n - 1)!)
Combina ons.

So wrapping up, here is a table you can use to reference these


concepts and their formulas.
Donate

I hope this ar cle has helped you be er understand these two


important mathema cal concepts. Thanks for reading.
Table of formulas for Permuta ons and Combina ons

If you read this far, tweet to the author to show them you care.
Tweet a thanks

Learn to code for free. freeCodeCamp's open source curriculum


has helped more than 40,000 people get jobs as developers.
Get started

freeCodeCamp is a donor-supported tax-exempt 501(c)(3) nonprofit organiza on (United States

Federal Tax Iden fica on Number: 82-0779546)

Our mission: to help people learn to code for free. We accomplish this by crea ng thousands of

videos, ar cles, and interac ve coding lessons - all freely available to the public. We also have
thousands of freeCodeCamp study groups around the world.

Dona ons to freeCodeCamp go toward our educa on ini a ves, and help pay for servers, services,

and staff.

You can make a tax-deduc ble dona on here.

Our Nonprofit Trending Guides

About 2019 Web Developer Roadmap


p p
Donate
Alumni Network Python Tutorial

Open Source CSS Flexbox Guide

Shop JavaScript Tutorial

Support Python Example

Sponsors HTML Tutorial

Academic Honesty Linux Command Line Guide

Code of Conduct JavaScript Example

Privacy Policy Git Tutorial

Terms of Service React Tutorial

Copyright Policy Java Tutorial

Linux Tutorial

CSS Tutorial

jQuery Example

SQL Tutorial

CSS Example

React Example

Angular Tutorial

Bootstrap Example

How to Set Up SSH Keys

WordPress Tutorial

PHP Example

You might also like