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:
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.
- Maximize count of nodes disconnected from all other nodes in a Graph
- Check if removing a given edge disconnects a graph
- Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph
- Add and Remove Edge in Adjacency Matrix representation of a Graph
- Sum of degrees of all nodes of a undirected graph
- Partition N into M parts such that difference between Max and Min part is smallest
- Number of groups formed in a graph of friends
- Number of shortest paths in an unweighted and directed graph
- Number of single cycle components in an undirected graph
- Program to find total number of edges in a Complete Graph
- Maximum number of edges among all connected components of an undirected graph
- Maximize the value of A by replacing some of its digits with digits of B
- Maximize the value of x + y + z such that ax + by + cz = n
- Count the number of non-reachable nodes
- Largest number with maximum trailing nines which is less than N and greater than N-D
- Count Numbers with N digits which consists of odd number of 0's
- Number of hours after which the second person moves ahead of the first person if they travel at a given speed
- Breadth First Search or BFS for a Graph
- Depth First Search or DFS for a Graph
- Graph and its representations
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.