Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast algorithm for finding out if an induced subgraph is complete

I have an undirected unweighted graph G = (V, E) and a randomly chosen subset S of its vertices. I want to check whether the vertices in S are mutually adjacent (i.e. form a complete subgraph/a clique).

I have the following algorithm (pseudo-code):

foreach vertex in S  {
  // Check that the vertex has enough edges
  if (vertex.edges.count < S.size - 1)
    return false;

  // Check that there is an edge to each vertex in S
  foreach vertex2 in S  {
    if (!vertex.hasEdgeTo(vertex2))
      return false;
  }
}
return true;

The problem is that this algorithm's worst-case performance is O(|V|2) (in case when the subset S contains all the vertices of a complete graph).

My question is: is there a faster algorithm that runs with a better big O worst-case complexity?

like image 399
Karel Petranek Avatar asked Jul 31 '10 23:07

Karel Petranek


People also ask

How do you identify an induced subgraph?

A subgraph H of G is called INDUCED, if for any two vertices u,v in H, u and v are adjacent in H if and only if they are adjacent in G. In other words, H has the same edges as G between the vertices in H. A general subgraph can have less edges between the same vertices than the original one.

Is the induced subgraph a complete graph?

. An induced subgraph that is a complete graph is called a clique. Any induced subgraph of a complete graph forms a clique. The subgraph induced by a set of vertices can be computed in the Wolfram Language using Subgraph[g, vlist].

How many induced subgraphs does a complete graph have?

How many induced subgraphs are there? How many spanning subgraphs are there? There are 2n induced subgraphs (all subsets of vertices) and 2m spanning subgraphs (all subsets of edges).

What is a complete subgraph?

A complete subgraph is a set of nodes for which all the nodes are connected to each other. Maximal complete subgraph is are then the largest (i.e. those containing most objects) of these complete subgraphs.


3 Answers

Assuming that you can check whether two vertices are incident in O(1), your algorithm has O(|V|²) = O(|E|) time complexity in the worst case. I don't think you can do better than O(|E|), since you should really check all the edges of the subgraph.

like image 172
Bolo Avatar answered Oct 31 '22 23:10

Bolo


I don't believe you'll get a non O(|E|^2) algorithm for performing this check. Logically, each V1-V2 edge must be sought to prove completeness. Separating into two loops, the first checking the edge counts and the second then checking the vertex connections would potentially speed up the algorithm. Perhaps another way of representing the graph (with edges rather than vertices) would help?

like image 43
Will A Avatar answered Oct 31 '22 23:10

Will A


How does your hasEdgeTo perform? If you use a tree-based set to store the edges, that function is not just O(1).

By using a bitvector for the edges, you can go with O(|S| * min(|E|, |V|, |S|)).

like image 32
Albert Avatar answered Oct 31 '22 21:10

Albert