{"id":152,"date":"2026-11-13T12:32:52","date_gmt":"2026-11-13T04:32:52","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-bron-kerbosch-lists-maximal-cliques\/"},"modified":"2026-11-13T21:51:23","modified_gmt":"2026-11-13T13:51:23","slug":"how-bron-kerbosch-lists-maximal-cliques","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-bron-kerbosch-lists-maximal-cliques\/","title":{"rendered":"How Bron-Kerbosch lists maximal cliques"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> The <strong>Bron-Kerbosch<\/strong> algorithm lists every maximal clique of an undirected graph. It keeps a current clique R, a set P of candidates that can still extend R, and a set X of vertices already excluded. A pivot taken from P \u222a X limits the branches to candidates outside the pivot&#8217;s neighborhood. With the pivot that minimizes that branch set, the running time is <strong>O(3^{n\/3})<\/strong>, matching the maximum number of maximal cliques. The algorithm lists maximal cliques. It does not stop at the single largest one.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">A clique is a set of vertices with every pairwise edge present. A maximal clique cannot add another vertex and stay a clique. A graph can contain exponentially many of them, up to 3^{n\/3} in the Moon-Moser bound, so any listing algorithm has an exponential worst case. The search has to avoid reporting a clique that is contained in a larger one, and it has to avoid exploring an extension that was already explored with a different vertex order.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The set X is the memory of that order. A vertex moved from P to X is finished as a sibling at this level. If the search ever reaches an empty P while X is still nonempty, every way to extend R uses a vertex that was already considered, so R is not maximal and nothing is reported.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">The algorithm reports each maximal clique once. With a pivot u chosen from P \u222a X to maximize the number of candidates adjacent to u, only candidates outside N(u) are branched on, and the time is O(3^{n\/3}) for an n-vertex graph. Extra memory is the recursion stack and the three sets, polynomial per level and O(n) levels deep. On a sparse graph, degeneracy ordering of the outer vertices improves the bound to a function of the degeneracy rather than of n alone.<\/p>\n\n\n<p class=\"wp-block-paragraph\">Listing every maximal clique is not the same as returning a maximum clique. The maximum-clique decision problem is NP-complete, and reading the longest list this algorithm emits would still cost time proportional to the number of maximal cliques, which can be exponential even when a single maximum clique is the only object a caller wanted.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Start with R and X empty and P equal to the vertex set.<\/li>\n<li>If P and X are both empty, report R. It is a maximal clique.<\/li>\n<li>Choose a pivot u in P \u222a X that maximizes the number of neighbors in P. Branch only on vertices v in P that are not neighbors of u.<\/li>\n<li>For each such v, recurse with R \u222a {v}, P \u2229 N(v), and X \u2229 N(v). Then move v from P to X.<\/li>\n<li>Pass adjacency tests against the graph. A missing edge means the vertex is not in N(v) and must not stay in the child candidate set.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">The exponential bound is a listing bound. A single maximum clique is a different question and stays hard. Degeneracy ordering is an outer schedule around the same recursion. Bron-Kerbosch is the R, P, X search.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when a clique is reported as soon as P is empty<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Report R whenever P is empty<\/td>\n<td>If X is nonempty, R is contained in a clique that was already branched on. Both sets have to be empty.<\/td>\n<\/tr>\n<tr>\n<td>Branch on every vertex in P and skip the pivot<\/td>\n<td>The cliques are still found. The 3^{n\/3} time bound is the pivoted algorithm. The unpivoted search does more work.<\/td>\n<\/tr>\n<tr>\n<td>Forget to move v into X after its recursion<\/td>\n<td>A later sibling can rebuild the same clique through a different order, and the maximality test loses the vertices already used.<\/td>\n<\/tr>\n<tr>\n<td>Intersect the child sets with the non-neighbors<\/td>\n<td>The child clique can then include a missing edge. The intersection is with N(v), the neighbors.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">A maximum matching is a different exhaustive search. Bron-Kerbosch is the backtracking enumeration of maximal cliques.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment lists every maximal clique with the sets R, P, and X. A pivot limits the branches to candidates outside the pivot&#8217;s neighborhood. On a triangle plus a pendant edge the maximal cliques are the triangle and the single extra edge. It prints <code>2<\/code>.<\/p>\n\n<pre><code class=\"language-python\">adj = {0: {1, 2}, 1: {0, 2}, 2: {0, 1, 3}, 3: {2}}\n\ndef bron(r, p, x, out):\n    if not p and not x:\n        out.append(set(r))\n        return\n    union = p | x\n    u = max(union, key=lambda v: len(p &amp; adj[v])) if union else None\n    for v in list(p - (adj[u] if u is not None else set())):\n        bron(r | {v}, p &amp; adj[v], x &amp; adj[v], out)\n        p.remove(v)\n        x.add(v)\n\nfound = []\nbron(set(), set(adj), set(), found)\nassert len(found) == 2 and {0, 1, 2} in found\nprint(len(found))\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Bron-Kerbosch lists maximal cliques in a social graph, a protein-interaction graph, or a conflict graph. <strong>NetworkX<\/strong> ships the algorithm. A maximum clique, one largest set, is the harder problem this enumeration does not pretend to solve in polynomial time.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop a full listing when the graph is large and only one large clique is needed. Use a heuristic or an integer program aimed at that single set, and accept that it may miss other maximal cliques. Keep Bron-Kerbosch when every maximal clique has to appear exactly once.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for Bron-Kerbosch returns the sets R, P, and X, the pivot, and the O(3^{n\/3}) bound. <strong>Bron-Kerbosch lists each maximal clique once by extending R with candidates in P, excluding vertices in X, and pivoting to reach an O(3^{n\/3}) bound.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: The Bron-Kerbosch algorithm lists every maximal clique of an undirected graph. It keeps a current clique R, a set P of candidates that can still extend R, and a set X of vertices already excluded. A pivot taken from P \u222a X limits the branches to candidates&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,32],"tags":[],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-graphs"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":551,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/152\/revisions\/551"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}