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:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
- Number of triangles formed by joining vertices of n-sided polygon with one side common
- Count number of triangles possible for the given sides range
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Number of occurrences of a given angle formed using 3 vertices of a n-sided regular polygon
- Check whether two convex regular polygon have same center or not
- Check if it is possible to create a polygon with given n sides
- Number of ways to split a binary number such that every part is divisible by 2
- Number of ways to split N as sum of K numbers from the given range
- Angle between 3 given vertices in a n-sided regular polygon
- Count the number of possible triangles
- Number of triangles after N moves
- Count number of right triangles possible with a given perimeter
- Number of triangles that can be formed with given N points
- Number of trees whose sum of degrees of all the vertices is L
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.