Bron–Kerbosch Algorithm
   HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, the Bron–Kerbosch algorithm is an
enumeration algorithm In computer science, an enumeration algorithm is an algorithm that enumerates the answers to a computational problem. Formally, such an algorithm applies to problems that take an input and produce a list of solutions, similarly to function problem ...
for finding all maximal
cliques A clique ( AusE, CanE, or ), in the social sciences, is a group of individuals who interact with one another and share similar interests. Interacting with cliques is part of normative social development regardless of gender, ethnicity, or popular ...
in an undirected
graph Graph may refer to: Mathematics *Graph (discrete mathematics), a structure made of vertices and edges **Graph theory, the study of such graphs and their properties *Graph (topology), a topological space resembling a graph in the sense of discre ...
. That is, it lists all
subset In mathematics, Set (mathematics), set ''A'' is a subset of a set ''B'' if all Element (mathematics), elements of ''A'' are also elements of ''B''; ''B'' is then a superset of ''A''. It is possible for ''A'' and ''B'' to be equal; if they are ...
s of vertices with the two properties that each pair of vertices in one of the listed subsets is connected by an edge, and no listed subset can have any additional vertices added to it while preserving its complete connectivity. The Bron–Kerbosch algorithm was designed by
Dutch Dutch commonly refers to: * Something of, from, or related to the Netherlands * Dutch people () * Dutch language () Dutch may also refer to: Places * Dutch, West Virginia, a community in the United States * Pennsylvania Dutch Country People E ...
scientists
Coenraad Bron Coenraad Bron (2 August 1937 – 15 August 2006) was a Dutch computer scientist. He worked with Edsger W. Dijkstra on the THE multiprogramming system. Together with Joep Kerbosch he invented the Bron–Kerbosch algorithm for the clique pro ...
and Joep Kerbosch, who published its description in 1973. Although other algorithms for solving the
clique problem In computer science, the clique problem is the computational problem of finding cliques (subsets of vertices, all adjacent to each other, also called complete subgraphs) in a graph. It has several different formulations depending on which cliq ...
have running times that are, in theory, better on inputs that have few maximal independent sets, the Bron–Kerbosch algorithm and subsequent improvements to it are frequently reported as being more efficient in practice than the alternatives. It is well-known and widely used in application areas of
graph algorithm The following is a list of well-known algorithms along with one-line descriptions for each. Automated planning Combinatorial algorithms General combinatorial algorithms * Brent's algorithm: finds a cycle in function value iterations using on ...
s such as
computational chemistry Computational chemistry is a branch of chemistry that uses computer simulation to assist in solving chemical problems. It uses methods of theoretical chemistry, incorporated into computer programs, to calculate the structures and properties of m ...
. A contemporaneous algorithm of , although presented in different terms, can be viewed as being the same as the Bron–Kerbosch algorithm, as it generates the same search tree.


Without pivoting

The basic form of the Bron–Kerbosch algorithm is a
recursive Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics ...
backtracking Backtracking is a class of algorithms for finding solutions to some computational problems, notably constraint satisfaction problems, that incrementally builds candidates to the solutions, and abandons a candidate ("backtracks") as soon as it de ...
algorithm that searches for all maximal cliques in a given graph ''G''. More generally, given three disjoint sets of vertices ''R'', ''P'', and ''X'', it finds the maximal cliques that include all of the vertices in ''R'', some of the vertices in ''P'', and none of the vertices in ''X''. In each call to the algorithm, ''P'' and ''X'' are disjoint sets whose union consists of those vertices that form cliques when added to ''R''. In other words, ''P'' ∪ ''X'' is the set of vertices which are joined to every element of ''R''. When ''P'' and ''X'' are both empty there are no further elements that can be added to ''R'', so R is a maximal clique and the algorithm outputs R. The recursion is initiated by setting ''R'' and ''X'' to be the
empty set In mathematics, the empty set is the unique set having no elements; its size or cardinality (count of elements in a set) is zero. Some axiomatic set theories ensure that the empty set exists by including an axiom of empty set, while in other ...
and ''P'' to be the vertex set of the graph. Within each recursive call, the algorithm considers the vertices in ''P'' in turn; if there are no such vertices, it either reports ''R'' as a maximal clique (if ''X'' is empty), or backtracks. For each vertex ''v'' chosen from ''P'', it makes a recursive call in which ''v'' is added to ''R'' and in which ''P'' and ''X'' are restricted to the neighbor set ''N(v)'' of ''v'', which finds and reports all clique extensions of ''R'' that contain ''v''. Then, it moves ''v'' from ''P'' to ''X'' to exclude it from consideration in future cliques and continues with the next vertex in ''P''. That is, in pseudocode, the algorithm performs the following steps: algorithm BronKerbosch1(R, P, X) is if ''P'' and ''X'' are both empty then report ''R'' as a maximal clique for each vertex ''v'' in ''P'' do BronKerbosch1(''R'' ⋃ , ''P'' ⋂ ''N''(''v''), ''X'' ⋂ ''N''(''v'')) ''P'' := ''P'' \ ''X'' := ''X'' ⋃


