Towards Optimal Output-Sensitive Clique Listing or: Listing Cliques from Smaller Cliques

We study the problem of finding and listing k-cliques in an m-edge, n-vertex graph, for constant k≥ 3. This is a fundamental problem of both theoretical and practical importance. Our first contribution is an algorithmic framework for finding k-cliques that gives the first improvement in 19 years over the old runtimes for 4 and 5-clique finding, as a function of m [Eisenbrand and Grandoni, TCS’04]. With the current bounds on matrix multiplication, our algorithms run in O(m1.66) and O(m2.06) time, respectively, for 4-clique and 5-clique finding. Our main contribution is an output-sensitive algorithm for listing k-cliques, for any constant k≥ 3. We complement the algorithm with tight lower bounds based on standard fine-grained assumptions. Previously, the only known conditionally optimal output-sensitive algorithms were for the case of 3-cliques given by Bj'orklund, Pagh, Vassilevska W. and Zwick [ICALP’14]. If the matrix multiplication exponent ω is 2, and if the number of k-cliques t is large enough, the running time of our algorithms is Õ(min{m1/k−2t1 − 2/k(k−2),n2/k−1t1−2/k(k−1)}), and this is tight under the Exact-k-Clique Hypothesis. This running time naturally extends the running time obtained by Bj'orklund, Pagh, Vassilevska W. and Zwick for k=3. Our framework is very general in that it gives k-clique listing algorithms whose running times can be measured in terms of the number of ℓ-cliques Δℓ in the graph for any 1≤ ℓ<k. This generalizes the typical parameterization in terms of n (the number of 1-cliques) and m (the number of 2-cliques). If ω is 2, and if the size of the output, Δk, is sufficiently large, then for every ℓ<k, the running time of our algorithm for listing k-cliques is Õ(Δℓ2/ℓ (k − ℓ)Δk1−2/k(k−ℓ)). We also show that this runtime is optimal for all 1 ≤ ℓ < k under the Exact k-Clique hypothesis.


Introduction
Finding, counting and listing cliques in graphs are fundamental tasks with numerous applications.In any type of network (social, biological, financial, web, maps, etc.) clique listing is used to find patterns such as communities, spam-link farms, motifs, correlated genes and more (see [SW05,DBS18] and the many citations within).
As finding a clique of maximum size has long been known to be NP-hard [Kar72], the focus in numerous practical works (see [DBS18, Tso15, SSPUVc15, PSV17, Lat08, CN85, SW05, ST15, CC11]) is on listing cliques of small size such as triangles and 4-cliques.
More generally, in an n-node m-edge graph, for a constant k ≥ 3 (independent of n and m), we want to find, count or list the k-cliques in G. Chiba and Nishizeki [CN85] presented an algorithm that for any constant k ≥ 3 can list all k-cliques in a graph in O(mα k−2 ) time, where α ≤ O( √ m) is the arboricity of the given graph.This algorithm is among the most efficient clique-listing approaches in practice (see e.g.[DBS18] and the references within).
Purely in terms of m, Chiba and Nishizeki's algorithm runs in O(m k/2 ) time.Since O(m k/2 ) is also the maximum number of k-cliques in an m-edge graph, this algorithm is optimal, as long as the graph has Θ(m k/2 ) cliques (e.g. when the graph itself is a clique).However, when the graph has t k-cliques, where t is o(m k/2 ), the optimality argument no longer works.In fact, it has been known for almost 40 years [NP85] that when t = 1, a much faster runtime is possible using fast matrix multiplication.
This motivates the study of output-sensitive algorithms for k-clique listing: algorithms whose running time depends on the number of k-cliques in the output.An even more desirable version of an output-sensitive algorithm is one that can also take as input some parameter t, and can list up to t k-cliques in the graph.When t is much smaller than the number of k-cliques in the graph, such an algorithm could potentially be more efficient.These two versions are actually runtimeequivalent up to logarithmic factors for most natural running times (we provide a proof in Section 2 for completeness).We thus use these two notions interchangeably.
Björklund, Pagh, Vassilevska W. and Zwick [BPVZ14] designed such output-sensitive algorithms for triangle listing with runtime Õ(n ω + n ) 1 , where ω < 2.372 [DWZ23,VXXZ24] is the exponent of matrix multiplication and t is the number of triangles listed.If ω = 2, the runtimes simplify to Õ(n 2 + nt 2/3 ) and Õ(m 4/3 + mt 1/3 ), and these are shown to be conditionally optimal for any t = Ω(n 1.5 ) and t = Ω(m) respectively under the popular 3SUM hypothesis [Pȃt10,KPP16] and the even more believable Exact Triangle hypothesis [VX20].There have also been many recent works focusing on output-sensitive cycle-listing algorithms.The works of [AKLS22,JX23] show O(min{n 2 + t, m 4/3 + t}) algorithms for listing t 4-cycles, and the work of [JVZ24] shows Õ(n 2 + t) algorithm for listing t 6-cycles.Moreover, matching conditional lower bounds for 4-cycle listing were shown under the 3SUM hypothesis [JX23,ABF23], which was subsequently strengthened to hold under the Exact Triangle hypothesis [CX24].
While the output-sensitive questions for triangle listing and 4-cycle listing are is well-understood by now, no similar conditionally optimal results are known for k-clique listing when k ≥ 4.
Question 1.What is the best output-sensitive algorithm for k-clique listing for k > 3?
When analyzing algorithms, researchers look at a variety of parameters to understand performance: the size of the input (typically n and m for graph problems), the size of the output (the number of k-cliques), and other natural parameters of the input (e.g. the arboricity, as in [CN85]).In this work, we study clique-listing algorithms parameterized by ∆ ℓ , the number of ℓ-cliques in the graph for ℓ < k.
To motivate this, let us consider the first non-trivial algorithm for k-clique finding by Nešetril and Poljak [NP85].For simplicity, assume that k is divisible by 3. First, the algorithm enumerates all k/3-cliques in the input graph G, and forms a new graph H whose nodes represent the k/3-cliques of G and whose edges connect two k/3-cliques that together form a 2k/3-clique.The triangles of H correspond to k-cliques in G, and so Nešetril and Poljak reduce k-clique finding, counting and listing in G to finding, counting and listing (respectively) of triangles in H2 .As there are O(n k/3 ) k/3-cliques in G, and since triangle finding or counting in N -node graphs can be done in O(N ω ) time [IR78], [NP85] gave an O(n ωk/3 ) time algorithm for k-clique finding or counting in n-node graphs.Eisenbrand and Grandoni [EG04] extended Nešetril and Poljak's reduction to obtain a kclique runtime of O(n β(k) ) where β(k) = ω(⌈k/3⌉, ⌈(k − 1)/3⌉, ⌊k/3⌋), and ω(a, b, c) is the exponent of multiplying an n a × n b matrix by an n b × n c matrix.As the runtime of k-clique detection has remained unchallenged for several decades, the hypothesis that these algorithms are optimal has been used to provide conditional lower bounds in several works (e.g.[ABV18, BT17, BW17]).Throughout the paper, we consider the word-RAM model of computation with O(log n) bit words.
More generally, if a graph has a small number ∆ ℓ of ℓ-cliques for ℓ < k, a simple generalization of Nešetril and Poljak's reduction would reduce k-clique to k/ℓ-clique in a graph with ∆ ℓ nodes (assuming k is divisible by ℓ for simplicity).If one can list the ℓ-cliques fast, then k-clique finding, listing and detection can all be done faster in graphs with small ∆ ℓ .
In other words, for k-clique problems, the number of ℓ-cliques ∆ ℓ , where ℓ < k is arguably the most natural parameter.The usual input parameters n and m can be viewed as the special cases ∆ 1 and ∆ 2 .We are not the first to suggest this natural parameterization of the input.In fact, small ∆ ℓ values have been exploited to obtain faster k-clique algorithms in experimental algorithmics: e.g., [PSV17] and [CWGR14] count k-cliques faster in graphs with a small number of triangles.Motivated by these practical results, we are the first to consider the following question within theoretical computer science: Question 2. Can we get a general conditionally optimal algorithms for output-sensitive k-clique listing in terms of the number ∆ ℓ of ℓ-cliques for any ℓ < k?

Our Contributions
We present a systematic study of clique finding and listing, and provide answers to both Questions 1 and 2. We give the first output-sensitive algorithms for listing k-cliques for k ≥ 4. We also give the first general algorithms for detecting and listing k-cliques in terms of the number of ℓ-cliques, and the first fine-grained lower bounds for the listing problem for general k.Our lower bounds show that our algorithms are tight for a non-trivial range of the number of k-cliques to output.We summarize our contributions in Table 1.(k, ℓ)-Clique-Detection and (k, ℓ)-Clique-Listing refer to detecting and listing k-cliques respectively given a list of all ℓ-cliques.Here, t is the number of k-cliques we are asked to list.
Improved 4 and 5-clique detection in sparse graphs.We provide a general algorithmic framework for detecting cliques.As special cases of the framework, we give the first improvement over the the runtime of Eisenbrand and Grandoni [EG04] for 4 and 5-clique detection in sparse graphs (we show this in Examples 3.3 and 3.4 in Section 3.2).
Theorem 1.2.There is an O(m 1.657 ) time algorithm for 4-clique detection and an O(m 2.057 ) time algorithm for 5-clique detection in m-edge graphs.
We compare the explicit values of [EG04]'s exponent and our improved exponents in , where β(k) is the exponent of k-clique detection (as in Hypothesis 1.1).We give the runtime of their algorithm with the current bounds on square and rectangular matrix multiplication [VXXZ24].
Lower bounds for k-clique listing.Prior works [Pȃt10, KPP16, VX20] give fine-grained lower bounds for listing triangles in an n-node, m-edge graph: triangle-listing requires n 1−o(1) t 2/3 time in n-node graphs, and requires m 1−o(1) t 1/3 in m-edge graphs time, under standard fine-grained hypotheses.The lower bounds imply tightness of the known algorithms [BPVZ14] if t is large enough: t = Ω(n 1.5 ) or t = Ω(m) respectively.The lower bounds of [Pȃt10,KPP16] are under the 3SUM hypothesis.Extending these to lower bounds for k-clique listing seems difficult.Instead we focus on the approach of [VX20] who showed hardness under the Exact-Triangle hypothesis which states that finding a triangle of weight sum 0 in an n-node edge-weighted graph requires n 3−o(1) time in the word-RAM model.The Exact-Triangle hypothesis is one of the most believable hypotheses in fine-grained complexity, as it is implied by both the 3SUM hypothesis and the APSP hypothesis (see [Vas18]).
A natural generalization of the Exact-Triangle hypothesis is the Exact-k-Clique hypothesis (which coincides with the Exact-Triangle hypothesis for k = 3): Hypothesis 1.3 (Exact-k-Clique hypothesis).For a constant k ≥ 3, let Exact-k-Clique be the problem that given an n-node graph with edge weights in {−n 100k , . . ., n 100k }, asks to determine whether the graph contains a k-clique whose edges sum to 0. Then, Exact-k-Clique requires n k−o(1) time, on the word-RAM model of computation with O(log n) bit words.
The Exact-k-Clique hypothesis is among the popular hardness hypotheses in fine-grained complexity.Most recently, it has been used to give hardness for the Orthogonal Vectors problem in moderate dimensions [ABDN18] and join queries in databases [BCM22].Moreover, due to known reductions (see e.g.[Vas18]), the Exact-k-Clique hypothesis is at least as believable as the Max-Weight-k-Clique hypothesis which is used in many previous papers (e.g.[AVW14, BDT16, BT17, LVW18, BGMW20]).
Under the Exact-k-Clique hypothesis we prove lower bounds for k-clique listing for all k ≥ 3.These are the first lower bounds for output-sensitive clique listing for k ≥ 4.
Theorem 1.4.For any k ≥ 3, and γ ∈ [0, k], listing t k-cliques in a graph with n vertices, and in a graph with m nodes requires and m time respectively under the Exact-k-Clique hypothesis.
This is a special case of Theorem 4.1 in the main body.For k = 3 this is the same lower bound as previously proven [Pȃt10, KPP16,VX20].Shortly, we will present algorithms that match our lower bound for all k, m, n and for large t if ω = 2, implying that our lower bound is tight.This is in fact the first output-sensitive lower bound for k-clique listing problems for k ≥ 4, and the first such lower bound for any graph pattern of size at least 5.
Optimal algorithms for 4 and 5-clique listing.For the special cases of k = 4, 5, we give algorithms parametrized by the number of vertices n and number of k-cliques t which are conditionally optimal if ω = 2.We prove these results in Corollary 5.7 and Corollary 5.8.
Similar to [BPVZ14], we state our runtimes in terms of ω.In our analysis, we compute rectangular matrix multiplication by truncating it to multiple instances of square matrix multiplication.If one is interested in better numerical values, one could instead use the best upper bound on rectangular matrix multiplication [VXXZ24] in these steps.
Theorem 1.5.Given a graph on n nodes, one can list t 4-cliques in Recall that the 4-Clique hypothesis, which is a special case of Hypothesis 1.1 when k = 4, gives a lower bound of n 3−o(1) if ω = 2.Moreover, Theorem 1.4 gives a lower bound of (n 2/3 t 5/6 ) 1−o(1) .Therefore, this 4-clique listing algorithm is indeed conditionally optimal.
Theorem 1.6.Given a graph on n nodes, one can list t 5-cliques in Recall that the 5-Clique hypothesis from Hypothesis 1.1 gives us a lower bound of n 4−o(1) if ω = 2.Moreover, Theorem 1.4 gives a lower bound of (n 1/2 t 9/10 ) 1−o(1) .Therefore, this 5-clique listing algorithm is also conditionally optimal.
Nearly-everywhere optimal algorithms for 4 and 5-clique listing in sparse graphs.In the case of sparse graphs, we obtain conditionally optimal runtimes for 4 and 5-clique listing for almost all values of t if ω = 2.The runtimes are stated in the following theorems and are pictorially depicted in Figure 1.Here, r is such that one can list t 4-cliques or 5-cliques respectively, in Õ(m r ) time.The blue line corresponds to our upper bound from Theorems 1.7 and 1.8, the dashed red line denotes our lower bound from Theorem 1.10, and the dashed black line corresponds to the lower bound from Hypothesis 1.1.The shaded region highlights the portions of the algorithms which are not conditionally optimal.
Theorem 1.7.If ω = 2, one can list t 4-cliques in a graph with m edges in time This algorithm matches the lower bound in Hypothesis 1.1 when t ≤ m 5/4 , and it matches our lower bound of Theorem 1.4 when t ≥ m 10/7 .Theorem 1.8.If ω = 2, one can list t 5-cliques in a graph with m edges in time if t ≤ m 19/10 , Õ(m 17/18 t 10/18 ) if m 19/10 ≤ t ≤ m 55/28 , Õ(m 1/3 t 13/15 ) if t ≥ m 55/28 .This algorithm matches the runtime of the lower bound in Hypothesis 1.1 when t ≤ m 19/10 , and it matches our lower bound from Theorem 1.4 when t ≥ m 55/28 .Theorem 1.7 and Theorem 1.8 are proved in Section 5.2.
Optimal algorithms for listing many k-cliques.More generally, we consider the problem of listing k-cliques for k ≥ 3.For instance, consider the problem of listing 6-cliques in sparse graphs with m edges.If we adapt the existing approach for k-clique detection [NP85, EG04] and directly reduce it to triangle listing in a graph with m nodes and then use [BPVZ14], we get an Õ(m 2 + mt 2/3 ) runtime when ω = 2.In comparison, the lower bound from Theorem 1.10 is (m 1/4 t 11/12 ) 1−o(1) .When t is close to maximum (as t → O(m 3 )), the Õ(m 2 + mt 2/3 ) runtime is polynomially higher than the lower bound.Therefore, we cannot only rely on such reductions.Nevertheless, we give a conditionally tight algorithm for graphs with many k-cliques, provided that ω = 2 for sufficiently large number of cliques.In particular, the runtime of the algorithm in the theorem below matches the lower bound of Theorem 1.4.
Theorem 1.9 (Informal).If ω = 2, there is an algorithm for k-clique listing which runs in time when t is large.
We give more explicit bounds on t and the runtimes in terms of ω in Sections 5.3 and 5.4.In other words, we have an algorithm which match the lower bound in Theorem 1.4 for graphs with many k-cliques.
General listing algorithm for all t.In Section 6, we give a general black-box approach (by non-trivially adapting previous reductions [NP85,EG04]) that uses our (conditionally) optimal algorithm for a large number of k-cliques t to obtain a fast algorithm that works for all t.The main advantage of this approach is its simplicity and generality.In particular, we obtain an intuitive and simple analysis of the runtime for all k, t.In Section 6, we show a comparison of our lower bounds and the runtime of our general algorithm in some examples.We illustrate the runtime of the general algorithm for some specific cases in Figure 2.
Improved algorithm for 6-clique listing.We note that our generic algorithm trades simplicity for optimality, and it is not always the best algorithm one can obtain for fixed k.
In Section 7, we give a more refined algorithm for 6-clique listing in terms of n and t if ω = 2 to illustrate how one might obtain a tighter runtime bound for specific k.In Figure 3, we compare our "general" bound, our best bound and our lower bounds to illustrate the improvement in the algorithm.However, since the number of terms and parameters in the runtime increases significantly with k, we do not do this refined analysis for all k.Listing cliques from smaller cliques.In fact, our frameworks are much more general and it extends to the problems of finding and listing k-cliques given a list of all ℓ-cliques in the graph, for ℓ ≥ 1.We use the notation ∆ ℓ to denote the number of ℓ-cliques in the graph.
Let (k, ℓ)-Clique-Detection be the problem of detecting a k-clique in a graph G, given the list of all ℓ-cliques in the graph for some ℓ ∈ {1, . . ., k − 1}.Our framework applies to (k, ℓ)-Clique-Detection for any k ≥ 3, 1 ≤ ℓ < k.We note that while we only mention k-clique detection, we can use wellknown techniques to also find k-cliques in the same runtime up to a log factor (see Section 2.2).Moreover, our algorithm can also be used to count the number of cliques with the same runtime.
In Table 3 we present the exponents of our runtimes for (k, ℓ)-Clique-Detection for small values of k and ℓ assuming ω = 2. See Table 4 for the runtime in terms of the current bound on ω.For ℓ = 1, we captures the best known k-clique detection algorithm and hence matches Hypothesis 1.1.Although our general framework is simple, it is actually quite powerful, and allows us to obtain the first improvement in almost 20 years over the runtime of Eisenbrand   Let (k, ℓ)-Clique-Listing be the problem of listing all k-cliques in a graph G, given all the ℓ-cliques of G. Equivalently, it is the problem of listing t k-cliques in a graph given all the ℓ-cliques, where t is an input to the problem (see a proof in Section 2).
Under the Exact-k-Clique hypothesis we prove lower bounds for (k, ℓ)-Clique-Listing for all k ≥ 3, 1 ≤ ℓ < k.This is Theorem 4.1 in the main body.In fact, Theorem 1.4 is a special case of this theorem.
Moreover, we give a conditionally tight algorithm for graphs with many k-cliques, provided that ω = 2.In particular, the runtime of the algorithm in the theorem below matches the lower bound of Theorem 1.10.
Theorem 1.11 (Informal).If ω = 2, there exists an algorithm for (k, ℓ)-Clique-Listing which runs in time Theorem 1.9 is a special case of this theorem.

Our Techniques
In this section, we highlight our main techniques used in the algorithms and lower bounds.We generalize this approach to k-clique detection in terms of the number of ℓ-cliques for ℓ < k.Suppose we are given a list of all ℓ-cliques in the graph, and we want to find a k-clique.Let a, b, c ∈ [1, k] be as before where a + b + c = k.Let A, B, and C, respectively, be the sets of a-, b-and c-cliques in the graph.We would like to bound their sizes in terms of ∆ ℓ .Let us focus on bounding |A|; bounding |B|, |C| is done similarly.
For a ≥ ℓ, a (probably folklore) bound shows that ∆ a ≤ O(∆ a/ℓ ℓ ) (we also provide a proof for completeness in Section 2).
For a < ℓ, we set a parameter Λ and consider two types of a-cliques: "low-degree" ones that are contained in < Λ ℓ-cliques, and "high-degree" ones that are contained in ≥ Λ ℓ-cliques.There are at most O(∆ ℓ /Λ) high-degree a-cliques.
Consider a low-degree a-clique K and its neighborhood consisting of the nodes adjacent to all nodes of K. We can recurse on the neighborhood: find a (k − a)-clique, given the list of (ℓ − a)cliques formed by excluding K from all ℓ-cliques that contain K.We can bound the recursion runtime using the fact that K has low degree.Since we have handled all low-degree a-cliques, we can set A to be only the O(∆ ℓ /Λ) high-degree a-cliques.Similarly, we can get bounds on |B| and |C|.
Finally, following previous k-clique detection algorithms [NP85, EG04], we perform a rectangular matrix multiplication between an |A| × |B| matrix and a |B| × |C| matrix.By analyzing the recursive steps and setting parameters appropriately, we obtain our detection runtimes.As we show in Examples 3.3 and 3.4, our recursion and its analysis are more careful than in prior work, allowing us to obtain improved runtimes for 4 and 5-clique detection.
We give some explicit examples of this algorithm in Section 3.2.We also analyze the asymptotic efficiency of this algorithm in Section 3.3 and Section 3.4.
Lower bounds for listing.We obtain our lower bound in Theorem 1.10 for listing from the Exact-k-Clique hypothesis.Our lower bound technique can be seen as a generalization of the reduction from Exact Triangle to triangle listing problems in [VX20].
We note that there is also a different generalization of the technique of [VX20] that shows a conditional lower bound for the k-Set-Intersection problem [BCM22].We briefly describe the problem.At a very high level, the lower bound of [BCM22] applies to the following hypergraph problem: the nodes are partitioned into k + 1 parts: V 1 , . . ., V k (these correspond to the sets) and U (this corresponds to the universe).There are hyperedges among the nodes in V 1 , . . ., V k (corresponding to k-set-intersection queries) and there are edges between U and V i for i ∈ [k] (corresponding to elements belonging to each set).Given this hypergraph, the problem asks for each hyperedge, whether its nodes share a common neighbor in U (i.e., whether the sets intersect).As the lower bound of [BCM22] is for a problem in a hypergraph with hyperedges of cardinality > 2, it does not directly apply to our applications.Hypergraph problems are generally harder than their graph counterparts (see e.g.[LVW18]), and there is no easy way to convert a hardness proof for hypergraphs into one for graphs without increasing the instance size significantly.Now, we describe the high-level ideas of our reduction.Without loss of generality, we can assume the input instance of Exact-k-Clique is a k-partite graph on nodes where each V i contains n nodes.At a high level, we first hash the edge weights so that they behave random enough.For simplicity, we assume all edge weights are independently uniformly at random from [−n k , n k ] in this overview (we deal with the randomness properly in our proof).Then we split [−n k , n k ] equally into s contiguous intervals, each of size O(n k /s) for some parameter s.We then enumerate combinations of intervals (L i,j ) 1≤i<j≤k , and consider the subgraph where we only keep edges between V i and V j whose weight is in L i,j .Note that a subgraph cannot contain a k-clique of weight 0 if 0 ̸ ∈ 1≤i<j≤k L i,j (we denote the sum of two intervals as the sumset of them).Therefore, we only need to consider combinations of intervals where 0 . Therefore, there are only O(1) choices for the final interval, and the total number of combinations of intervals we need to consider is O(s ( k 2 )−1 ).For each combination of intervals, we form the subgraph only containing edges with weights in the intervals, and we list all the k-cliques in this subgraph.The expected number of ℓ-cliques in the subgraph is O(n ℓ /s ( ℓ 2 ) ) and the expected number of ) ).For simplicity, we assume these upper bounds always hold in this overview (instead of only holding in expectation).Also, we can list all the ℓ-cliques in the subgraphs efficiently, i.e., in nearly linear time in their number, which is faster than n k when s is small enough.

