Given N‘, the number of non-parallel lines. The task is to find the maximum number of regions in which these lines can divide a plane.
Input : N = 3
Output : 7
Input : N = 2
Output : 4
Approach : The above image shows the maximum number of regions a line can divide a plane. One line can divide a plane into two regions, two non-parallel lines can divide a plane into 4 regions and three non-parallel lines can divide into 7 regions and so on. When the nth line is added to a cluster of (n-1) lines then the maximum number of extra regions formed is equal to n.
Now solve the recursion as follows:
L(2) – L(1) = 2 … (i)
L(3) – L(2) = 3 … (ii)
L(4) – L(3) = 4 … (iii)
. . .
. . .
L(n) – L(n-1) = n ; … (n)
Adding all the above equation we get,
L(n) – L(1) = 2 + 3 + 4 + 5 + 6 + 7 + …… + n ;
L(n) = L(1) + 2 + 3 + 4 + 5 + 6 + 7 + …… + n ;
L(n) = 2 + 2 + 3 + 4 + 5 + 6 + 7 + …… + n ;
L(n) = 1 + 2 + 3 + 4 + 5 + 6 + 7 + …… + n + 1 ;
L(n) = n ( n + 1 ) / 2 + 1 ;
The number of region in which N non-parallel lines can divide a plane is equal to N*( N + 1 )/2 + 1.
Below is the implementation of the above approach:
Time Complexity : 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 that can be formed given a set of lines in Euclidean Plane
- Count of intersections of M line segments with N vertical lines in XY plane
- Check if a line at 45 degree can divide the plane into two equal weight parts
- Python - Find the maximum number of triangles with given points on three lines
- Divide a number into two parts such that sum of digits is maximum
- Find the maximum value of Y for a given X from given set of lines
- Maximum distance between two points in coordinate plane using Rotating Caliper's Method
- Maximum points of intersection n lines
- Program to find the number of region in Planar Graph
- Maximum distinct lines passing through a single point
- Maximum points of intersections possible among X circles and Y straight lines
- Number of triangles in a plane if no more than two points are collinear
- Divide cuboid into cubes such that sum of volumes is maximum
- Number of jump required of given length to reach a point of form (d, 0) from origin in 2D plane
- Number of triangles formed from a set of points on three lines
- Number of lines from given N points not parallel to X or Y axis
- Divide array in two maximum equal length arrays of similar and dissimilar elements
- Number of pairs of lines having integer intersection points
- Count number of pairs of lines intersecting at a Point
- Number of cycles in a Polygon with lines from Centroid to Vertices
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.