Given a regular polygon with N sides. The task is to find the count of polygons that can be drawn from the given polygon by joining the vertices of the given polygon internally.
Input: N = 6
There is only one nested polygon i.e., Triangle whose sides are the chords of the immediate parent polygon i.e., Hexagon.
Input: N = 12
There are two nested polygons. First one is a Hexagon and second one is a Triangle. The sides of both of the nested polygons are actually chords of their immediate parent polygon.
Approach: To solve this problem observe the following:
- Polygons with a number of sides less than or equal to 5 can not produce nested polygons, i.e. polygons of sides ≤5 will always have at least one side overlapping with its nested polygon.
- Each side of a nested polygon takes two consecutive sides of the immediate parent polygon.
With the above observations, it is easy to conclude that number of sides of each nested polygon is half of the number of sides of its immediate parent polygon. So, we keep dividing N by 2, and increment the counter for nested polygons, until N becomes less than or equal to 5.
Below is the implementation of the above approach:
Time Complexity: O(log N), where N is the number of vertices in the given polygon.
Auxiliary Space: O(1)
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 one side common
- Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
- Number of cycles formed by joining vertices of n sided polygon at the center
- Count of squares that can be drawn without lifting the pencil
- Area of largest semicircle that can be drawn inside a square
- Find the remaining vertices of a square from two given vertices
- Count rectangles generated in a given rectangle by lines drawn parallel to X and Y axis from a given set of points
- Tangents between two Convex Polygons
- Count of distinct graphs that can be formed with N vertices
- Length of the perpendicular bisector of the line joining the centers of two circles
- Check if number formed by joining two Numbers is Perfect Cube
- Number of ways a convex polygon of n+2 sides can split into triangles by connecting vertices
- Area of a polygon with given n ordered vertices
- Check if a path exists in a tree with K vertices present or are at most at a distance D
- Minimum initial vertices to traverse whole matrix with given conditions
- Number of Simple Graph with N Vertices and M Edges
- Find the cordinates of the fourth vertex of a rectangle with given 3 vertices
- Maximize the sum of products of the degrees between any two vertices of the tree
- Make a tree with n vertices , d diameter and at most vertex degree k
- Find the number of distinct pairs of vertices which have a distance of exactly k in a tree
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.