With pivoting

The basic form of the algorithm, described above, is inefficient in the case of graphs with many non-maximal cliques: it makes a recursive call for every clique, maximal or not. To save time and allow the algorithm to backtrack more quickly in branches of the search that contain no maximal cliques, Bron and Kerbosch introduced a variant of the algorithm involving a "pivot vertex" ''u'', chosen from ''P'' (or more generally, as later investigators realized, from ''P'' ⋃ ''X''). Any maximal clique must include either ''u'' or one of its non-neighbors, for otherwise the clique could be augmented by adding ''u'' to it. Therefore, only ''u'' and its non-neighbors need to be tested as the choices for the vertex ''v'' that is added to ''R'' in each recursive call to the algorithm. In pseudocode: algorithm BronKerbosch2(R, P, X) is if ''P'' and ''X'' are both empty then report ''R'' as a maximal clique choose a pivot vertex ''u'' in ''P'' ⋃ ''X'' for each vertex ''v'' in ''P'' \ N(''u'') do BronKerbosch2(''R'' ⋃ , ''P'' ⋂ N(''v''), X ⋂ N(''v'')) ''P'' := ''P'' \ ''X'' := ''X'' ⋃ If the pivot is chosen to minimize the number of recursive calls made by the algorithm, the savings in running time compared to the non-pivoting version of the algorithm can be significant.


With vertex ordering

An alternative method for improving the basic form of the Bron–Kerbosch algorithm involves forgoing pivoting at the outermost level of recursion, and instead choosing the ordering of the recursive calls carefully in order to minimize the sizes of the sets of candidate vertices within each recursive call. The
degeneracy Degeneracy, degenerate, or degeneration may refer to: Arts and entertainment * ''Degenerate'' (album), a 2010 album by the British band Trigger the Bloodshed * Degenerate art, a term adopted in the 1920s by the Nazi Party in Germany to descri ...
of a graph is the smallest number such that every subgraph of has a vertex with
degree Degree may refer to: As a unit of measurement * Degree (angle), a unit of angle measurement ** Degree of geographical latitude ** Degree of geographical longitude * Degree symbol (°), a notation used in science, engineering, and mathematics ...
or less. Every graph has a ''degeneracy ordering'', an ordering of the vertices such that each vertex has or fewer neighbors that come later in the ordering; a degeneracy ordering may be found in
linear time In computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by ...
by repeatedly selecting the vertex of minimum degree among the remaining vertices. If the order of the vertices that the Bron–Kerbosch algorithm loops through is a degeneracy ordering, then the set of candidate vertices in each call (the neighbors of that are later in the ordering) will be guaranteed to have size at most . The set of excluded vertices will consist of all earlier neighbors of , and may be much larger than . In recursive calls to the algorithm below the topmost level of the recursion, the pivoting version can still be used... In pseudocode, the algorithm performs the following steps: algorithm BronKerbosch3(G) is ''P'' = V(''G'') ''R'' = X = empty for each vertex ''v'' in a degeneracy ordering of ''G'' do BronKerbosch2(, ''P'' ⋂ N(''v''), X ⋂ N(''v'')) ''P'' := ''P'' \ ''X'' := ''X'' ⋃ This variant of the algorithm can be proven to be efficient for graphs of small degeneracy, and experiments show that it also works well in practice for large sparse
social network A social network is a social structure made up of a set of social actors (such as individuals or organizations), sets of dyadic ties, and other social interactions between actors. The social network perspective provides a set of methods for an ...
s and other real-world graphs.


Example

In the example graph shown, the algorithm is initially called with ''R'' = Ø, ''P'' = , and ''X'' = Ø. The pivot ''u'' should be chosen as one of the degree-three vertices, to minimize the number of recursive calls; for instance, suppose that ''u'' is chosen to be vertex 2. Then there are three remaining vertices in ''P'' \ ''N''(''u''): vertices 2, 4, and 6. The iteration of the inner loop of the algorithm for ''v'' = 2 makes a recursive call to the algorithm with ''R'' = , ''P'' = , and ''X'' = Ø. Within this recursive call, one of 1 or 5 will be chosen as a pivot, and there will be two second-level recursive calls, one for vertex 3 and the other for whichever vertex was not chosen as pivot. These two calls will eventually report the two cliques and . After returning from these recursive calls, vertex 2 is added to ''X'' and removed from ''P''. The iteration of the inner loop of the algorithm for ''v'' = 4 makes a recursive call to the algorithm with ''R'' = , ''P'' = , and ''X'' = Ø (although vertex 2 belongs to the set ''X'' in the outer call to the algorithm, it is not a neighbor of ''v'' and is excluded from the subset of ''X'' passed to the recursive call). This recursive call will end up making three second-level recursive calls to the algorithm that report the three cliques , , and . Then, vertex 4 is added to ''X'' and removed from ''P''. In the third and final iteration of the inner loop of the algorithm, for ''v'' = 6, there is a recursive call to the algorithm with ''R'' = , ''P'' = Ø, and ''X'' = . Because this recursive call has ''P'' empty and ''X'' non-empty, it immediately backtracks without reporting any more cliques, as there can be no maximal clique that includes vertex 6 and excludes vertex 4. The call tree for the algorithm, therefore, looks like: BronKerbosch2(Ø, , Ø) BronKerbosch2(, , Ø) BronKerbosch2(, Ø, Ø): output BronKerbosch2(, , Ø) BronKerbosch2(, Ø, Ø): output BronKerbosch2(, , Ø) BronKerbosch2(, Ø, Ø): output BronKerbosch2(, Ø, Ø): output BronKerbosch2(, Ø, Ø): output BronKerbosch2(, Ø, ): no output The graph in the example has degeneracy two; one possible degeneracy ordering is 6,4,3,1,2,5. If the vertex-ordering version of the Bron–Kerbosch algorithm is applied to the vertices, in this order, the call tree looks like BronKerbosch3(G) BronKerbosch2(, , Ø) BronKerbosch2(, Ø, Ø): output BronKerbosch2(, , ) BronKerbosch2(, Ø, Ø): output BronKerbosch2(, Ø, Ø): output BronKerbosch2(, , ) BronKerbosch2(, Ø, Ø): output BronKerbosch2(, , Ø) BronKerbosch2(, , Ø) BronKerbosch2(, Ø, Ø): output BronKerbosch2(, , ): no output BronKerbosch2(, Ø, ): no output


Worst-case analysis

The Bron–Kerbosch algorithm is not an
output-sensitive algorithm In computer science, an output-sensitive algorithm is an algorithm whose running time depends on the size of the output, instead of, or in addition to, the size of the input. For certain problems where the output size varies widely, for example fro ...
: unlike some other algorithms for the clique problem, it does not run in
polynomial time In computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by ...
per maximal clique generated. However, it is efficient in a worst-case sense: by a result of , any ''n''-vertex graph has at most 3''n''/3 maximal cliques, and the worst-case running time of the Bron–Kerbosch algorithm (with a pivot strategy that minimizes the number of recursive calls made at each step) is O(3''n''/3), matching this bound.. For
sparse graph In mathematics, a dense graph is a graph in which the number of edges is close to the maximal number of edges (where every pair of vertices is connected by one edge). The opposite, a graph with only a few edges, is a sparse graph. The distinction ...
s, tighter bounds are possible. In particular the vertex-ordering version of the Bron–Kerbosch algorithm can be made to run in time , where is the
degeneracy Degeneracy, degenerate, or degeneration may refer to: Arts and entertainment * ''Degenerate'' (album), a 2010 album by the British band Trigger the Bloodshed * Degenerate art, a term adopted in the 1920s by the Nazi Party in Germany to descri ...
of the graph, a measure of its sparseness. There exist -degenerate graphs for which the total number of maximal cliques is , so this bound is close to tight.


Notes


References

*. *. *. *. *. *. *. *. *. *.


External links


Review of the Bron-Kerbosch algorithm and variations
by Alessio Conte
Bron-Kerbosch algorithm implementation visualized in Javascript

Bron-Kerbosch algorithm implementation in Python

Bron-Kerbosch algorithm with vertex ordering implementation in Python

Bron-Kerbosch algorithm implementation in C++

Bron-Kerbosch algorithm implementation in C++11 with unit tests

C++ implementation of the algorithms presented in Eppstein, Strash (2011)
by Darren Strash
Finding all cliques of an undirected graph
Seminar notes by Michaela Regneri, January 11, 2007.
Bron-Kerbosch, algorithms implementation in PHP, library with composer install
by Sergio Zambrano {{DEFAULTSORT:Bron-Kerbosch algorithm Graph algorithms Articles with example pseudocode