Then suppose we have an
1−ε time algorithm for listing all k-cliques in a graph with t k-cliques and with a given list of ∆ ℓ ℓ-cliques.We can list all k-cliques in all the subgraphs in time ) time for ε ′ > 0 for sufficiently small s, and violates the Exact-k-Clique hypothesis.
Listing algorithms for graphs with a large number t of k-cliques.Here we discuss how we obtain our optimal algorithm for (k, ℓ)-Clique-Listing in Theorem 1.11, for all ℓ < k and large enough t.We give the full algorithm in Section 5.The framework works for all values of t, but the runtime is conditionally optimal only for large t.We will later explain how to improve upon the framework for small t.
As a first step, we obtain output-sensitive algorithms for k-clique listing in terms of n (ℓ = 1).We then use these algorithms in a black-box way for ℓ ≥ 2.
Björklund, Pagh, Vassilevska W. and Zwick [BPVZ14] gave an algorithm for triangle listing using a dense-sparse paradigm.We generalize this algorithm to k ≥ 4. Let t be the number of k-cliques in the graph which we want to list.
• Dense algorithm: When the input graph has many edges, we use sampling and rectangular matrix multiplication to find all the edges that occur in at most λ k-cliques, for some parameter λ.We then list all k-cliques incident to such edges, and can then delete these edges to obtain a graph with at most O(t/λ) edges.We then call the algorithm for sparse graphs.
• Sparse algorithm: When the input graph has few edges, we list all k-cliques incident to nodes with degree at most x by listing (k − 1)-cliques in their neighborhoods, for some parameter x.We are then left with a graph with at most O(m/x) nodes, at which point we call the dense algorithm.
The key change from the framework of [BPVZ14] is in the sparse algorithm.There, [BPVZ14] uses brute-force to list triangles through low-degree nodes.We on the other hand, recursively use (k − 1, 1)-Clique-Listing algorithms to list the (k − 1)-cliques in the neighborhoods of low-degree nodes.This makes our algorithm efficient, but also complicates the analysis significantly.
For ℓ ≥ 2, we exploit recursion even more: we recursively use algorithms for both k-clique listing in terms of nodes, and (k − 1)-clique listing in terms of (ℓ − 1)-cliques.At a high level, we first find all nodes that are contained in at most y ℓ-cliques, for some parameter y.Then, in the neighborhoods of such nodes, we can find all (k − 1)-cliques based on the list of all (ℓ − 1)-cliques in the neighborhood.We can then delete all the low-degree nodes.The resulting graph now only has O(∆ ℓ /y) nodes.Now, we can call the k-clique listing algorithm in terms of n.
Because of the extra recursion, the analysis gets more complicated, but we are able to keep the algorithms relatively simple.Thus we get the best of both worlds: simplicity and optimality (at least for large t).
The reason why our (k, 1)-Clique-Listing algorithm is only optimal for large t is that our dense algorithm has an inherent cost of Ω(n k−1 ) due to the rectangular matrix multiplication that we use.This bottleneck extends to (k, ℓ)-Clique-Listing for all ℓ as well since all of these algorithms call (k, 1)-Clique-Listing.
Generalizing the listing algorithm to all values of t.In Section 6, we explain how to improve upon our listing framework above when t is smaller.While our general runtime analysis for arbitrary k, t and ℓ quickly gets complicated, here we will focus on a small example, to give intuition.Let us consider the example of 6-clique listing in an n-node graph G assuming ω = 2.The algorithm in Theorem 1.11 has runtime Õ(n 2 5 t 14 15 ) only when t ≥ n 4+ 13 14 , and otherwise runs in Õ(n 5 ) time 3 which is worse than the 6-clique detection runtime Õ(n 4 ).
We improve the runtime for t smaller than the threshold of n 4+ 13 14 by instead following the techniques of [NP85,EG04].We create a new graph G ′ whose nodes correspond to the pairs of nodes of the original graph G, i.e. the new graph has n 2 nodes.We then add an edge between two nodes (a, b) and (c, d) if (a, b, c, d) forms a 4-clique in the original graph.Now, we run the triangle listing algorithm (in [BPVZ14] or Theorem 1.11) in the new graph.This has runtime Õ(n 2 t 2/3 ) when t ≥ (n 2 ) 1.5 = n 3 .This also allows us to obtain an algorithm for all t ≤ n 3 , running in time Õ(n 4 ), the 6-clique detection runtime, which is tight under Hypothesis 1.1.
The corresponding runtime is depicted in blue in Figure 3.More generally, for larger k, we create a new graph where the nodes represent ℓ ′ -cliques in the original graph.Then, we list ⌈k/ℓ ′ ⌉-cliques in the new graph.The best ℓ ′ varies for different t, and this gives us the trade-offs as seen in Figure 2.
Roughly speaking, the algorithm can be viewed as using different dimensions of rectangular matrix multiplication depending on the value of t.For example, in the case of k = 6, the algorithm 3 Clearly, when t is smaller, the runtime can only be smaller or equal, so for any t < n 4+ 13 14 , the runtime of this algorithm is Õ(n for large t ≥ n 4+ 13 14 uses Õ(λ) matrix multiplications of size roughly n × n 4 /λ by n 4 /λ × n for some parameter λ ≥ 1, and this requires at least Ω(n 5 ) time.For n 3 ≤ t ≤ n 4+ 13 14 , the algorithm uses Õ(ρ) matrix multiplications of size n 2 × n 2 /ρ by n 2 /ρ × n 2 for some parameter ρ ≥ 1, which requires at least Ω(n 4 ) time.

Organization
In Section 2, we give necessary definitions and standard algorithms.In Section 3, we show our framework for detecting cliques.In Section 4, we show our lower bound for listing cliques, proving Theorem 1.10.In Section 5, we show our optimal algorithm for clique listing in graphs with many k-cliques, and we extend this algorithm to graphs with fewer k-cliques in Section 6.Finally, we show a more efficient algorithm for 6-clique listing in Section 7.

Preliminaries
Notation.Throughout this paper, we denote the number of nodes in a graph by n, the number of edges by m, and the number of ℓ-cliques by ∆ ℓ .For an ℓ ′ -clique K for some 1 ≤ ℓ ′ ≤ ℓ, we use ∆ ℓ (K) to denote the number of ℓ-cliques containing K. For the special case of ℓ = 2, we use deg(v) := ∆ 2 (v).For integer k, we use K k to denote a k-clique.
For a nonnegative integer n, we use This bound is obtained by splitting the matrix multiplication into B A • C A instances of square matrix multiplication of size A, and it is in general weaker than the bound in [LU18].

Problem Definitions
Now, we define the main clique problems that we consider in this paper.In (k, ℓ)-Clique-Listing, we use t to denote the total number of k-cliques in the graph.However, as we will show in Section 2.2, we can equivalently (up to Õ(1) factor) use t to denote the number of k-cliques we wish to list.

Basic Clique Listing Algorithms
Next, we give some standard algorithms and reductions.Lemma 2.5.Suppose (k, ℓ)-Clique-Detection can be solved in time D(∆ ℓ ).Then, given the list of all ℓ-cliques in a graph, one can find a k-clique in Õ(D(∆ ℓ )) time.
Proof.Let the input graph be G = (V, E), with list L of all ℓ-cliques.Without loss of generality, we may assume that |V | ≤ O(∆ ℓ ) by deleting all nodes that are not in any ℓ-clique (since such a node cannot be in a k-clique).
If |V | ≤ k, brute force and check if the graph has a k-clique.Otherwise, run (k, ℓ)-Clique-Detection on the graph.If it has a k-clique, arbitrarily partition V into k + 1 sets, V 1 , . . ., V k+1 .Now, for each i ∈ [k + 1], consider the subgraph on node set V −i = ∪ j∈[k+1]\{i} V j , and run (k, ℓ)-Clique-Detection.Note that each such subgraph contains at most ∆ ℓ ℓ-cliques.For some i, it must be the case that the graph on V −i contains a k-clique as we partitioned into k + 1 parts and a k-clique has only k nodes.Recurse on exactly one such subgraph V −i on which the detection algorithm returned "YES".
Since the depth of this recursion is Proof.We will prove by induction on the following stronger statement: given a list L of ℓ-cliques in a graph (not necessarily all ℓ-cliques), one can list all k-cliques covered by these ℓ-cliques in the graph in time Õ |L| k/ℓ , where a k-clique K is covered by a list L of ℓ-cliques if every ℓ-clique subgraph of K lies in L.
When ℓ = 1, it suffices to use brute-force to list all k-cliques.Now suppose ℓ > 1.
First, we find all (ℓ − 1)-cliques that are contained in at most x (and at least 1) ℓ-cliques in the list in O(|L|) time.If an (ℓ − 1)-clique K is contained in y ≤ x ℓ-cliques in the list, then we can list all k-cliques containing K in Õ(y k−ℓ+1 ) ≤ Õ(y • x k−ℓ ) time by brute-force.Over all such (ℓ − 1)-cliques, the total running time is thus Õ(|L|x k−ℓ ).
The number of (ℓ − 1)-cliques that are contained in at least one of the ℓ-cliques in L and are not considered above is O(|L|/x).Let L ′ be the list of these O(|L|/x) (ℓ − 1)-cliques.If a k-clique K is not found above, then all of its (ℓ − 1)-clique subgraphs are in the list L ′ , i.e., K is covered by L ′ .By induction, we can find the list of all k-cliques that are covered by (ℓ − 1)-cliques in L ′ in Õ((|L|/x) k/(ℓ−1) ) time.This combined with the k-cliques listed in the previous case gives all the k-cliques covered by L.
The proof of Lemma 2.6 also implies that the number of k-cliques in a graph with Suppose there is a T (∆ ℓ , x) time algorithm for (k, ℓ)-Clique-Listing where the total number of k-cliques is Θ(∆ x ℓ ).Then for any x ′ < x, (k, ℓ)-Clique-Listing on graphs where the total number of k-cliques is Θ(∆ x ′ ℓ ) can be solved in O(T (∆ ℓ , x)) time.Proof.First of all, by Lemma 2.6, x ≤ k ℓ .We then add a complete k-partite graph to the graph where the number of nodes in each part is ∆ x/k ℓ .This way, the number of k-cliques in the graph is increased by ∆ x ℓ , and the number of ℓ-cliques is increased by is the new number of ℓ-cliques in the graph.Therefore, we can run the T (∆ ℓ , x) time algorithm on the new graph in Θ(T (∆ ℓ , x)) time.Once we list all the k-cliques in the new graph, we can return those that belong to the original graph.
Let f (∆ ℓ , t) be the runtime of (k, ℓ)-Clique-Listing when the graph has (an unknown number of) t cliques in total, and let g(∆ ℓ , t) be the runtime of listing min{∆ k , t} distinct k-cliques, given the list of all ℓ-cliques in the graph and a specified t as input.We assume f ( Õ(∆ ℓ ), Õ(t)) = Õ(f (∆ ℓ , t)) and g( Õ(∆ ℓ ), Õ(t)) = Õ(g(∆ ℓ , t)).This is true for all of our algorithms as well as any algorithm that has at most a polynomial dependence on ∆ ℓ and t.
The following lemma shows that f (∆ ℓ , t) = Θ(g(∆ ℓ , t)).Therefore, we use both of these two notions interchangeably for the definition of (k, ℓ)-Clique-Listing.In particular, given an instance of (k, ℓ)-Clique-Listing with an unknown number of k-cliques, the proof of Lemma 2.8 allows us to assume that we know an 2-approximation of ∆ k , with only Õ(1) loss in the running time.
Proof.We first show f (∆ ℓ , t) = Õ(g(∆ ℓ , t)).Let A be an algorithm for listing a specified number of k-cliques.Given an n-node graph G and the list of ∆ ℓ cliques, we run O(log n) instances of A in parallel.More specifically, we specify these instances to list 2 0 , 2 1 , . . ., 2 ⌈log(n k +1)⌉ k-cliques respectively.We wait until one of the instances finishes listing all k-cliques in the graph.Suppose t is the actual number of k-cliques in the graph, and we specify A to list 2 ⌈log t⌉ k-cliques, then it will finish within g(∆ ℓ , O(t)) = Õ(g(∆ ℓ , t)) time.Since we run O(log n) instances in parallel, the overall running time is Õ(g(∆ ℓ , t)).
Next, we show g(∆ ℓ , t) = Õ(f (∆ ℓ , t)).Let B be an algorithm for (k, ℓ)-Clique-Listing.Given a graph G = (V, E), a list of all ℓ-cliques and a parameter t, we need to list min{t, time, and we are done.Now, we assume the number of k-cliques in G is at least 2 k t.
Clearly, the number of k-cliques in G ′ is at least 2 k (k!)t, and we need to list (k!)t distinct k-cliques in G ′ in order to produce t distinct k-cliques in G. Also, the number of ℓ-cliques in G ′ is O(∆ ℓ ).Then we partition each V i arbitrarily into two sets V i,0 and V i,1 of size n/2.We run B on each of the 2 k induced subgraphs on the sets By the pigenhole principle, one of the subgraphs contain at least (k!)t k-cliques.If B finishes on that subgraph, we are done.Otherwise, B does not finish on that subgraph, and by Lemma 2.7, that subgraph must have more than 2 k (k!)t distinct k-cliques, so we can recurse on that induced subgraph.Overall, the running time is Õ(f (∆ ℓ , t)) because the recursion depth is O(log n).
[BPVZ14] gave similar reductions from listing a specified number of t triangles to listing all ∆ 3 triangles in n-node or m-edge graphs.Their reduction is more efficient than ours when t is much smaller than ∆ 3 .However, their reduction requires an algorithm for counting the number of triangles.We instead provide a black box reduction that does not rely on counting, that works for arbitrary k, ℓ, and is more self-contained and efficient enough for our purpose.

Detecting Cliques
In this section, we first describe our algorithm for (k, ℓ)-Clique-Detection, and then analyze its running time in some interesting cases.

General Detection Framework
Now we describe a generic algorithm for (k, ℓ)-Clique-Detection for k ≥ 3 (for k = 2, we trivially list all edges in the graph, so g(2, 1) = 2) in Algorithm 1.
The correctness of this algorithm is immediate.We also remark that the algorithm can be used to count the number of k-cliques, by replacing all the recursive calls with the counting version of the algorithm, using the matrix multiplication to count the number of k-cliques in the remaining graph, and properly summing up and scaling the numbers.Clearly, the counting version of the algorithm will have the same running time.

Examples
Let us give some explicit examples to illustrate the algorithm.).The running time of this step is • Finally, we conduct a usual matrix multiplication of dimensions S a , S b , S c in time MM(S a , S b , S c ) as follows.If we find a k-clique, output yes, otherwise we output no.
).Then we have S a ≤ Θ(m), S b , S c ≤ Θ(m 1−x b ).Thus, the running time for the matrix multiplication of dimensions S a , S b , S c is Õ(m ω(1,1−x b ,1−x b ) ).The algorithm chooses 2 by setting x b = 1 2 .For the current best bound of square and rectangular matrix multiplication [VXXZ24], we can set x b = 0.478 to get an upper bound g(4, 2) ≤ 1.657.As seen in Table 2, this is an improvement over the previous best algorithm of Eisenbrand and Grandoni [EG04].The key difference between our algorithm and [EG04]'s algorithm is that, after they perform a similar first stage, they recursively call a (4, 1)-Clique-Detection algorithm on graphs with S b nodes, losing the information that the graph has S a = m edges to begin with.We instead utilize this information with rectangular matrix multiplication to get a better running time.
Example 3.5 (More Small Examples).See Tables 3 and 4 for more examples of the running times of our algorithm.These running times were obtained by finding the optimal values of a, b, c using dynamic programming.
From previous examples, one might wonder whether the algorithm always sets a, b, c as close to k/3 as possible.The following example shows that it is not the case (for ω = 2).

