# Problem on permutations and combinations | Set 2

Prerequisite : Permutation and Combination

**Given a polygon of m sides, count number of triangles that can be formed using vertices of polygon.**

Answer : [m (m – 1)(m – 2) / 6]

Explanation : There are m vertices in a polygon with m sides. We need to count different combinations of three points chosen from m. So answer is^{m}C_{3}= m * (m – 1) * (m – 2) / 6

Examples :

Input: m = 3

Output: 1

We put value of m = 3, we get required no. of triangles = 3 * 2 * 1 / 6 = 1Input : m = 6

output : 20

**Given a polygon of m sides, count number of diagonals that can be formed using vertices of polygon.**

Answer : [m (m – 3)] / 2.

Explanation : We need to choose two vertices from polygon. We can choose first vertex m ways. We can choose second vertex in m-3 ways (Note that we can not choose adjacent two vertices to form a diagonal). So total number is m * (m – 3). This is twice the total number of combinations as we consider an diagonal edge u-v twice (u-v and v-u)

Examples:

Input m = 4

output: 2

We put the value of m = 4, we get the number of required diagonals = 4 * (4 – 3) / 2 = 2Input: m = 5

Output: 5

** Count the total number rectangles that can be formed using m vertical lines and n horizontal lines**

Answer : (

^{m}C_{2}*^{n}C_{2}).

We need to choose two vertical lines and two horizontal lines. Since the vertical and horizontal lines are chosen independently, we multiply the result.

Examples:

Input: m = 2, n = 2

Output: 1

We have the total no of rectangles

=^{2}C_{2}*^{2}C_{2}

= 1 * 1 = 1Input: m = 4, n = 4

Output: 36

**There are ‘n’ points in a plane, out of which ‘m’ points are co-linear. Find the number of triangles formed by the points as vertices ?**

Number of triangles =

^{n}C_{3}–^{m}C_{3}

Explanation : Consider the example n = 10, m = 4. There are 10 points, out of which 4 collinear. A triangle will be formed by any three of these ten points. Thus forming a triangle amounts to selecting any three of the 10 points. Three points can be selected out of the 10 points in^{n}C_{3}ways.

Number of triangles formed by 10 points when no 3 of them are co-linear =^{10}C_{3}……(i)

Similarly, the number of triangles formed by 4 points when no 3 of them are co-linear =^{4}C_{3}……..(ii)Since triangle formed by these 4 points are not valid, required number of triangles formed =

^{10}C_{3}–^{4}C_{3}= 120 – 4 = 116

**There are ‘n’ points in a plane out of which ‘m’ points are collinear, count the number of distinct straight lines formed by joining two points.**

Answer :

^{n}C_{2}–^{m}C_{2}+ 1

Explanation : Number of straight lines formed by n points when none of them are col-linear =^{n}C_{2}

Similarly, the number of straight lines formed by m points when none of them collinear =^{m}C_{2}

m points are collinear and reduce in one line. Therefore we subtract^{m}C_{2}and add 1.

Hence answer =^{n}C_{2}–^{m}C_{2}+1

Examples:

Input : n = 4, m = 3

output : 1

We apply this formula

Answer =^{4}C_{2}–^{3}C_{2}+1

= 3 – 3 + 1

= 1

**More practice questions on permutation and combination : **

Quiz on Permutation and Combination

Combination and Permutation Practice Questions

## Recommended Posts:

- itertools.combinations() module in Python to print all possible combinations
- Generate all binary permutations such that there are more or equal 1's than 0's before every point in all permutations
- Combinations with repetitions
- Combinations in a String of Digits
- Make all combinations of size k
- Iterating over all possible combinations in an Array using Bits
- Combinations from n arrays picking one element from each array
- Print all the combinations of N elements by changing sign such that their sum is divisible by M
- Permutations of a given string using STL
- Check if two arrays are permutations of each other
- All permutations of a string using iteration
- Number of palindromic permutations | Set 1
- Distinct permutations of the string | Set 2
- Missing Permutations in a list
- Permutations of string such that no two vowels are adjacent

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.