Program to find the number of region in Planar Graph
Given two integers V and E which represent the number of Vertices and Edges of a Planar Graph. The Task is to find the number of regions of that planar graph.
Planar Graph: A planar graph is one in which no edges cross each other or a graph that can be drawn on a plane without edges crossing is called planar graph.
Region: When a planar graph is drawn without edges crossing, the edges and vertices of the graph divide the plane into regions.
Examples:
Input: V = 4, E = 5
Output: R = 3
Input: V = 3, E = 3
Output: R = 2
Approach: Euler found out the number of regions in a planar graph as a function of the number of vertices and number of edges in the graph i.e.
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
int Regions( int Vertices, int Edges)
{
int R = Edges + 2 - Vertices;
return R;
}
int main()
{
int V = 5, E = 7;
cout << Regions(V, E);
return 0;
}
|
Java
import java.io.*;
class GFG {
static int Regions( int Vertices, int Edges)
{
int R = Edges + 2 - Vertices;
return R;
}
public static void main(String[] args)
{
int V = 5 , E = 7 ;
System.out.println(Regions(V, E));
}
}
|
Python3
def Regions(Vertices, Edges) :
R = Edges + 2 - Vertices;
return R;
if __name__ = = "__main__" :
V = 5 ; E = 7 ;
print (Regions(V, E));
|
C#
using System;
class GFG {
static int Regions( int Vertices, int Edges)
{
int R = Edges + 2 - Vertices;
return R;
}
static public void Main()
{
int V = 5, E = 7;
Console.WriteLine(Regions(V, E));
}
}
|
PHP
<?php
function Regions( $Vertices , $Edges )
{
$R = $Edges + 2 - $Vertices ;
return $R ;
}
$V = 5; $E = 7;
echo (Regions( $V , $E ));
?>
|
Javascript
<script>
function Regions(Vertices, Edges)
{
var R = Edges + 2 - Vertices;
return R;
}
var V = 5, E = 7;
document.write( Regions(V, E));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
07 Jun, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...