VOOZH about

URL: https://www.geeksforgeeks.org/dsa/two-clique-problem-check-graph-can-divided-two-cliques/

⇱ Two Clique Problem (Check if Graph can be divided in two Cliques) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Two Clique Problem (Check if Graph can be divided in two Cliques)

Last Updated : 23 Jul, 2025

A Clique is a subgraph of graph such that all vertices in subgraph are completely connected with each other. Given a Graph, find if it can be divided into two Cliques.

Example:

Input : G[][] =
[[0, 1, 1, 1, 0],
[1, 0, 1, 0, 0],
[1, 1, 0, 0, 0],
[1, 0, 0, 0, 1],
[0, 0, 0, 1, 0]]
Output : Yes
Explanation:

👁 graph divided in two cliques

This problem looks tricky at first, but has a simple and interesting solution. A graph can be divided in two cliques if its complement graph is Bipartitite. So below are two steps to find if graph can be divided in two Cliques or not. 

  • Find the complement of Graph. Below is the complement graph is above shown graph. In complement, all original edges are removed. And the vertices which did not have an edge between them, now have an edge connecting them. 

👁 twoclique2

  • Return true if complement is Bipartite, else false. The above shown graph is Bipartite. Checking whether a Graph is Bipartite or no is discussed here.

How does this work?

If complement is Bipartite, then graph can be divided into two sets U and V such that there is no edge connecting to vertices of same set. This means in original graph, these sets U and V are completely connected. Hence original graph could be divided in two Cliques.


Output
Yes

Time complexity : O(V2)
Space complexity : O(V^2), 

Comment
Article Tags:
Article Tags: