networkx.find_cliques_recursive

networkx.find_cliques_recursive(G)[source]

Returns all maximal cliques in a graph.

For each node v, a maximal clique for v is a largest complete subgraph containing v. The largest maximal clique is sometimes called the maximum clique.

This function returns an iterator over cliques, each of which is a list of nodes. It is a recursive implementation, so may suffer from recursion depth issues.

Parameters:

G : NetworkX graph

Returns:

iterator

An iterator over maximal cliques, each of which is a list of nodes in G. The order of cliques is arbitrary.

See also

find_cliques
An iterative version of the same algorithm.

Notes

To obtain a list of all maximal cliques, use list(find_cliques_recursive(G)). However, be aware that in the worst-case, the length of this list can be exponential in the number of nodes in the graph (for example, when the graph is the complete graph). This function avoids storing all cliques in memory by only keeping current candidate node lists in memory during its search.

This implementation is based on the algorithm published by Bron and Kerbosch (1973) [R923], as adapted by Tomita, Tanaka and Takahashi (2006) [R924] and discussed in Cazals and Karande (2008) [R925]. For a non-recursive implementation, see find_cliques().

This algorithm ignores self-loops and parallel edges, since cliques are not conventionally defined with such edges.

References

[R923](1, 2) Bron, C. and Kerbosch, J. “Algorithm 457: finding all cliques of an undirected graph”. Communications of the ACM 16, 9 (Sep. 1973), 575–577. <http://portal.acm.org/citation.cfm?doid=362342.362367>
[R924](1, 2) Etsuji Tomita, Akira Tanaka, Haruhisa Takahashi, “The worst-case time complexity for generating all maximal cliques and computational experiments”, Theoretical Computer Science, Volume 363, Issue 1, Computing and Combinatorics, 10th Annual International Conference on Computing and Combinatorics (COCOON 2004), 25 October 2006, Pages 28–42 <http://dx.doi.org/10.1016/j.tcs.2006.06.015>
[R925](1, 2) F. Cazals, C. Karande, “A note on the problem of reporting maximal cliques”, Theoretical Computer Science, Volume 407, Issues 1–3, 6 November 2008, Pages 564–568, <http://dx.doi.org/10.1016/j.tcs.2008.05.010>