VOOZH about

URL: https://www.geeksforgeeks.org/dsa/minimum-bipartite-groups/

⇱ Minimum Bipartite Groups - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Minimum Bipartite Groups

Last Updated : 12 Jul, 2025

Given Adjacency List representation of graph of N vertices from 1 to N, the task is to count the minimum bipartite groups of the given graph.

Examples: 

Input: N = 5 
Below is the given graph with number of nodes is 5: 
 

👁 Image


Output:
Explanation: 
Possible groups satisfying the Bipartite property: [2, 5], [1, 3], [4] 
Below is the number of bipartite groups can be formed: 
 

👁 Image

Approach: 
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: 

  1. For all the non-visited vertex in the given graph, find the height of the current Connected Components starting from the current vertex.
  2. Start DFS Traversal to find the height of all the Connected Components.
  3. 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: 


Output: 
3

 

Time Complexity: O(V+E), where V is the number of vertices and E is the set of edges.
Auxiliary Space: O(V). 

Comment
Article Tags:
Article Tags: