The Role of Permutations and Combinations in Data Science

# The Role of Permutations and Combinations in Data Science

Vikram Singh
Assistant Manager - Content
Updated on Dec 23, 2022 17:08 IST

Permutation and combination are one of the most important topics of mathematics that has application in various domain such as machine learning, computer vision etc. In this article, we have discussed what it is, its formula, and how to calculate permutation and combination in python.

Permutation and Combination is an arrangement of a certain number of items. It is mainly concerned with determining the number of different ways of arranging and selecting objects from a given number of objects without actually listing them.

A permutation is all about the arrangement of a number of an object in a definite order, whereas a Combination is all about the selection of objects where order doesn’t matter.

In simple terms, permutation is an ordered selection. This article will briefly discuss all Permutations and Combinations, their formula, and their differences.

Let’s take an example to understand Permutation and Combination better.

Let there be three balls: A, B, and C. So find the Permutation and Combination.

Case -1: Number of possibilities when order matters

A B C, A C B, B C A, B A C, C B A, C A B

Case – 2: Number of possibilities when order doesn’t matter

A B C

So, the Permutation is 6, and the Combination is 1 (as all the item is arranged in one set since order doesn’t matter).

Now, let’s dive deep to better understand Permutation and Combination.

## What is Permutation and Combination

### Permutation

A permutation is the number of ways to arrange items/objects given in a list taken, some or all at a time, in a specific order. In other words, a mathematical operation that is used to generate all the possible combinations of items of a set is called permutation.

It implies all the possible arrangements or rearrangements of a set into different orders.

Example – 1: Number of possibilities of four-digit lock.

Example – 2: Number of ways five students can sit on five chairs.

### Combination

The combination is defined as the number of ways of selecting a group of an object from a set such that the order of selection does not matters.

The combination is all about grouping.

Example – 1: Picking finalists for a TV reality show.

Example 2: Selecting four toppings for pizza from the available ten toppings.

Note:

1. In combination order of outcome does not matter.
2. If the order is taken into consideration, then the combination will be the same as the number of permutations.

## Permutation and Combination Formula

### Permutation

1. The number of permutations on a set of n elements is given by n!.
2. The number of ways of obtaining an ordered subset (permutation) of r elements from the set of n elements is:

Proof:

Let we have to arrange r object from the list of n objects, and since in permutation the order of arrangement is important, so

1st element can be arranged in n ways.

2nd element can be arranged in n-1 ways.

3rd element can be arranged in n-2 ways.

So, the r-the element can be arranged in – (– 1) ways = n – r + 1 ways

Hence, all the r-element from the set of n-elements can be arranged in

n (n – 1) (n – 2) …. (n – r + 1) ways, i.e.

Now, multiplying and dividing (n – r) in numerator and denominator, respectively, we get:

Example: Find the number of permutation of {1, 2, 3}.

Answer: The number of permutation on a set of 3 elements will be 3! = 3 x 2 x 1 = 6, namely

{1, 2, 3}, {1, 3, 2}, {2, 3, 1}, {2, 1, 3}, {3, 2, 1}, {3, 1, 2}.

### Combination

The number of ways of picking r unordered outcomes from n possibilities is:

C (n, r) = number of permutations/number of ways to arrange r

It is read as “n choose r”.

Example: Combination of 2 subsets from the set of {1, 2, 3, 4}.

There are 4C2 = 6, combinations of two elements that are form from the set of {1, 2, 3, 4}, namely

{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, and {3, 4}.

## Permutation and Combination Question

Example – 1: Let us have 15 cricket players, and we have to select 11 players for the final match. In how many ways can we select 11 players from the 15 players?

Answer: In order to select the team, the order of selection doesn’t matter, and the players can’t be selected multiple times.

So, the number of ways the final 11 players can be selected from 15 players is as follows:

Example – 2: Handshake Problem

For a group of n people, how many different handshakes are possible.

n: Number of people in the group.

r = 2: number of people involved in each different handshake

Here, it doesn’t matter whom you handshake first, so for a group of 3 people, it will count:

1 with 2, 1 with 3, and 2 with 3, but we will not count 2 with 1, 3 with 1, and 3 with 2 as they are duplicates.

So, the total number of handshakes will be

Hence, total number of different handshakes will be n(n-1)/2.

## Permutation and Combination in Python

Example – 1: Print the python program to get all the permutation of [1, 2, 3, 4] of length 3.

#Python program for Permutation
from itertools import permutations
permu = permutations([1, 2, 3, 4], 3)
#print the permutations
for i in list(permu):
print(i)

Output

Example – 2: Print the python program to get all the combination of [1, 2, 3, 4] of length 3.

#Pyton program for Combination
from itertools import combinations
comb = combinations([1, 2, 3, 4], 3)
#print the obtained combinations
for i in list(comb):
print(i)

Output

## Conclusion

In this article, we have briefly discussed permutation and combinations, formula, and how to calculate it with the help of examples.

Hope you like the article.

Top Trending Article

Interview Questions