Given a convex polygon with n+2 sides. The task is to calculate the number of ways in which triangles can be formed by connecting vertices with non-crossing line segments.
Input: n = 1
It is already a triangle so it can only be formed in 1 way.
Input: n = 2
It can be cut into 2 triangles by using either pair of opposite vertices.
The above problem is an application of a catalan numbers. So, the task is to only find the n’th Catalan Number. First few catalan numbers are 1 1 2 5 14 42 132 429 1430 4862, … (considered from 0th number)
Below is the program to find Nth catalan number:
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.
- Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
- Polygon with maximum sides that can be inscribed in an N-sided regular polygon
- Check if given polygon is a convex polygon or not
- Count right angled triangles in a matrix having two of its sides parallel to sides of the matrix
- Number of triangles formed by joining vertices of n-sided polygon with one side common
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Check whether two convex regular polygon have same center or not
- Check if the given point lies inside given N points of a Convex Polygon
- Count number of triangles possible for the given sides range
- Count number of triangles possible with length of sides not exceeding N
- Number of occurrences of a given angle formed using 3 vertices of a n-sided regular polygon
- Number of cycles formed by joining vertices of n sided polygon at the center
- Number of cycles in a Polygon with lines from Centroid to Vertices
- Find the remaining vertices of a square from two given vertices
- Check if it is possible to create a polygon with given n sides
- Minimum side of square embedded in Regular polygon with N sides
- Angle between 3 given vertices in a n-sided regular polygon
- Count of ways to split a given number into prime segments
- Count of ways to split an Array into three contiguous Subarrays having increasing Sum
- Count of ways to split N into Triplets forming a Triangle
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.