Given ‘n’ vertices and ‘m’ edges of a graph. Find the minimum number and maximum number of isolated vertices that are possible in the graph.
Input : 4 2 Output : Minimum 0 Maximum 1 1--2 3--4 <---Minimum - No isolated vertex 1--2 <--- Maximum - 1 Isolated vertex i.e. 4 | 3 Input : 5 2 Output : Minimum 1 Maximum 2 1--2 3--4 5 <-- Minimum - 1 isolated vertex i.e. 5 1--2 4 5 <-- Maximum - 2 isolated vertex i.e. 4 and 5 | 3
- For minimum number of isolated vertices, we connect two vertices by only one edge. Each vertex should be only connected to one other vertex and each vertex should have degree one
Thus if the number of edges is ‘m’, and if ‘n’ vertices <=2 * 'm' edges, there is no isolated vertex and if this condition is false, there are n-2*m isolated vertices.
- For maximum number of isolated vertices, we create a polygon such that each vertex is connected to other vertex and each vertex has a diagonal with every other vertex. Thus, number of diagonals from one vertex to other vertex of n sided polygon is n*(n-3)/2 and number of edges connecting adjacent vertices is n. Thus, total number of edges is n*(n-1)/2.
Below is the implementation of above approach.
# Python3 program to find maximum/minimum
# number of isolated vertices.
# Function to find out the minimum and
# maximum number of isolated vertices
def find(n, m) :
# Condition to find out minimum
# number of isolated vertices
if (n <= 2 * m): print("Minimum ", 0) else: print("Minimum ", n - 2 * m ) # To find out maximum number of # isolated vertices # Loop to find out value of number # of vertices that are connected for i in range(1, n + 1): if (i * (i - 1) // 2 >= m):
print(“Maximum “, n – i)
# Driver Code
if __name__ == ‘__main__’:
# Number of vertices
n = 4
# Number of edges
m = 2
# Calling the function to maximum and
# minimum number of isolated vertices
# This code is contributed by
Minimum 0 Maximum 1
Time Complexity – O(n)
- Minimum number of edges between two vertices of a Graph
- Minimum number of edges between two vertices of a graph using DFS
- Count single node isolated sub-graphs in a disconnected graph
- Finding in and out degrees of all vertices in a graph
- Construct a graph from given degrees of all vertices
- Articulation Points (or Cut Vertices) in a Graph
- Number of Simple Graph with N Vertices and M Edges
- Find if there is a path between two vertices in a directed graph
- Check whether given degrees of vertices represent a Graph or Tree
- Largest subset of Graph vertices with edges of 2 or more colors
- Calculate number of nodes between two vertices in an acyclic Graph by Disjoint Union method
- Minimum Operations to make value of all vertices of the tree Zero
- Minimum initial vertices to traverse whole matrix with given conditions
- Find maximum number of edge disjoint paths between two vertices
- Find the maximum value permutation of a 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 firstname.lastname@example.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.