Given a graph with n nodes and m edges. Find the maximum possible number of nodes which are not part of any edge (m will always be less than or equal to a number of edges in complete graph).
Input: n = 3, m = 3 Output: Maximum Nodes Left Out: 0 Since it is a complete graph. Input: n = 7, m = 6 Output: Maximum Nodes Left Out: 3 We can construct a complete graph on 4 vertices using 6 edges.
Approach: Iterate over all n and see at which a number of nodes if we make a complete graph we obtain a number of edges more than m say it is K. Answer is n-k.
- Maximum number of edges which can be used to form a graph on n nodes is n * (n – 1) / 2 (A complete Graph).
- Then find number of maximum n, which will use m or less than m edges to form a complete graph.
- If still edges are left, then it will cover only one more node, as if it would have covered more than one node than, this is not the maximum value of n.
Below is the implementation of above approach:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Number of sink nodes in a graph
- Edge Coloring of a Graph
- Maximum number of nodes which can be reached from each node in a graph.
- Program to Calculate the Edge Cover of a Graph
- Check if removing a given edge disconnects a graph
- Add and Remove Edge in Adjacency List representation of a Graph
- Shortest Path in a weighted Graph where weight of an edge is 1 or 2
- Tree, Back, Edge and Cross Edges in DFS of Graph
- Find weight of MST in a complete graph with edge-weights either 0 or 1
- Find the maximum component size after addition of each edge to the graph
- Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph
- Calculate number of nodes between two vertices in an acyclic Graph by Disjoint Union method
- Detect cycle in the graph using degrees of nodes of graph
- Paths to travel each nodes using each edge (Seven Bridges of Königsberg)
- Maximum number of edges that N-vertex graph can have such that graph is Triangle free | Mantel's Theorem
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.