Upper Bound for (k, k − h)-Clique-Detection
In this section, we analyze the running time of our algorithm for (k, k − h)-Clique-Detection for some constant h = O(1).For convenience, let e h (k) = g(k, k − h).
We start with the following lemma.
Proof.We prove the statement by induction.We skip the base case k = h + 1 as it works similarly as the induction step (except for h = 1, in which case e h (2) = 2 and e h (3) = 2ω ω+1 ≤ e h (2), as the algorithm handles (2, 1)-Clique-Detection specially).Suppose the statement is already true for all smaller k.
We then compare exponents related to S b and S ), a smaller exponent.
• If b = ℓ.In this case, S b = Õ(∆ ℓ ) and we will have b ), the same exponent as the bound of S b .Also, the cost for having this bound is Õ(( ), so we can ignore the cost as it is near-linear time.Proposition 3.7.e h (k We also show that our choices of a, b, c are not too far away from optimal, at least when ω = 2.In the following proposition, recall e h (k) is the exponent of our algorithm, instead of the best exponent for (k, k − h)-Clique-Detection.
1 for some sufficiently large constant M > 1 because our algorithm does not achieve almost linear time, i.e., it always has e h (k) > 1 and thus f h (k) < ∞.
Let k > k 0 , and let a, b, c be the optimal choices for (k, k − h)-Clique-Detection.We will show by induction that f h (k) ≤ M k ρ − 1.Consider two cases.
For the first case, assume a < ℓ.Let x a , x b , x c be the optimal parameters for (k, k−h)-Clique-Detection, and if there are multiple choices, we choose one set of parameters with smallest x a + x b + x c .Then, the bound of our running time is (up to Õ(1) factors) . Therefore, we can slightly increase x b , and the running time of the algorithm will not be worse.This contradicts with the optimality of x a , x b , x c and minimality of x a + x b + x c .Thus, we must have Substituting e h by f h gives the following cleaner formula: As the algorithm chooses the optimal a, b, c, we have that By Lemma 3.6, f h (k − b) is nondecreasing when b increases, so we can pick b to be as large as possible for fixed a. Therefore, for fixed a, we choose c = ⌊ k−a 2 ⌋ and b = ⌈ k−a 2 ⌉.Therefore, we can rewrite

By the induction assumption
which completes the induction step for this case.
For the other case, assume a ≥ ℓ.Note that we must have b, c < ℓ as 2ℓ > k.Let x b , x c be the optimal parameters.Similar as before, we can assume x b ≤ x c .Then, the bound of our running time is (up to Õ(1) factors) The optimal way to balance is to set Note that it is possible that x b > 1 in this setting, but if that happens, e h (k) > e h (k − b), which by Lemma 3.6, can never be optimal.In terms of f h , this implies that As the algorithm chooses the optimal a, b, c, we have that By Lemma 3.6, f h (k − b) is nondecreasing when b increases, so we can pick b to be as large as possible for fixed a. Therefore, for fixed a, we choose c = ⌊ k−a 2 ⌋ and b = ⌈ k−a 2 ⌉.Thus, we can rewrite By induction, it can be further upper bounded by max as M, ρ > 1.This finishes the induction step for this case.
Overall, we have shown that 2) .

Upper Bound for (Cℓ, ℓ)-Clique-Detection
Define a sequence of functions (f i ) i≥0 as follows: The functions have the following recurrence relation, whose proof we omit as it is straightforward algebra.
Claim 3.9.f 0 (C) = ωC 3 and Then we can express the running time of (Cℓ, ℓ)-Clique-Detection for sufficiently large ℓ in terms of the functions f i : Proof.We prove by induction on i.When i = 0, k ≥ Cℓ ≥ 3ℓ.Therefore, we can apply the (k, ℓ)-Clique-Detection example in Section 3.2 for ℓ ≤ ⌊k/3⌋ to get g(k, ℓ) ≤ ω(⌈k/3⌉, ⌈(k − 1)/3⌉, ⌊k/3⌋)/ℓ.This leads to When i > 0, assume the claim is correct for i − 1.Similar to the proof of Proposition 3.7, we choose a, b, c in our (k, ℓ)-Clique-Detection algorithm so that ⌊k/3⌋ = c ≤ b ≤ a = ⌈k/3⌉.By the same analysis, the running time exponent can then be bounded by ω Therefore, the running time exponent of (k, ℓ)-Clique-Detection can be bounded by In Figure 4, we compare the bound obtained from Theorem 3.10 with the actual running time of Algorithm 1 computed by dynamic programming for 3 ≤ k ≤ 200.In particular, for various values of C, we plot the exponent of (k, ⌊k/C⌋)-Clique-Detection against the upper bound obtained from Theorem 3.10 (without the o ℓ (1) factor).Figure 4 shows that the estimates given by Theorem 3.10 are actually quite close to the actual exponents, and the values indeed converge to our bound.

Lower Bounds for Listing Cliques
In this section, we will show our conditional lower bound for (k, ℓ)-Clique-Listing under the Exactk-Clique hypothesis.

Proof. First, we can assume
Without loss of generality, we assume the edge weights w of G are from F p for some sufficiently large prime p = n O(k) = n O(1) .Then we sample x ∼ F p uniformly at random.For every i ∈ [k], and every node v ∈ V i , we sample k − 1 random variables (y v,j ) j∈[k]\{i} ∼ F p where j∈[k]\{i} y v,j = 0 uniformly at random.Note that (y v,j ) j∈[k]\{i} are (k − 2)-wise independent.
For every 1 ≤ i < j ≤ k, and It is not difficult to verify that, whenever x ̸ = 0, the sets of exact-k-cliques in the graph with weight w and with weight w ′ are the same.
Then we partition F p into s contiguous intervals, each of length O(p/s), for some s to be chosen later where Ω(1) ≤ s ≤ O(n 2 k−1 ).Consider all combinations of intervals (L i,j ) 1≤i<j≤k , where 0 ∈ 1≤i<j≤k L i,j .If we fix an arbitrary choice of the first k 2 − 1 intervals, their sumset is an interval of length O(p/s).Thus, there is only O(1) choices for the last interval in order for their sumset to contain 0. Hence, there are only O(s ( k 2 )−1 ) such combinations.For each such combination, we construct an instance of (k, ℓ)-Clique-Listing as follows: create an unweighted graph H such that an edge (v i , v j ) ∈ V i × V j for i < j in G is added to H if and only if w ′ (v i , v j ) ∈ L i,j .The high level idea then is to list a certain number of k-cliques in H and verify whether any of them is an exact-k-clique in G. Clearly, this algorithm never finds an exact-k-clique if G does not have one, so it suffices to show that when G does have an exact-k-clique, the algorithm finds it with decent probability.
Let (u 1 , . . ., u k ) be an arbitrary exact-k-clique in G. Clearly, there exists one combination of intervals such that all edges in this exact-k-clique are in the corresponding subgraph H 0 .For any i, j and edge which happens with probability O(1/s) as long as {u i , u j } ̸ = {v i , v j }.The following lemma shows that the random variables w ′ (u i , u j ) − w ′ (v i , v j ) are fairly independent.Lemma 4.2.If (v 1 , . . ., v k ) is not an exact-k-clique w.r.t.w, and (u 1 , . . ., u k ) shares exactly c nodes indexed by S with (v 1 , . . ., v k ), then the random variables Proof.By symmetry, we can assume |S| = [c], and we need to show that Define α i,j = w ′ (u i , u j ) − w ′ (v i , v j ).Let β be the sum of all the α i,j : are independent is equivalent to showing that the variables are independent when one of the variables is replaced with the sums of the variables.Namely, it suffices to show {α i,j } c+1≤j≤k Consider the following ordering of the variables: Conditioned on the previous variables, all α j,i variables in this list has an additive term y u j ,i that is independent of all previous variables.Thus, this list of variables is independent.
Corollary 4.3.For any ℓ-clique on nodes (v i ) i∈T in G that shares exactly c nodes indexed by S with (u 1 , . . ., u k ), the random variables

Proof. By symmetry, we can assume [T ] = [ℓ] and [S] = [c]
. We can complete this ℓ-clique to a nonzero k-clique (v 1 , . . ., v k ) (we can assume any ℓ-clique is in some nonzero k-clique by adding hypothetical nodes to the graph in this analysis).
By Lemma 4.2, {w are also independent.
Now we can compute the expected number of ℓ-cliques in H 0 .The number of ℓ-cliques in G that share exactly c nodes with (u 1 , . . since by our choice of s = O(n 2/(k−1) ), we have that s ( c 2 ) = O(n c ).Similarly, the expected number of k-cliques in H 0 that do not correspond to exact-k-cliques in . Therefore, by Markov's inequality and union bound, with probability at least 1 − 1/Ω(log n), the number of ℓ-cliques in H 0 is at most n ℓ log n/s ( ℓ 2 ) and the number of k-cliques in H 0 that do not correspond to exact-k-cliques in G is at most Suppose for the sake of contradiction that there is a (k, ℓ)-Clique-Listing algorithm A for instances with specified t = Θ(∆ γ ℓ ) with running time 1−ε for some ε > 0. Then consider the following algorithm for Exact-k-Clique: 1. First, hash the weights of the graph and enumerate O(s ( k 2 )−1 ) graphs H as described earlier.2. Enumerate all ℓ-cliques in G, and pre-compute which graphs H contain each ℓ-clique.Since each ℓ-clique exists in s ( k 2 )−1−( ℓ 2 ) graphs H, and this list of graphs can be listed efficiently, this step costs for some δ ′ > 0. 3. From the previous step, we have a list of ℓ-cliques for each graph H.If some H contains more than n ℓ log n/s ( ℓ 2 ) ℓ-cliques, we skip it.If it contains fewer than 0.99n ℓ /s ( ℓ 2 ) ℓ-cliques, we add a complete ℓ-partite graphs with n ′ nodes on each part, for some n ′ , so that the total number of ℓ-cliques in the new graph reaches 0.99 For graphs H which we did not skip in the previous step, we run A on it with t = n k log n/s ( k 2 ) + 1.For any k-clique listed by A, we test whether it is an exact-k-clique in G.This step takes s ) )) time. 5.If any exact-k-clique is found in the previous step, we return YES for the Exact-k-Clique instance; otherwise, we return NO.
Clearly, if G contains no exact-k-clique, our algorithm is always correct.If G contains any exactk-clique, let H 0 be the constructed graph containing it.As discussed previously, with probability 1 − 1/Ω(log n), the number of ℓ-cliques in H 0 is at most n ℓ log n/s ( ℓ 2 ) and the number of k-cliques in H 0 that do not correspond to exact-k-cliques in G is at most n k log n/s ( k 2 ) .In this case, we will not skip H 0 in Step 3, and listing t = n k log n/s ( k 2 ) + 1 k-cliques in Step 4 guarantees an exact-kclique.Thus, we will find an exact-k-clique with probability 1 − 1/Ω(log n), which can be boosted to 1 − 1/ poly(n) by repeating the algorithm O(log n) times.
Overall, this algorithm only needs time (besides the previous Õ( As s = O(n 2 k−1 ), the above running time can be further upper bounded by

Optimal Listing Algorithms for Graphs with Many k-Cliques
In this section, we give a (k, 1)-Clique-Listing algorithm that is optimal for graphs with many kcliques under Hypothesis 1.3.This algorithm can be seen as a generalization of the densifying and sparsifying paradigm of [BPVZ14].
We then show how we can extend this algorithm to obtain the conditionally optimal algorithms for all (k, ℓ)-Clique-Listing for graphs with many k-cliques.

Algorithm
First, we describe the algorithm for (k, 1)-Clique-Listing in Algorithm 2.
• Output: List of k-cliques in G.
• The Algorithm: 2. Choose a parameter λ.Let an edge be λ-light if it is in fewer than λ k-cliques.
3. Use the algorithm in Lemma 2.6 to obtain a list L of all (k − 2)-cliques (there are at most n k−2 such cliques).4. Initialize an empty list T . 5. Repeat the following O(λ log n) times: -Sample a subset L ′ of L of size |L|/λ.
-Construct adjacency matrices A and A where the rows are indexed by V and columns are indexed by -For every edge (u, v) 7. Delete all λ-light edges from E to obtain E ′ (all λ-light edges are found in Step 5 w.h.p.).8.Call Sparse(G ′ := (V, E ′ ), k 2 t/λ, t).Sparse(G := (V, E), m, t): • Input: Graph G = (V, E) with |E| ≤ m and at most t k-cliques.
• Output: List of k-cliques in G.
• The Algorithm: 3. Find all nodes such that deg(v) ≤ x, and call the (k − 1, 1)-Clique-Listing algorithm in the neighbourhoods of all such nodes with n ′ = deg(v).4. Delete all nodes in V of degree less than x to obtain set V ′ .

Call Dense(G
In the Dense algorithm, we use matrix multiplication to enumerate all k-cliques containing light edges, i.e. edges that are part of very few k-cliques.These edges are then removed to result in a sparse graph with only edges that are part of many k-cliques. In the Sparse algorithm, we enumerate all k-cliques containing low-degree nodes by recursively listing all (k − 1)-cliques in their neighborhoods, and delete all such nodes.Deleting these nodes results in a dense graph with only high degree nodes.While one could brute-force the (k−1)-cliques in the neighborhoods, our key insight is that we can instead recursively use a (k −1, 1)-Clique-Listing algorithm to be more efficient.
We first show the correctness of Algorithm 2 and defer its runtime analysis to Section 5.3.
Correctness.It is clear that the Sparse algorithm finds all k-cliques in the neighborhoods of low-degree nodes.At the end of the algorithm, since the graph has ∆ ℓ ℓ-cliques and only nodes with degree at least x, there are at most 2m/x nodes left in the graph.Now, we argue that the Dense algorithm lists all k-cliques containing λ-light edges.We argue that Step 5 finds all λ-light edges with high probability.For every (u, v) ∈ E, let L u,v denote the set of all (k − 2)-cliques that form k-cliques with nodes u and v. Since we sample L ′ of size |L|/λ, the probability that Therefore, by choosing O(λ log n) random sets of size |L|/λ, with high probability, we find all k-cliques containing λ-light edges.
Algorithm 3 (k, ℓ)-Clique-Listing Algorithm for large t ≥ n γ k,ℓ , where γ k,ℓ is defined in Theorem 5.10 Input: A graph G and a list L of all ℓ-cliques.
Output: All k-cliques in the graph.
The Algorithm: 1.Call a node v light if ∆ ℓ (v) ≤ x, for some parameter x.
Correctness.It is clear that the algorithm lists all k-cliques incident to low-degree nodes.Since all remaining nodes are in at least x ℓ-cliques, and each ℓ-cliques contains at most ℓ nodes, we can bound the remaining number of nodes by ℓ∆ ℓ /x.
To illustrate these algorithms, we first show simplified analyses of Algorithms 2 and 3 for the case of k = 4 and k = 5 assuming that ω = 2 in Section 5.2.We give more detailed analyses in terms of ω in Sections 5.3 and 5.4.• (4, 1)-Clique-Listing can be solved in Õ(n 3 + n 2/3 t 5/6 ) if G has n nodes.
Proof.Consider the Dense algorithm.In this case, L is a list of all (up to n 2 ) edges.Therefore, the runtime of this step can be bounded by We can also upper bound m by n 2 to obtain the following bound without a dependence on n: D(n, t) ≤ D(n, n 2 , t) ≤ Õ(n 3 + λn 2 ) + S(6t/λ, t).
(4, 2)-Clique-Listing analysis.To obtain a runtime for (4, 2)-Clique-Listing, we analyze the runtime of S(m, t).Here, we use our bound D ′ in terms of n, m and t to get a tighter analysis (instead of just n and t).
(4, 3)-Clique-Listing analysis.Note that while we can use Algorithm 3 to bound the runtime in this case, we instead provide a more efficient algorithm shown in Algorithm 4 for (4, 3)-Clique-Listing.
Algorithm 4 (4, 3)-Clique-Listing algorithm Input: Graph G = (V, E), and a list L of all triangles in G.
Output: A list of all k-cliques in G.
Consider the Sparse algorithm.In this case, we call (4, 1)-Clique-Listing in the neighborhoods of all low-degree nodes, so by using Hölder's inequality as in Corollary 2.2.

Analysis for (k, 1)-Clique-Listing
For k ≥ 2, define The following identities are immediate.
Claim 5.3.For any k ≥ 3, there exists an algorithm that lists all t k-cliques in time Õ(n

2
, therefore giving a runtime of Õ(n Proof.For k = 2, the brute-force algorithm runs in n 2 time, and it is easy to check that x k = 2 and y k = 1.Moreover, this bound holds for all values of t, so we can set γ k = 0.
For k = 3, [BPVZ14] give an algorithm that runs in time O(n ω +n 3(ω−1) 5−ω t 2(3−ω) 5−ω ), which can easily be verified to match the form of the theorem statement.Rewriting this as O(n ω + n α 3 t 1− α 3 3 ), it is easy to see that this term dominates exactly when t ≥ n 3 1− 3−ω 3−α 3 , which corresponds exactly to our setting of γ 3 .Now suppose k ≥ 3 and that the theorem statement is true for all (r, 1)-Clique-Listing for all r < k.In particular, suppose the runtime of (k − 1, 1)-Clique-Listing is bounded by for some γ k−1 .In fact, since the runtime is non-decreasing in the parameter ∆ k−1 by Lemma 2.7, one can bound the above runtime for any ∆ k by: Runtime analysis.Let D(n, t) be the running time of Dense(G, n, t), and let S(m, t) be the running time of Sparse(G, m, t).Note that ignoring Õ(1) factors By the standard trick of decomposing a rectangular matrix product into smaller square matrix products, one can bound Therefore, we can rewrite For Sparse(G, m, t), note that the runtime is bounded by: One can use Hölder's inequality as in Corollary 2.2 to bound .
Thus, we have that (once again ignoring Õ(1) factors) Unravelling the runtime of Dense(G, n, t), we therefore have If one chooses λ and x so that First, suppose that the term t nx 3−ω n ω(k−2)−2k+6 dominates n k−3+ω and the term )−1 (we show that this is in fact true for our choice of γ k later) .Then, Choosing x to equate the two terms, we set Substituting this into (3), we have it is easy to verify that the above bound is in fact of the form n α k t 1− α k k .Moreover, note that Bound on γ k .Now, it suffices to show that for t ≥ n γ k , for our choice of x, The first inequality (6) is trivially satisfied since we chose γ k ≥ k 1 − 3−ω k−α k .It suffices to show that the second inequality (7) is also satisfied.Rearranging, we see that it suffices to show that x γ k−1 ≤ t n .Plugging in x from (4) and γ k−1 and rearranging, we obtain that this holds as long as To show that all t ≥ n γ k satisfies the above inequality, it suffices to check that the exponent above is at most γ k , i.e., it suffices to check that to obtain the following equivalent inequality: When ω > 2, we substitute our recursive formula for α k from (5) and rearrange to obtain that the inequality is satisfied for all k > 0 as long as Claim 5.5.For 2 ≤ ω ≤ 3 and k ≥ 2, we have k(ω − 2) ≤ α k .
Proof.We proceed by induction.First, we note that α 2 = 2 and Therefore, α k ≤ k as long as which is indeed true by Claim 5.5.Therefore, the bounds in (8) indeed hold, thereby completing the proof.
Using the bound of Theorem 5.4 and note that the runtime of (k, ℓ)-Clique-Listing is monotone with respect to t (Lemma 2.7), we immediately get the following corollaries.
Corollary 5.7 (Theorem 1.5).Given a graph on n nodes, one can list t 4-cliques in Corollary 5.8 (Theorem 1.6).Given a graph on n nodes, one can list t 5-cliques in where we use Hölder's inequality to bound the second term.Suppose for now that t is large enough so that the second term dominates.
In Step 4, by Theorem 5.4, the runtime can be bounded by (k∆ ℓ /x) Suppose that t is large enough so that this inequality holds.Then, the runtime of the algorithm is we get a runtime of (omitting Õ(1) factors) by Claim 5.9.
Bound on γ k,ℓ if ω = 2.If ℓ = 1, then γ k,1 matches the value of γ k we obtained from Theorem 5.4.Thus, we assume ℓ > 1 and the bound for all ℓ ′ < ℓ holds.Recall that when ω = 2, α k = 2 k−1 and α k−1,ℓ−1 = 2 (ℓ−1)(k−ℓ) .Therefore, substituting this into (11), we obtain First, we check that (10) holds.In fact, ℓ , which is indeed true by our choice of γ k,ℓ .Now, it suffices to show that if t ≥ ∆ γ k,ℓ ℓ , then the second term dominates in (9).In fact, the second term dominates as long as where the last equality holds because by induction.Hence, it suffices to show that γ k,ℓ is at least the exponent on the right-hand side.
which is true since k ≥ 3.

Extending the Algorithm to Graphs with Fewer k-Cliques
In this section, we show how to apply our algorithm in Section 5 which only works for very large t (or rather, does not have improved runtime for smaller t) to other ranges of t as well, via black-box reductions.
Theorem 6.1.Suppose for every 1 ≤ ℓ < k, (k, ℓ)-Clique-Listing can be solved in Õ(∆ Proof.Let G be the input of a (k, ℓ)-Clique-Listing instance.Without loss of generality, assume G is k-partite with parts V 1 , . . ., V k .Create a new k ′ -partite graph G ′ on node parts  ) time as well.Thus, to solve (k, ℓ)-Clique-Listing on G with t k-cliques, it suffices to solve (k ′ , ℓ ′ )-Clique-Listing on G ′ with t k ′ -cliques.The theorem thus easily follows.
Figure 5 shows a pictorial representation of the (12, 1)-Clique-Listing runtime.We can similarly obtain the following corollary for (k, 2)-Clique-Listing.
The corollary then follows.

6-Clique Madness
In this section, we show that our algorithm in Section 5 is improvable by showing a faster algorithm for (6, 1)-Clique-Listing.See Figure 3 for a comparison of the bounds achieved by the algorithm in Section 6 and this section.The new algorithm for (6, 1)-Clique-Listing comprises two parts: Algorithms 5 and 6.Remark 7.1.Intuitively, Algorithm 5 is similar to Algorithm 3 with one main difference: we first bound the number of 4-cliques in the graph by O(t/ρ) by getting rid of light 4-cliques rather than simply bounding the number of 4-cliques by n 4 .This idea allows us to get a better bound on γ 6 than in Theorem 5.4.This idea can also be extended to all k ≥ 6. Lemma 7.2.Algorithm 5 is correct and runs in Õ(n 4 + n 5/2 t 1/2 + n 2/5 t 14/15 ) time if ω = 2.
Proof.After Line 3, the algorithm has listed all K 6 containing at least one light K 4 .After Line 5, the algorithm has also listed all K 6 containing a dense K 4 and a disjoint light edge.Thus, after this point, only K 6 containing no light edges are not listed.Then clearly, the next two steps list all such K 6 .
The running time, excluding the recursion, is (if ω = 2) Õ   ρMM n We also set λ = max{1, 15t xn }, so that each recursion level decreases n by a factor of at least 2. The overall time complexity is thus within Õ(1) of the time complexity of the first recursion level.The running time then becomes (assuming 15t xn ≥ 1) Õ ρn 4 + nt x + nt ρ + x 4 n + t 9/10 x 1/2 n 1/10 .
The running time of the algorithm is thus • Õ(n 4 ) when t ≤ n 3 by setting ρ = 1 and x = 1 (even though in this setting, 15t xn will be less than 1 if t < n/15, the running time still holds by setting λ = 1);

Figure 1 :
Figure1: Upper and lower bounds for 4 and 5-cliques in graphs with m edges, if ω = 2. Here, r is such that one can list t 4-cliques or 5-cliques respectively, in Õ(m r ) time.The blue line corresponds to our upper bound from Theorems 1.7 and 1.8, the dashed red line denotes our lower bound from Theorem 1.10, and the dashed black line corresponds to the lower bound from Hypothesis 1.1.The shaded region highlights the portions of the algorithms which are not conditionally optimal. 0

Figure 3 :
Figure 3: Upper and lower bounds for listing 6-cliques in n-node graphs if ω = 2. Here, r is such that one can list t 6-cliques in Õ(n r ) time.The blue line corresponds to the upper bound of our general listing algorithm, the black line corresponds to the upper bound of our refined algorithm, and the dashed red line denotes lower bound from Theorem 1.4 and Hypothesis 1.1.
[n] to denote {1, 2, . . ., n}.Matrix multiplication.We use ω < 2.372 to denote the matrix multiplication exponent[DWZ23,VXXZ24].For any constants a, b, c ≥ 0, we use ω(a, b, c) to denote the exponent of multiplying an n a × n b matrix by an n b × n c matrix.The current best bounds for rectangular matrix multiplication are given by[VXXZ24].We denote by MM(A, B, C) the runtime of multiplying an A × B by a B × C matrix.If A ≤ B ≤ C, we can loosely bound MM(A, B, C) in terms of ω as follows:

Definition 2 .
3 ((k, ℓ)-Clique-Detection).Given a graph G = (V, E) and the list L of all ℓ-cliques in G, decide whether G contains a k-clique.Definition 2.4 ((k, ℓ)-Clique-Listing).Given a graph G = (V, E) and the list L of all ℓ-cliques in G, list all k-cliques in G.
(k, 1)-Clique-Detection.The simplest example is (k, 1)-Clique-Detection for k ≥ 3. Let ⌊k/3⌋ ≤ c ≤ b ≤ a ≤ ⌈k/3⌉ be integers such that a + b + c = k, which is one of the possible choices of a, b, c for the algorithm.Note that c = ⌊k/3⌋, b = ⌈(k − 1)/3⌉, a = ⌈k/3⌉.Since a, b, c ≥ ℓ = 1, the algorithm would choose to use Lemma 2.6 to bound the number of cliques of sizes a, b, c as n a , n b , n c respectively.Thus, the running time of the algorithm is Õ(n ω(a,b,c) ) = Õ(n β(k) ), matching the previous running time [EG04].Algorithm 1 Generic (k, ℓ)-Clique-Detection algorithm.Input: Graph G = (V, E) and the list L of all ℓ-cliques.Output: Output yes if G contains a k-cliques, and no otherwise.The Algorithm: • Let integers k ≥ a ≥ b ≥ c ≥ 1 be such that k = a + b + c (the algorithm chooses a, b, c optimally).Then goal is then to bound the number of d-cliques for d ∈ {a, b, c}.-If d ≥ ℓ, we can use Lemma 2.6 to upper bound the number of d-cliques with S d = Θ(∆ d/ℓ ℓ ), and add these d-cliques to a list L d in the same time.-If d < ℓ, for every d-clique K with ∆ ℓ (K) ≤ ∆ x d ℓ (for some parameter x d ∈ [0, 1] to be chosen), we check if K is in a k-clique by recursively running (k−d, ℓ−d)-Clique-Detection in its neighbourhood.Then, let L d denote the set of remaining d-cliques.Then, S d := |L d | = Θ(∆ 1−x d ℓ Create a matrix X whose rows are indexed by a-cliques in L a and columns are indexed by b-cliques in L b .Set A[K a , K b ] = 1 if the nodes of K a and K b form an (a + b)-clique, and 0 otherwise.-Create a matrix Y whose rows are indexed by b-cliques in L b and columns are indexed by c-cliques in L c , and set the entries similarly.-Compute Z = XY .For each pair of remaining a-clique K a and c-clique K c that form an (a+c)-clique, check if Z[K a , K c ] > 0. If such an entry exists, output yes.Otherwise, output no.(k, ℓ)-Clique-Detection for ℓ ≤ ⌊k/3⌋.Similar as above, let c = ⌊k/3⌋, b = ⌈(k − 1)/3⌉, a = ⌈k/3⌉ and the algorithm would choose to use Lemma 2.6 to bound the number of cliques of sizes a, b, c.Thus, the running time of the algorithm is Õ(∆ ω(a/ℓ,b/ℓ,c/ℓ) ℓ) ≤ Õ(∆ ω(⌈k/3⌉,⌈(k−1)/3⌉,⌊k/3⌋)/ℓ ℓ

•
If b < ℓ, the exponent of the running time for bounding S b in (k, ℓ)-Clique-Detection is 1 + x b (e h (k − b) − 1), and S b is bounded by ∆ 1−x b ℓ .Let x ′ b ′ be equal to x b in the algorithm for (k +1, ℓ+1)-Clique-Detection.Then notice that the exponent for running time is 1+x ′ b ′ (e h (k + 1−b ′ )−1) = 1+x b (e h (k −b+1)−1).By the induction assumption, e h (k −b+1) ≤ e h (k −b), so 1 + x b (e h (k − b + 1) − 1) is upper bounded by the running time exponent of the corresponding case in (k, ℓ)-Clique-Detection.Note that this case does not happen in the base case k = h + 1, as b < ℓ = 1 can never happen, so we can safely apply the induction assumption.The bound on S ′ b ′ is (∆ ′ ℓ ′ ) 1−x b , with the same exponent as S b in (k, ℓ)-Clique-Detection.The comparison of the exponents related to S c and S ′ c ′ works similarly.Thus, e h (k +1) ≤ e h (k).

Figure 4 :
Figure 4: Comparison of our detection time for (k, ⌊k/C⌋) (assuming ω = 2) between the actual running time exponent of Algorithm 1 and the upper bound from Theorem 3.10 (without the o ℓ (1) term; here ℓ = ⌊k/C⌋).The actual exponents are computed by dynamic programming.The colored lines denote the actual running time exponent, and the dashed lines denote the values of f i (C) for appropriately chosen i.Note that the upper bound from Theorem 3.10 can be lower than the actual exponent because we omitted the o ℓ (1) factors.

k = 4
and k = 5 assuming ω = 2 In this section, we illustrate how to analyze the runtime for listing algorithm by considering the cases where k = 4 or k = 5.Proposition 5.1.Suppose ω = 2.Then, given a graph G with t 4-cliques,
-cliques in G ′ have one-to-one correspondence with k-cliques in G, so it suffices to listt k ′ -cliques in G ′ in order to list t k-cliques in G. Furthermore, distinct ℓ ′ -clique in G ′ corresponds to distinct clique in G.Depending on whether an ℓ ′ -clique uses a node in U k ′ , it corresponds to either an (sℓ ′ )-clique in G or an (sℓ ′ + k − sk ′ )-clique in G. Either way, it is a clique of size at most sℓ ′ .Thus, by Lemma 2.6, there are Õ(∆

Figure 5 :
Figure 5: Upper and lower bounds for the runtime r for (12, 1)-Clique-Listing for a graph with t k-cliques, assuming ω = 2.The upper bound is from Example 6.3 and the lower bounds are from Proposition 3.7 and Theorem 4.1.

Table 2
[VXXZ24] of the current bounds for square and rectangular matrix multiplication[VXXZ24].

Table 2 :
The table contains exponents c such that 4 and 5-clique detection is in O(m c ) time.For (4, 2)-Clique-Detection and (5, 2)-Clique-Detection, the previous exponent was given by β
is not necessarily divisible by 3.For some integers a, b, c ∈ [1, k] where a+b+c = k, the algorithm creates a tripartite graph on node parts A, B, C with n a , n b , n c nodes respectively, which represent tuples of a, b, c nodes respectively.It also suffices to keep only the tuples of nodes that form a clique in the original graph.For every node (u 1 , . . ., u a ) ∈ A and every node (v 1 , . . ., v b ) ∈ B, the algorithm adds an edge between them if and only if u 1 , . . ., u a , v 1 , . . ., v b form an (a + b)-clique in the original graph.It similarly adds edges between B, C and between A, C. It is not difficult to see that there is a triangle in the new graph if and only if there is a k-clique in the original graph, so we can simply detect triangles by multiplying an |A| × |B| matrix with a |B| × |C| matrix.