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 ?
Input : n = 5, m = 4 Output : 6 Out of five points, four points are collinear, we can make 6 triangles. We can choose any 2 points from 4 collinear points and use the single point as 3rd point. So total count is 4C2 = 6 Input : n = 10, m = 4 Output : 116
Number of triangles = nC3 – mC3
How does this formula work?
Consider the second example above. 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 nC3 ways.
Number of triangles formed by 10 points when no 3 of them are co-linear = 10C3……(i)
Similarly, the number of triangles formed by 4 points when no 3 of them are co-linear = 4C3……..(ii)
Since triangle formed by these 4 points are not valid, required number of triangles formed = 10C3 – 4C3 = 120 – 4 = 116
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of different straight lines with total n points with m collinear
- Count the total number of triangles after Nth operation
- Forming triangles using points on a square
- Number of triangles formed from a set of points on three lines
- Number of triangles that can be formed with given N points
- Total ways of choosing X men and Y women from a total of M men and W women
- Count the number of possible triangles
- Count number of triangles possible for the given sides range
- Count of Equilateral Triangles of unit length possible from a given Hexagon
- Maximum count of Equilateral Triangles that can be formed within given Equilateral Triangle
- Count number of unique Triangles using STL | Set 1 (Using set)
- Count number of triangles possible with length of sides not exceeding N
- Count right angled triangles in a matrix having two of its sides parallel to sides of the matrix
- Count number of triangles cut by the given horizontal and vertical line segments
- Number of Triangles in an Undirected Graph
- Number of Triangles in Directed and Undirected Graphs
- Finding the number of triangles amongst horizontal and vertical line segments
- Number of possible Triangles in a Cartesian coordinate system
- Number of triangles after N moves
- Find all possible triangles with XOR of sides zero
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
Improved By : chitranayal