Input: N = 5
Below is the given graph with number of nodes is 5:
Possible groups satisfying the Bipartite property: [2, 5], [1, 3], 
Below is the number of bipartite groups can be formed:
The idea is to find the maximum height of all the Connected Components in the given graph of N nodes to find the minimum bipartite groups. Below are the steps:
- For all the non-visited vertex in the given graph, find the height of the current Connected Components starting from the current vertex.
- Start DFS Traversal to find the height of all the Connected Components.
- The maximum of the heights calculated for all the Connected Components gives the minimum bipartite groups required.
Below is the implementation of the above approach:
Time Complexity: O(V+E), where V is the number of vertices and E is the set of edges.
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.
- Minimum difference between groups of size two
- Divide 1 to n into two groups with minimum sum difference
- Minimum number of groups of nodes such that no ancestor is present in the same group
- Check whether a given graph is Bipartite or not
- Check if a given graph is Bipartite using DFS
- Maximum number of edges to be added to a tree so that it stays a Bipartite graph
- Count of different groups using Graph
- Segregate groups of first N numbers having GCD equals to 1
- Count of groups among N people having only one leader in each group
- Number of groups formed in a graph of friends
- Minimize the cost of partitioning an array into K groups
- Maximum number of groups of size 3 containing two type of items
- Divide N segments into two non-empty groups such that given condition is satisfied
- Count the number of ways to divide N in k groups incrementally
- Reverse a singly Linked List in groups of given size | Set 3
- Reverse an array in groups of given size | Set 3 (Single traversal)
- Find the size of largest group where groups are according to the xor of digits
- Reverse a Linked List in groups of given size (Iterative Approach)
- Count of largest sized groups while grouping according to product of digits
- Number of ways to make binary string of length N such that 0s always occur together in groups of size K
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.