Number of cycles in a Polygon with lines from Centroid to Vertices
Given a number N which denotes the number of sides of the polygon where the centroid of the polygon is connected with all the vertices, the task is to find the number of cycles in the polygon.
Input: N = 4
Input: N = 8
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Approach: This problem follows a simplistic approach where we can use a simple formula to find the number of cycles in Polygon with lines from Centroid to Vertices. To deduce the number of cycles we can use this formula:
(N) * (N – 1) + 1
If the value of N is 4, we can use this simple formula to find the number of Cycles which is 13. In a similar manner, if the value of N is 10, then the number of Cycles would be 91.
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiliary Space: O(1)