Divyaanand Sinha
Divyaanand Sinha

Reputation: 396

Graph algorithms?

What would be the most efficient way if I want to identify if a graph can be grouped into two sub graphs where in each sub graph each node is connected to every other node.For Example here in the image the graph can be grouped into two sub graphs consisting of 4 nodes and 5 nodes respectively where in each sub graph every node is connected to every other node. Suppose I am given a graph and I am to check whether the above fact holds true or not,what would be the most efficient way or algorithm to do so.enter image description here

Upvotes: 0

Views: 680

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234795

This is known as the clique problem. A clique is a subset of vertices such that every two vertices in the subset are connected in the original graph (that is, they form a complete subgraph). You are asking for an algorithm that lists all maximal cliques (cliques that are not part of larger cliques). There are various algorithms for this. The usual one used is the Bron-Kerbosch algorithm. It has a worst-case running time of O(3n/3), where n is the number of vertices in the graph.

Other algorithms may be applicable if your graph has special structure (e.g., planar, which your example is not).

EDIT: Actually, if your decision problem is whether the graph can be partitioned into exactly two cliques, there's a more efficient algorithm, as described in this thread (which then becomes a duplicate of your question).

Upvotes: 5

Related Questions