Maximum points of intersection n circles
Given a number n, we need to find the maximum number of times n circles intersect.
Examples:
Input : n = 2
Output : 2
Input : n = 3
Output : 6
Description and Derivation
As we can see in above diagram, for each pair of circles, there can be maximum two intersection points. Therefore if we have n circles then there can be nC2 pairs of circles in which each pair will have two intersections. So by this, we can conclude that by looking at all possible pairs of circles the mathematical formula can be made for the maximum number of intersections by n circles is given by 2 * nC2.
2 * nC2 = 2 * n * (n – 1)/2 = n * (n-1)
C++
#include <bits/stdc++.h>
using namespace std;
int intersection( int n)
{
return n * (n - 1);
}
int main()
{
cout << intersection(3) << endl;
return 0;
}
|
Java
import java.io.*;
public class GFG {
static int intersection( int n)
{
return n * (n - 1 );
}
public static void main(String[] args) throws IOException
{
System.out.println(intersection( 3 ));
}
}
|
Python3
def intersection(n):
return n * (n - 1 );
print (intersection( 3 ))
|
C#
using System;
class GFG {
static int intersection( int n)
{
return n * (n - 1);
}
public static void Main()
{
Console.WriteLine(intersection(3));
}
}
|
PHP
<?php
function intersection( $n )
{
return $n * ( $n - 1);
}
echo intersection(3);
?>
|
Javascript
<script>
function intersection(n)
{
return n * (n - 1);
}
document.write(intersection(3));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
07 Oct, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...