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++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the number ` `// of regions in a Planar Graph ` `int` `Regions(` `int` `Vertices, ` `int` `Edges) ` `{ ` ` ` `int` `R = Edges + 2 - Vertices; ` ` ` ` ` `return` `R; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `V = 5, E = 7; ` ` ` ` ` `cout << Regions(V, E); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to return the number ` ` ` `// of regions in a Planar Graph ` ` ` `static` `int` `Regions(` `int` `Vertices, ` `int` `Edges) ` ` ` `{ ` ` ` `int` `R = Edges + ` `2` `- Vertices; ` ` ` ` ` `return` `R; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` ` ` `int` `V = ` `5` `, E = ` `7` `; ` ` ` `System.out.println(Regions(V, E)); ` ` ` `} ` `} ` ` ` `// This code is contributed by akt_mit ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to return the number ` `# of regions in a Planar Graph ` `def` `Regions(Vertices, Edges) : ` ` ` ` ` `R ` `=` `Edges ` `+` `2` `-` `Vertices; ` ` ` ` ` `return` `R; ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `V ` `=` `5` `; E ` `=` `7` `; ` ` ` ` ` `print` `(Regions(V, E)); ` ` ` `# This code is contributed ` `# by AnkitRai01 ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to return the number ` ` ` `// of regions in a Planar Graph ` ` ` `static` `int` `Regions(` `int` `Vertices, ` `int` `Edges) ` ` ` `{ ` ` ` `int` `R = Edges + 2 - Vertices; ` ` ` ` ` `return` `R; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `static` `public` `void` `Main() ` ` ` `{ ` ` ` ` ` `int` `V = 5, E = 7; ` ` ` `Console.WriteLine(Regions(V, E)); ` ` ` `} ` `} ` ` ` `// This code is contributed by ajit ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// Function to return the number ` `// of regions in a Planar Graph ` `function` `Regions(` `$Vertices` `, ` `$Edges` `) ` `{ ` ` ` `$R` `= ` `$Edges` `+ 2 - ` `$Vertices` `; ` ` ` ` ` `return` `$R` `; ` `} ` ` ` `// Driver code ` `$V` `= 5; ` `$E` `= 7; ` `echo` `(Regions(` `$V` `, ` `$E` `)); ` ` ` `// This code is contributed ` `// by Code_Mech ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

4

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.

## Recommended Posts:

- Find length of the largest region in Boolean Matrix
- Find the area of the shaded region formed by the intersection of four semicircles in a square
- Maximum number of region in which N non-parallel lines can divide a plane
- Maximum number of edges that N-vertex graph can have such that graph is Triangle free | Mantel's Theorem
- Program to find total number of edges in a Complete Graph
- Graph implementation using STL for competitive programming | Set 2 (Weighted graph)
- Detect cycle in the graph using degrees of nodes of graph
- Convert the undirected graph into directed graph such that there is no path of length greater than 1
- Convert undirected connected graph to strongly connected directed graph
- Program to find Circuit Rank of an Undirected Graph
- Program to find the diameter, cycles and edges of a Wheel Graph
- Program to count Number of connected components in an undirected graph
- Find the number of paths of length K in a directed graph
- Program to Calculate the Edge Cover of a Graph
- C program to implement Adjacency Matrix of a given Graph
- Find if there is a path between two vertices in a directed graph
- Disjoint Set (Or Union-Find) | Set 1 (Detect Cycle in an Undirected Graph)
- Find k-cores of an undirected graph
- Find a Mother Vertex in a Graph
- Find minimum weight cycle in an undirected graph

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.