algorithmgraphclique

Bron Kerbosh algorithm for clique finding - what happens when the pivot vertex doesn't exist?


The wikipedia pseudocode on BK clique finding with pivoting:

   BronKerbosch2(R,P,X):
   if P and X are both empty:
       report R as a maximal clique
   choose a pivot vertex u in P ⋃ X
   for each vertex v in P \ N(u):
       BronKerbosch2(R ⋃ {v}, P ⋂ N(v), X ⋂ N(v))
       P := P \ {v}
       X := X ⋃ {v}

I'm unclear on what happens with P union X is empty. Since u is undefined, does the function continue with N(u) as the empty set (i.e. it continues with for each vertex v in P), or does it return to the caller?


Solution

  • P union X is empty if and only if both P and X are empty. This condition is checked in the line

    if P and X are both empty:
    

    Thus, if this condition fails, this means P or X or both are not empty. Thus, there must be at least one element in P union X.

    To put it in other words: If P union X is empty, we report R as a maximal clique.