Equivalences between triangle and range query problems
Lech Duraj, Krzysztof Kleiner, Adam Polak, Virginia Vassilevska Williams
aa r X i v : . [ c s . CC ] A p r Equivalences between triangle and range query problems
Lech Duraj ∗ , Krzysztof Kleiner , Adam Polak † , and Virginia Vassilevska Williams Institute of Theoretical Computer Science, Faculty of Mathematics and Computer Science,Jagiellonian University, { duraj,polak } @tcs.uj.edu.pl , [email protected] MIT CSAIL and EECS, [email protected]
Abstract
We define a natural class of range query problems, and prove that all problems within thisclass have the same time complexity (up to polylogarithmic factors). The equivalence is verygeneral, and even applies to online algorithms. This allows us to obtain new improved algorithmsfor all of the problems in the class.We then focus on the special case of the problems when the queries are offline and thenumber of queries is linear. We show that our range query problems are runtime-equivalent(up to polylogarithmic factors) to counting for each edge e in an m -edge graph the numberof triangles through e . This natural triangle problem can be solved using the best knowntriangle counting algorithm, running in O (cid:0) m ω/ ( ω +1) (cid:1) O (cid:0) m . (cid:1) time. Moreover, if ω = 2,the O (cid:0) m ω/ ( ω +1) (cid:1) running time is known to be tight (within m o (1) factors) under the 3SUMHypothesis. In this case, our equivalence settles the complexity of the range query problems.Our problems constitute the first equivalence class with this peculiar running time bound.To better understand the complexity of these problems, we also provide a deeper insight intothe family of triangle problems, in particular showing black-box reductions between trianglelisting and per-edge triangle detection and counting. As a byproduct of our reductions, weobtain a simple triangle listing algorithm matching the state-of-the-art for all regimes of thenumber of triangles. We also give some not necessarily tight, but still surprising reductionsfrom variants of matrix products, such as the (min , max)-product. ∗ Partially supported by the National Science Center, Poland under grant 2016/21/B/ST6/02165. † Partially supported by the National Science Center, Poland under grants 2017/27/N/ST6/01334 and2018/28/T/ST6/00305.
Introduction
Finding, counting and listing triangles in graphs are fundamental problems with a variety of appli-cations from classical theoretical computer science problems such as subgraph isomorphism to joinquery problems in databases.Since the 1970s [16] it has been known that triangle finding and counting can both be solvedin O ( n ω ) time in n -node graphs, where ω < .
373 [31, 20] is the exponent of square matrix multi-plication. Alon, Yuster and Zwick [4] improved upon this running time for sparse enough graphsby giving an O (cid:0) m ω/ ( ω +1) (cid:1) O (cid:0) m . (cid:1) time triangle finding and counting algorithm for m -edgegraphs. This is the best bound for these problems to date.A TriangleListing algorithm takes as an input a graph G and an integer t and is required to re-turn t triangles in G , or all the triangles in G if G has fewer than t triangles. The fastest known algo-rithms for TriangleListing in m -edge, n -node graphs run in either e O (cid:0) n ω + n ω − / (5 − ω ) t − ω ) / (5 − ω ) (cid:1) time or in e O (cid:0) m ω/ ( ω +1) + m ω − / ( ω +1) t (3 − ω ) / ( ω +1) } (cid:1) time , depending on the graph density [7]. If ω = 2, the runtime simplifies to e O (cid:0) min { n + nt / , m / + mt / } (cid:1) , and this running time has beenshown to be optimal under the hypothesis that 3SUM on n integers requires n − o (1) time [26, 18]. TriangleDetection and
TriangleListing are important problems in graph algorithmsand fine-grained complexity. Due to their simplicity, triangle problems can easily be reduced tomany other problems. Fine-grained complexity has formulated hypotheses about the complexity oftriangle detection and listing, and such hypotheses have been used to show lower bounds for manyproblems (e.g. [26, 2]).
TriangleDetection , TriangleCounting and
TriangleListing are also powerful prim-itives on their own. Many problems are known to be reducible to
TriangleDetection , e.g. k -Clique and more generally Subgraph Isomorphism for any fixed size pattern [24] and ShortestCycle [27]. TriangleDetection and Boolean Matrix Multiplication (
BMM ) [33] were shown to be equiv-alent under fine-grained subcubic reductions so that an O (cid:0) n − ε (cid:1) time algorithm for one of theproblems, for any ε >
0, would imply an O (cid:0) n − δ (cid:1) time algorithm for the other, for some δ > This relationship between the two prob-lems also implies that many other problems are equivalent (under fine-grained subcubic reductions)to
TriangleDetection . Some examples include Replacement Paths and Shortest Cycle in un-weighted graphs [33].All these equivalences only go through for dense graphs. When the running time is measured interms of the number of edges m , however, the complexities of the above problems differ a lot fromthe O (cid:0) m ω/ ( ω +1) (cid:1) time for TriangleDetection , e.g. Shortest Cycle seems to require mn − o (1) time [5, 22]. Prior to our work no equivalence class has been developed for triangle problems whenit comes to sparse inputs. In fact, there are very few such equivalences for sparse graph problemsat all: (1) There are a few equivalences for weighted graph problems whose best known runningtime is O ( mn ) [3, 1], and more interestingly, (2) a recent result [12] shows that counting 4-cyclesin m -edge graphs is equivalent to computing the quartet distance between two m -node trees, twoproblems with runtime O (cid:0) m . (cid:1) . We use e O ( · ) notation to hide polylogarithmic factors. TriangleDetection is the problem of detecting whether a given graph has a triangle.
TriangleFinding asksto return a triangle contained in a given graph, if one exists, and
TriangleCounting asks to return the number oftriangles in the given graph. It is not hard to see that
TriangleDetection and
TriangleFinding are equivalentin terms of running time. We will not attempt to define “combinatorial”. The notion is supposedly meant to circumvent the inefficientnature of the Strassen-like algorithms for matrix multiplication. equivalence class of natural prob-lems runtime-equivalent to the following very natural triangle counting variant, still solvable in O (cid:0) m ω/ ( ω +1) (cid:1) time by the Alon-Yuster-Zwick [4] algorithm. Definition 1 ( EdgeTriangleCounting ) . Given an undirected graph G = ( V, E ), with n nodesand m edges, compute for every edge e ∈ E the number of triangles in G which contain e .The problems we consider are certain range query problems known to be solvable, for a linearnumber of queries, in e O (cid:0) n . (cid:1) time. As a byproduct of their equivalence to EdgeTriangleCount-ing , we show that they are in fact all solvable in e O (cid:0) n ω/ ( ω +1) (cid:1) e O (cid:0) n . (cid:1) time.The equivalence class is the first about problems with the bizarre complexity e O (cid:0) n ω/ ( ω +1) (cid:1) . Itturns out that this class has interesting relationships to other problems in fine-grained complexitysuch as 3SUM, TriangleListing , and the (min , max)-product of matrices. Here we define four range query problems that are featured in our equivalence theorem. In Sec-tion 1.2 we will define a more general range query problem that will generalize all of the problemsbelow and will allow us to significantly extend our equivalence class. Let us define the first four.The first problem we consider is a problem about counting the number of inversions in a set ofgiven range queries:
Definition 2 ( RangeInversionsQuery ) . Given an array of integers A [1 ..n ] and a sequence ofranges [ l , r ] , [ l , r ] , . . . , [ l q , r q ], compute for each range [ l, r ] the quantity |{ ( i, j ) : l i < j r and A [ i ] > A [ j ] }| . This is a problem commonly used to illustrate an algorithmic technique, popular under thename of
Mo’s algorithm in the competitive programming community, as well as referred to asthe Rectilinear Steiner Minimal Arborescence technique [17]. See Appendix A for details on thetechnique.Mo’s technique is very general and achieves a runtime of e O (cid:0) n √ q (cid:1) for many types of range queryproblems, in particular for all the range query problems in our equivalence class. For many simpletypes of queries, however, faster, often (near-)linear time algorithms are known. Examples includesum (folklore), minimum [13, 6], or median [9]. Counting the number of inversions seems to beone of the simplest examples for which no significant improvement over Mo’s algorithm was knownprior to our work.The second problem is a variant of the first one, where we ask about two nonoverlapping rangesinstead of one. An inversion is now a pair of elements from different ranges such that the left rangeelement is larger than the right range element. Definition 3 ( ) . Given an array of integers A [1 ..n ] and a sequence ofpairs of nonoverlapping ranges ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) , ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) , . . . , ([ l ′ q , r ′ q ] , [ l ′′ q , r ′′ q ]), with r ′ i < l ′′ i ,compute for each pair ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) the quantity |{ ( i, j ) : l ′ i r ′ and l ′′ j r ′′ and A [ i ] > A [ j ] }| . In the third and fourth problem instead of inversions we count pairs of equal elements.
Definition 4 ( RangeEqPairsQuery ) . Given an array of integers A [1 ..n ] and a sequence of ranges[ l , r ] , [ l , r ] , . . . , [ l q , r q ], compute for each range [ l, r ] the quantity |{ ( i, j ) : l i < j r and A [ i ] = A [ j ] }| . efinition 5 ( ) . Given an array of integers A [1 ..n ] and a sequence ofpairs of nonoverlapping ranges ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) , ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) , . . . , ([ l ′ q , r ′ q ] , [ l ′′ q , r ′′ q ]), with r ′ i < l ′′ i ,compute for each pair ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) the quantity |{ ( i, j ) : l ′ i r ′ and l ′′ j r ′′ and A [ i ] = A [ j ] }| . Now that all those problems have been stated, we present our equivalence theorem.
Theorem 6.
The problems
EdgeTriangleCounting (with input size m ), RangeEqPairs-Query , , RangeInversionsQuery , (withinput sizes n , restricted to offline queries and to instances with q = Θ( n ) ) all have the same timecomplexity in the size of their inputs, up to polylogarithmic factors. Due to the equivalence, all these problems are solvable in e O (cid:0) m ω/ ( ω +1) (cid:1) time, the time for EdgeTriangleCounting . This presents the first improvement over Mo’s algorithm for the rangequery problems. Moreover, if any of these problems has a faster algorithm, then all of themhave an algorithm with the same complexity. It has been open for a long time whether one canimprove upon the O (cid:0) m ω/ ( ω +1) (cid:1) TriangleDetection runtime. Any polynomial improvementover O (cid:0) n ω/ ( ω +1) (cid:1) for the range query problems in our equivalence class would resolve this bigopen problem.The q = Θ( n ) regime is a straightforward choice if we want to study the complexity as a functionof a single parameter. The most natural parameter, the input size, equals to Θ( n + q ), and it iseasy to see that the worst-case asymptotic complexity must be maximized for q = Θ( n ). Later wealso analyse the complexity as a function of two parameters.In Sections 2 and 3 we prove two lemmas which together establish Theorem 6. Lemma 7. If for q = n can be solved offline in T = ( n ) time, then Edge-TriangleCounting can be solved in e O ( T = ( m )) time. Conversely, if EdgeTriangleCounting can be solved in T ∆ ( m ) time, then for q = n can be solved offline in e O ( T ∆ ( n )) time. Lemma 8.
The problems
RangeEqPairsQuery , , RangeInversion-sQuery , all have the same time complexity, up to polylogarithmicfactors. This holds even when the queries are presented online and with the complexity measuredas a function of two variables, n and q . Since Lemma 8 holds for online algorithms as well, it is quite powerful. In fact, we use it todevelop improved algorithms for all of these range query problems, which work also in the onlinesetting. In Section 5 we present an online algorithm for
RangeEqPairsQuery , which by Lemma 8also implies the same online running time for the rest of the problems.
Theorem 9.
RangeEqPairsQuery can be solved online in time T ( n, q ) = e O (cid:16) nq ω − ω +1 (cid:17) if q n e O (cid:16) n ω − ω +1 q ω +1 (cid:17) if q > n. q significantly different than n our algorithm improves over the bound of e O (cid:0) ( n + q ) ω/ ( ω +1) (cid:1) following trivially from Theorem 6.In Section 5 we compare this running time against a multivariate 3SUM lower bound, andconclude that, assuming ω = 2, the bounds are tight for q > n , but a gap remains for q < n .The range query problems from our equivalence class are instances of two more general problemsthat we will now define. For a binary integer function f : Z → Z , and an array A clear from context,let us abuse the notation and write f ([ l, r ]) def= X l i Definition 10 ( Range- f -PairsQuery ) . Given an array of integers A [1 ..n ] and a sequence ofranges [ l , r ] , [ l , r ] , . . . , [ l q , r q ], compute f ([ l i , r i ]) for each i ∈ [ q ]. Definition 11 ( f -PairsQuery ) . Given an array of integers A [1 ..n ] and a sequenceof pairs of nonoverlapping ranges ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) , ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) , . . . , ([ l ′ q , r ′ q ] , [ l ′′ q , r ′′ q ]), compute f ([ l ′ i , r ′ i ] , [ l ′′ i , r ′′ i ]) for each i ∈ [ q ].Note that our initial four range query problems are instantiations of the above schemes forfunctions inv ( x, y ) def= ( x > y, , and eqp ( x, y ) def= ( x = y, . A natural question is: What other functions yield range query problems with the same time complex-ity? Labib, Uzna´nski and Wolleb-Graf [19] investigate functions equivalent to Hamming distancein the context of convolutions and matrix products. They come up with a helpful definition. Definition 12 (Labib, Uzna´nski, Wolleb-Graf [19]) . For integers A, B, C and polynomial P ( x, y )we say that the function P ( x, y ) · [ Ax + By + C > 0] is halfplane polynomial . We call a sum ofhalfplane polynomial functions P i P i ( x, y ) · [ A i x + B i y + C i > piecewise polynomial .We say that a function is axis-orthogonal piecewise polynomial , if it is piecewise polynomial andfor every i , A i = 0 or B i = 0.Note that both inv and eqp are non-axis-orthogonal piecewise polynomial, and also many othernatural functions fall within the definition. Examples include max( x, y ), the L distance | x − y | ,more generally any odd L p +1 distance, the threshold function [ | x − y | < δ ], or the rectifier functionmax(0 , x − y ).In Section 2 we integrate their techniques and vastly expand the equivalence class introducedin Theorem 6. Theorem 13. Let f : Z → Z be any non-axis-orthogonal piecewise polynomial function of con-stant degree and polylog( n ) number of summands. For input values bounded in absolute value by poly( n ) , the problems Range- f -PairsQuery and f -PairsQuery have the same timecomplexity, up to polylogarithmic factors, as . Hence, for q = n , offline Range- f -PairsQuery and offline f -PairsQuery have the same time complexity, up topolylogarithmic factors, as EdgeTriangleCounting . RangeInversionsQueryRangeInversionsQuery 2RangeEqPairsQueryRangeEqPairsQuery 2Range- f -PairsQueryRange- f -PairsQueryEdgeTriangleCountingEdgeTriangleDetectionTriangleListing ( t = m ) TriangleListing ( t > m ) (min , max)- Product3SUM Alon-Yuster-Zwickalgorithm [4] Lem 8 Lem 8 Thm 13Lem 8 Thm 13Lem 7( q = n ) (trivial)Thm 16Thm 15Thm 17 (implicit)Lem 19(implicit in [18],tight if ω = 2) Thm 21[26], [18](tight if ω = 2) Figure 1: Problems, reductions and equivalence classes considered in this paper. Dashed arrowsrepresent reductions which are not tight with respect to current fastest algorithms.Thus Range- f -PairsQuery and f -PairsQuery (for arbitrary f ) are equivalent to f -PairsQuery for the specific f which is equality, even when the queries are presentedonline and with the complexity measured as a function of two variables, n and q . This significantlyextends our equivalence class.Fine-grained complexity gives conditional lower bounds for all the problems in our expandedequivalence class. Techniques initially developed by Pˇatra¸scu [26] for TriangleListing , andfurther advanced by Kopelowitz, Pettie and Porat [18], can also prove that an O (cid:0) m / − ε (cid:1) timealgorithm for ε > EdgeTriangleCounting would break the 3SUM Hypothesis. Thus, weimmediately obtain that under the 3SUM Hypothesis, all problems in our equivalence class require n / − o (1) time. Thus if ω = 2, then we have a class whose time complexity is squarely n / ± o (1) (under the 3SUM Hypothesis). Moreover, improving over either the current upper bound or thecurrent lower bound for our class by a polynomial factor would result in a significant breakthrough:Namely, an O (cid:0) n ω/ ( ω +1) − ε (cid:1) time algorithm for ε > ω > 2. On the other hand, if one can givean n / ε − o (1) lower bound, then it must be that ω > TriangleListing and the(min , max) matrix product. See Figure 1 for an overview of the complexity landscape mapped byour results. Relationship to triangle listing. TriangleListing is arguably the most widely studied output-intensive triangle problem in sparse graphs [28, 26, 7]. Quite surprisingly, in Section 4 we showthat it is equivalent, in the t = m regime, to the following problem, which trivially reduces to Ed-geTriangleCounting . The reductions in that section are the first such tight reductions betweentriangle listing and detection problems. For a reader unassured by this hand-waving argument, let us note that the same lower bounds follow from ourreductions from TriangleListing and TriangleDetection , which we shall discuss later in the paper. efinition 14 ( EdgeTriangleDetection ) . Given an undirected graph G = ( V, E ), with n nodes and m edges, determine for every edge e ∈ E if there exists a triangle in G which contains e . Theorem 15. If EdgeTriangleDetection can be solved in T ( m ) time, then TriangleListing for t = m can be solved in e O ( T ( m )) time. Theorem 16. If TriangleListing for t = m can be solved in T ( m ) time, then EdgeTrian-gleDetection can be solved in (randomized, Las Vegas) e O ( T ( m )) time. While the above reductions work in the t = m regime, the next theorem lets an EdgeTrian-gleDetection algorithm be used to efficiently list an even larger number of triangles. Theorem 17. Assume that there is an algorithm which can list up to m triangles in a graph with m edges in e O ( m c ) time, for a constant c . Then t > m triangles can be listed in (randomized, MonteCarlo) e O (cid:0) m c − t − c (cid:1) time. Plugging in the O (cid:0) m ω/ ( ω +1) (cid:1) time for detection [4] we match the current fastest listing algo-rithm [7], running in e O (cid:0) m ω − / ( ω +1) t (3 − ω ) / ( ω +1) (cid:1) time. Let us note that a fair share of intricaciesin the proofs of Theorems 15 and 17 comes from the fact that they have to provide general black-box reductions. If one actually wishes to obtain a listing algorithm by chaining these reductionswith the Alon-Yuster-Zwick algorithm [4], one can use the algorithm’s counting ability to simplifythings substantially. In particular, no randomization is needed in that case.Last, let us define a decision variant of : Definition 18 ( ) . Given an array of integers A [1 ..n ] and a sequence ofpairs of nonoverlapping ranges ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) , ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) , . . . , ([ l ′ q , r ′ q ] , [ l ′′ q , r ′′ q ]), determine foreach pair ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) whether the sets of elements in these two ranges are disjoint, i.e. whether ¬∃ i,j : l ′ i r ′ < l ′′ j r ′′ and A [ i ] = A [ j ] . In the same way Lemma 7 establishes the equivalence of and Ed-geTriangleCounting , we can prove and EdgeTriangleDetection are equivalent: Lemma 19. If for q = n can be solved offline in T ⊥ ( n ) time, then EdgeTriangleDetection can be solved in e O ( T ⊥ ( m )) time. Conversely, if EdgeTriangleDe-tection can be solved in T ∆ ( m ) time, then for q = n can be solvedoffline in e O ( T ∆ ( n )) time. Recall that in Section 1.1 we defined four counting range query problems. Out of them, is the only one which remains hard in the decision variant. The otherthree become solvable in linear time, using range minimum query data structures [13, 6]. Connections to matrix products. is very convenient in drawingconnections of our class with matrix product problems. Let us start with a simple observation. Observation 20. Multiplication of two √ n × √ n (0 , -matrices can be reduced to with n queries in an array of length O ( n ) . 6o see why this is true, represent each row of the first matrix and each column of the secondmatrix as an array of the indices in which the row/column has a 1. Then, concatenate theserepresentations to form a single large array. Now, the value of the ( i, j ) cell of the output matrixcan be determined by asking a query about the number of pairs of equal indices in the subarrayscorresponding to the row i and column j .The so-called BMM Hypothesis states that no “combinatorial” algorithm can multiply two n × n matrices, even over the Boolean semiring, in time O (cid:0) n − ε (cid:1) , for any ε > 0. Under this hypothesis,Mo’s algorithm is optimal (up to subpolynomial factors) among “combinatorial” algorithms forrange query problems in our class. While the notion of a “combinatorial” algorithm is not welldefined, that observation shows that using a fast matrix multiplication algorithm – what Alon-Yuster-Zwick algorithm [4] for EdgeTriangleCounting does – is necessary in order to beat the n / barrier.We will now relate our equivalence class to a slightly harder matrix product problem, whosecomplexity seems to be independent of the 3SUM Hypothesis. The (min , max)-product of matrices A and B is the matrix C such that C [ i ][ j ] = min k max( A [ i ][ k ] , B [ k ][ j ]). The problem of computingthe (min , max)-product stems from research on the All-Pairs Bottleneck Paths problem [29, 30, 11],and recently has been shown to be equivalent to approximating All-Pairs Shortest Paths [8]. InSection 6 we show the following (non-tight) reduction. Theorem 21. If for q = n can be solved offline in T ( n ) time, then the (min , max) -product of two n × n matrices can be computed in e O (cid:0) T ( n ) (cid:1) time. The current fastest algorithm for (min , max)-product runs in e O (cid:0) n . (cid:1) time [11]. This algo-rithm is quite intricate and seems difficult to improve upon. Assuming this algorithm is optimal,Theorem 21, combined with Lemma 19 and Theorem 16, yields an Ω (cid:0) m . (cid:1) conditional lowerbound for EdgeTriangleDetection and TriangleListing . This is a slightly higher barrierthan the m / one following from the 3SUM Hypothesis, but the hardness assumption is much lessunderstood and presumably less likely to be true.Moreover, there is a group of equivalent matrix products [15], including dominance product [23],equality product [32] (also later called Hamming distance product) and sparse matrix product,which can be reduced to (and thus EdgeTriangleCounting ) with aneven simpler argument, generalizing Observation 20. However these products can be computed in e O (cid:0) n . (cid:1) time [14], slightly faster than the (min , max)-product running time, so they provide alower bound weaker than the one based on 3SUM, both in terms of the exponent value and perhapscredibility. Preliminaries. We assume all graphs have no isolated vertices so that the number of vertices isnever asymptotically larger than the number of edges. Throughout the paper we will omit floorsand ceilings for simplicity. In this section we present reductions between the range query problems in our equivalence class.We start with the four problems defined in Section 1.1. Although their equivalence follows from amore general Theorem 13, we focus on them first, so that we can highlight the main ideas behindour reductions, unobscured by technical details required for the general result. Lemma 8. The problems RangeEqPairsQuery , , RangeInversion-sQuery , all have the same time complexity, up to polylogarithmic actors. This holds even when the queries are presented online and with the complexity measuredas a function of two variables, n and q .Proof. ( → RangeInversionsQuery ):Observe that for every a b c d we have inv ([ a, b ] , [ c, d ]) = inv ([ a, d ]) − inv ([ a, c ]) − inv ([ b, d ])+ inv ([ b, c ]). Thus, the answer for each pair of intervals in can be ob-tained from four queries in a RangeInversionsQuery instance.( RangeInversionsQuery → ):First, note that the values inv ([1 , x ]), for all 1 x n , can be precomputed in O ( n log n ) time.To do that, note that inv ([1 , x ]) − inv ([1 , x − { i < x : A [ i ] > A [ x ] } . If we storeall elements of A [1 ..x − 1] in a balanced binary search tree, the value of inv ([1 , x ]) − inv ([1 , x − A [ x ] to the tree. It remains to see that inv ([1 , a − , [ a, b ]) = inv ([1 , b ]) − inv ([1 , a − − inv ([ a, b ]), so we can find inv ([ a, b ]) with a single inv ([1 , a − , [ a, b ]), as the other terms are precomputed.( RangeEqPairsQuery ↔ ):The proofs are obtained from the above ones by simply replacing inv with eqp .( → ):To solve we simply use the fact that A [ i ] = A [ j ] if and only if neither A [ i ] > A [ j ] nor A [ i ] < A [ j ]. Formally, we employ a second array A ′ [1 ..n ] with A ′ [ x ] = − A [ x ]and on both arrays we use the algorithm for . Therefore, for every a b c d we can compute inv A ([ a, b ] , [ c, d ]) = { ( i, j ) ∈ [ a, b ] × [ c, d ] : A [ i ] > A [ j ] } as well as inv A ′ ([ a, b ] , [ c, d ]) = { ( i, j ) ∈ [ a, b ] × [ c, d ] : A ′ [ i ] > A ′ [ j ] } = { ( i, j ) ∈ [ a, b ] × [ c, d ] : A [ i ] < A [ j ] } . Itis clear that eqp ([ a, b ] , [ c, d ]) = ( b − a + 1) · ( d − c + 1) − inv A ([ a, b ] , [ c, d ]) − inv A ′ ([ a, b ] , [ c, d ]).( → ):We assume w.l.o.g. that the elements in A are integers in [1 , n ]. Indeed, if they were not, we couldreplace each element with its position in the sorted order of all elements of A .Let k = ⌈ log n ⌉ be the number of bits needed to represent the integers in A . For a k -bit integer x and 1 j k let v j ( x ) denote the j -th bit of x , starting from the most significant. Also, let p j ( x ) denote the number obtained from x by taking only the j most significant bits (in other words, p j ( x ) = ⌊ x/ k − j ⌋ ). We assume p ( x ) = 0.We create k new arrays A , . . . , A k , all of length 2 n . For i = 1 , , . . . , n and 1 t k we define: A t [ i ] = ( p t − ( A [ i ]) if v t ( A [ i ]) = 1 −∞ otherwise A t [ n + i ] = ( p t − ( A [ i ]) if v t ( A [ i ]) = 0 ∞ otherwiseWe claim that inv A ([ a, b ] , [ c, d ]) = P kt =1 eqp A t ([ a, b ] , [ n + c, n + d ]). This equality allows usto simulate with log n instances of and thusrender the proof done. To prove it, first let i ∈ [ a, b ] and j ∈ [ c, d ] be such that A [ i ] > A [ j ]. Thenthere is exactly one 1 t k such that p t − ( A [ i ]) = p t − ( A [ j ]), v t ( A [ i ]) = 1 and v t ( A [ j ]) = 0,which implies A t [ i ] = A t [ n + j ]. Every pair that is counted in inv A ([ a, b ] , [ c, d ]) then correspondsto a pair in P kt =1 eqp A t ([ a, b ] , [ n + c, n + d ]), so inv A ([ a, b ] , [ c, d ]) P kt =1 eqp A t ([ a, b ] , [ n + c, n + d ]).Conversely, if A t [ i ] = A t [ n + j ] for some a i b and c j d , then this equal element canbe neither −∞ nor ∞ , as these infinities appear only in first and second half of A t , respectively,and the halves are disjoint. So p t − ( A [ i ]) = p t − ( A [ j ]), v t ( A [ i ]) = 1 and v t ( A [ j ]) = 0, which meansthat A [ i ] > A [ j ] is an inversion and t is the most significant bit on which A [ i ] and A [ j ] differ. Inparticular, we cannot obtain the same pair ( i, j ) from different t ’s. This proves inv A ([ a, b ] , [ c, d ]) > P kt =1 eqp A t ([ a, b ] , [ n + c, n + d ]), so we are done. 8ow we are ready to prove a more general result. Theorem 13. Let f : Z → Z be any non-axis-orthogonal piecewise polynomial function of con-stant degree and polylog( n ) number of summands. For input values bounded in absolute value by poly( n ) , the problems Range- f -PairsQuery and f -PairsQuery have the same timecomplexity, up to polylogarithmic factors, as . Hence, for q = n , offline Range- f -PairsQuery and offline f -PairsQuery have the same time complexity, up topolylogarithmic factors, as EdgeTriangleCounting . The proof is similar in spirit to the proof of Lemma 8, but the ad hoc reductions between theequality and inversion predicates are replaced with a general tool developed by Labib, Uzna´nskiand Wolleb-Graf [19]. Theorem 22 (Theorem 10 in [19], rephrased) . Let f : Z → Z be any piecewise polynomial functionof degree d with c summands. There exist integer k = O (cid:0) c · d · log d +1 U (cid:1) , constant-time computablefunctions g , . . . , g k , h , . . . , h k , and coefficients α , . . . , α k , such that for every x, y Uf ( x, y ) = k X i =1 α i · eqp ( g i ( x ) , h i ( y )) . Theorem 23 (Theorem 11 in [19], rephrased) . Let f : Z → Z be any non-axis-orthogonal piecewisepolynomial function of degree d . There exist integer k = O (cid:0) d (cid:1) , constant-time computable functions g , . . . , g k , h , . . . , h k , and coefficients α , . . . , α k , such that for every x, y ∈ Z eqp ( x, y ) = k X i =1 α i · f i ( g i ( x ) , h i ( y )) , where each f i either equals to f or is a simple multiplication, i.e. f i ( x, y ) = x · y . Theorem 13 follows from the next two lemmas, which establish the equivalence between all therange query problems in our equivalence class, and Lemma 7, which we prove in Section 3, andwhich relates the range query problems to EdgeTriangleCounting . Lemma 24. Let f : Z → Z be any non-axis-orthogonal piecewise polynomial function of con-stant degree and polylog( n ) number of summands. For input values bounded in absolute value by poly( n ) , the problems f -PairsQuery and have the same timecomplexity, up to polylogarithmic factors.Proof. ( f -PairsQuery → ):We apply Theorem 22 to f , and create polylogarithmically many instances of , the i -th one with a 2 n -element array A i such that A i [ j ] = g i ( A [ j ]) and A i [ n + j ] = h i ( A [ j ])for every j ∈ [ n ]. To finish the proof, observe that f A ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) = k X i =1 α i · eqp A i ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) . ( → f -PairsQuery ):The argument is very similar to the reduction in the reverse direction. We use Theorem 23 andcreate a constant number of arrays. We then solve f -PairsQuery on those arrays with9 i = f , and mul -PairsQuery on those with f i = mul , where mul ( x, y ) = x · y . Whatremains to be shown is that mul -PairsQuery is computationally easy. Observe that mul ([ l ′ , r ′ ] , [ l ′′ , r ′′ ]) = X l ′ i r ′ l ′′ j r ′′ A [ i ] A [ j ] = X l ′ i r ′ A [ i ] · X l ′′ j r ′′ A [ j ] = ( S [ r ′ + 1] − S [ l ′ ]) · ( S [ r ′′ + 1] − S [ l ′′ ]) , where S [ i ] = P j
Let f : Z → Z be any non-axis-orthogonal piecewise polynomial function of constantdegree and polylog( n ) number of summands. For input values bounded in absolute value by poly( n ) ,the problems Range- f -PairsQuery and f -PairsQuery have the same time complexity,up to polylogarithmic factors.Proof. ( f -PairsQuery → Range- f -PairsQuery ):The reduction is essentially the same as the → RangeInversions-Query reduction in the proof of Lemma 8. Actually, the inclusion-exclusion identity f ([ a, b ] , [ c, d ]) = f ([ a, d ]) − f ([ a, c ]) − f ([ b, d ]) + f ([ b, c ]) holds for any binary function f , not necessarily piecewisepolynomial.( Range- f -PairsQuery → f -PairsQuery ):The reduction closely follows the RangeInversionsQuery → reduc-tion in the proof of Lemma 8. The inclusion-exclusion part of the argument translates verbatim,i.e. we have f ([1 , a − , [ a, b ]) = f ([1 , b ]) − f ([1 , a − − f ([ a, b ]). What requires more work is to pre-compute the values f ([1 , x ]), for all 1 x n , in e O ( n ) time. In order to do so, we apply Theorem 22to f . We do a single pass over the array A and, for each i ∈ [ k ], we keep a multiset of already en-countered values g i ( A [ x ]). During the pass, each value f ([1 , x ]) − f ([1 , x − P x ′ EdgeTriangleCounting and an offline rangequery problem from our equivalence class. Analogous reductions establish equivalence between EdgeTriangleDetection and , which we briefly discuss at the end ofthis section. Lemma 7. If for q = n can be solved offline in T = ( n ) time, then Edge-TriangleCounting can be solved in e O ( T = ( m )) time. Conversely, if EdgeTriangleCounting can be solved in T ∆ ( m ) time, then for q = n can be solved offline in e O ( T ∆ ( n )) time.Proof. ( EdgeTriangleCounting → ):Given a graph, we construct an array by concatenating the lists of neighbours of all vertices. Foreach edge e = ( u, v ), the number of triangles containing it, denoted by ∆ e , equals eqp (Nb( u ) , Nb( v )),where Nb( a ) denotes the interval containing the neighbour list of vertex a . Thus we reduce Edge-TriangleCounting to m queries in an array of length 2 m , and can solve it in T = (2 m ) time.( → EdgeTriangleCounting ):We first present a reduction producing a multigraph instance, and then explain how to eliminateparallel edges. 10e assume n is a power of 2, by appending dummy elements if necessary. Given an arrayof length n , we define the family of base intervals as follows: for each i = 0 , , . . . , log n , j =0 , , . . . , ( n/ i ) − 1, let base ( i, j ) denote the interval [ j · i , ( j + 1) · i − segment tree . There are 2 n − O ( n log n ).Any interval I can be split into a collection base I of O (log n ) base intervals by the followingrecursive procedure. We start with base (log n, 0) = [0 , n − base ( i, j ) is fully contained in interval I , we add it to the collection. Otherwise, we check if I has a non-empty intersection with base ( i − , j ) and base ( i − , j + 1), and descend recursivelyinto one or both of them accordingly. A conclusion that only O (log n ) base intervals are addedto the collection (as well as that the procedure finishes in O (log n ) time) follows easily from theobservation that, for any i , there can be at most two base intervals base ( i, j ) which have a non-emptyintersection with I but are not fully contained in I .We create a tripartite multigraph G = (cid:0) ( U ∪ V ∪ W ) , ( E UV ∪ E UW ∪ E V W ) (cid:1) :1. We add a vertex u k to U for each value k appearing in the array A . If a value appears multipletimes, we do not create multiple copies of the vertex.2. We add vertices v i,j to V and w i,j to W for each base interval base ( i, j ).3. We add edges ( u k , v i,j ) to E UV and ( u k , w i,j ) to E UW for each value k which appears inthe interval base ( i, j ) in the array A . If k appears multiple times, we add multiple edges,accordingly.4. For each queried pair of intervals ( I , I ) we compute the collections base I and base I andadd an edge ( v i ,j , w i ,j ) to E V W for each base ( i , j ) ∈ base I and each base ( i , j ) ∈ base I .Since G is tripartite, all of its triangles are of the form ( u k , v i ,j , w i ,j ). Hence, for any edge e = ( v i ,j , w i ,j ) ∈ E V W , we have ∆ e = eqp ( base ( i , j ) , base ( i , j )). In order to compute theresults of the original queries, we sum ∆ e ’s for all those edges which have been induced by a givenquery in Step 4. This completes the reduction to a multigraph instance.Let us analyse the size of G . In Step 3, an edge is added between each base interval and eachoccurrence of a value in this interval, so the total number of edges is equal to the sum of lengths ofall base intervals, which is O ( n log n ). In Step 4, for each query, both intervals are split into O (log n )base intervals, and an edge is added for every pair of those base intervals. That gives O (cid:0) log n (cid:1) edges per query, O (cid:0) q log n (cid:1) edges in total. Therefore, the total size of G is O (cid:0) n log n + q log n (cid:1) .Note that multiple copies of an edge in E V W can be simply ignored. They occur when severalqueries happen to ask about the same pair of base intervals in their decompositions, but then asingle copy of such an edge is sufficient to answer all those queries.Now let us eliminate the remaining parallel edges. We represent all edge multiplicities in binary.For every i ∈ [log n ], we create sets E iUV and E iUW containing those edges from E UV and E UW whose multiplicities have 1 in the i -th position in their binary representation. For every pair( i, j ) ∈ [log n ] , we create a (simple) graph G i,j = (cid:0) ( U ∪ V ∪ W ) , ( E iUV , E jUW , E V W ) (cid:1) , and feed itto the triangle counting algorithm to compute ∆ i,je for each e ∈ E V W . Finally, we obtain each ∆ e as P i,j i + j ∆ i,je . This reduces the multigraph instance G to log n (simple) graph instances, eachno larger than G .The whole reduction runs in time linear in the size of instances it produces. Thus, the totaltime to solve is dominated by the calls to the triangle counting algorithm,and equals to log n · T ∆ (cid:0) O (cid:0) n log n + q log n (cid:1)(cid:1) , which is e O ( T ∆ ( n )) for q = n .11 emma 19. If for q = n can be solved offline in T ⊥ ( n ) time, then EdgeTriangleDetection can be solved in e O ( T ⊥ ( m )) time. Conversely, if EdgeTriangleDe-tection can be solved in T ∆ ( m ) time, then for q = n can be solvedoffline in e O ( T ∆ ( n )) time.Proof sketch. Constructions from the above proof of Lemma 7 work verbatim. A slight simplifica-tion is possible: Multiple parallel edges can be simply ignored, since they change only the numberof triangles, not their existence. This saves a factor of log n . In this section we prove the equivalence between TriangleListing and EdgeTriangleDetec-tion . Since the latter problem reduces to EdgeTriangleCounting trivially, this also establishesthe relationship of our equivalence class to TriangleListing .We start with the version of TriangleListing restricted to the t = m regime. Theorem 15. If EdgeTriangleDetection can be solved in T ( m ) time, then TriangleListing for t = m can be solved in e O ( T ( m )) time.Proof. Given a graph e G = ( e V , e E ), with m = | e E | edges, we create a tripartite graph G = ( V ∪ V ∪ V , E ) as follows: for every vertex v ∈ e V we create three vertices v ∈ V , v ∈ V , v ∈ V and for every edge ( u, v ) ∈ e E we create six edges ( u i , v j ) ∈ E for i, j ∈ { , , } , i = j . Let E = E , ∪ E ∗ , where E , is the set of edges connecting V with V and E ∗ , is the set of edgesconnecting V ∪ V with V . We partition G into its connected components, and denote the i -thcomponent by G i = ( V i , E i ), V i = V i ∪ V i ∪ V i , E i = E i , ∪ E i ∗ , . We will list t = 6 m triangles in G . Since every triangle in e G has exactly 6 copies in G , this allows us to retrieve at least m uniquetriangles in e G . Procedure. We iterate the whole following procedure in a loop, until the stopping conditionspecified in the last paragraph holds.First, for each connected component G i , we check whether | V i | = 1. If so, we keep it unchanged.Otherwise, we are going to replace it with two new components G i and G i . To do that, wearbitrarily split V i into two sets V i and V i of roughly equal size. We construct a new component G i as follows: We create copies of V i , V i and E i , and add them to G i . We add V i to G i . Wetake all those edges from E i ∗ , which are incident to V i , and add them to G i . We construct G i analogously. We remove G i from G and add G i and G i in its stead.Note that due to these transformations the cardinality of E , might have increased by no morethan a factor of 2, while the cardinality of E ∗ , hasn’t changed. After all the components areexamined, and possibly split, we solve EdgeTriangleDetection on G . Then, we remove all theedges from E , which turn out not to form any triangles. If after this step it holds that | E , | > t ,we additionally remove arbitrary edges from E , until | E , | = t . We also remove any verticeswhich become isolated in the process.If there still exists a component with | V i | > 1, we repeat the procedure. Otherwise, | V i | = 1 foreach component i , and therefore for each edge in E , there is exactly one vertex candidate whichcan form a triangle with it. Conversely, each edge still left in E , is guaranteed to form at leastone triangle. We therefore list all the triangles by performing a single pass over the edges from E , , and terminate. 12 nalysis. Observe that the only step of the algorithm in which some triangles can be lost is whenwe remove arbitrary edges due to the condition | E , | > t . If we reach this step, however, we areguaranteed that each of the remaining t edges from E , participates in at least one triangle. Weconclude that if the original graph has at least t triangles, each step of the algorithm preserves atleast t of them, while otherwise all the triangles are preserved.The number of iterations of the procedure is O (log | V | ) as the cardinality of the largest V i decreases roughly by half with each iteration. This is O (log m ) by the assertion of there being noisolated vertices. The cardinality of E ∗ , is initially 4 m and remains unchanged across the iterations,as each edge from E i ∗ , is added to exactly one of the newly created components when a componentgets split. Moreover, initially | E , | = 2 m and then at the end of every iteration we explicitlyensure that | E , | t = 6 m . Hence, the total number of edges at the beginning of every iterationis O ( m ), while within the iteration it can increase by no more than a factor of 2. The cost of eachcall to EdgeTriangleDetection is thus O ( T ( m )), while the rest of the procedure takes O ( m )time per iteration. This yields the overall running time of O ( T ( m ) log m ). Theorem 16. If TriangleListing for t = m can be solved in T ( m ) time, then EdgeTrian-gleDetection can be solved in (randomized, Las Vegas) e O ( T ( m )) time.Proof. First, observe that it is enough to solve a special case of EdgeTriangleDetection : as-suming that G is a tripartite graph G = ( V ∪ V ∪ V , E ) and only detecting edges between V and V that are part of some triangle. Indeed, any other graph e G = ( e V , e E ) can be treated as inTheorem 15: we create a tripartite graph G = ( V ∪ V ∪ V , E ) where V j = { v j for each v ∈ V } and E = { ( u i , v j ) : ( u, v ) ∈ e E, i, j ∈ { , , } , i = j } . Then we call the special case algorithmfor EdgeTriangleDetection for G to detect edges between ( V , V ). As every edge ( u, v ) ∈ e G corresponds to an edge ( u , v ) ∈ V × V and every triangle ( u, v, w ) corresponds to a triangle( u , v , w ) ∈ G , we will detect all the right edges.The algorithm itself is rather simple: for every s = log m, log m − , . . . , phase of the algorithm, which itself consists of calling TriangleListing m times. Each call ismade on an induced subgraph G ∗ = ( V ∪ V ∪ V ∗ , E ∗ ) where the subset V ∗ ⊆ V is created bypicking every vertex from V independently at random with probability p = 2 − s . We assume that TriangleListing can list up to 100 m triangles, even if G ∗ has less edges – we can easily achievethat by adding dummy vertices and edges. Every edge ( v , v ) ∈ V × V which is detected as beingpart of a triangle is subsequently removed from G . The key idea is that the phase for a given valueof s detects w.h.p. all the edges with at least 2 s triangles, and because we promptly remove them,they cannot interfere with next phases, thus keeping the number of triangles low.Let us formalize this idea. Recall that ∆ e denotes the number of triangles containing edge e .Let us define A s = { e ∈ E ∩ ( V × V ) : 2 s ∆ e < s +1 } for any integer 0 s log m . To completethe proof, we will show the following statement: If all edges in A s ′ sets for s ′ > s are detected and removed from G before the s phase, then, withprobability − m , all (previously undetected) edges in A s are detected in that phase. Suppose that there are indeed no more edges from A s ′ for s ′ > s . For any remaining edge e ∈ S r s A r the expected number of triangles in G ∗ containing e is no larger than 2 − s ∆ e − s · s +1 = 2.The expected number of all triangles in G ∗ is then no larger than 2 m , so the chance of not listingall triangles (recall that we can find up to 100 m of them) is at most 1 / 50, by the Markov inequality.Let us now pick any edge γ ∈ A s and prove that it is likely to be detected. There are at least 2 s triangles with γ . For any such triangle the chance of it not appearing in G ∗ is 1 − − s , and all arechosen independently, so the chance of all of them being left out is at most (1 − − s ) s < /e . Fromthese facts we deduce that in every iteration of TriangleListing , γ is detected with probability13t least 1 − /e − / > / 2. With 2 log m iterations we have no more than m chance of missinga single edge and thus, by union bound, no more than m chance of missing any edge from A s , as | A s | m .This completes the proof, as the total chance that at least one phase fails is not larger thanlog m · m / 2. The running time of this algorithm is O (cid:0) T ( m ) log m (cid:1) . Note that we can easilydetect a failure, using one extra call to TriangleListing with t = 1 at the very end of thealgorithm to check whether any edge remained undetected. This makes our algorithm Las Vegasinstead of Monte Carlo. t > m to t = m In this section we assume that there is an algorithm, denoted by BasicListingAlgorithm, which listsup to m triangles in any graph G with m edges in time T ( m ) = e O ( m c ). Our goal is to use it tolist up to t > m triangles in e O (cid:0) m c − t − c (cid:1) time.Let ζ > 100 be a big enough constant, to be determined later. If t ζ · m , we can useBasicListingAlgorithm: we simply add t − m ζ · m dummy edges to G , which allows us to list all t triangles with only a constant factor overhead in the running time. Therefore, from now on weassume that t > ζ · m .Let t ∗ denote the number of triangles in G . Note that we do not know t ∗ beforehand. First weare going to deal with the case t ∗ t . We present an algorithm (called InnerListingAlgorithm),which lists all triangles in a graph, provided there are at most t of them. If there are more trianglesin the input graph, the algorithm outputs some subset of them, with no guarantees as to the subset’ssize. In either case, the running time depends only on the input value t , and not on the actualnumber of triangles t ∗ . The main idea is to invoke BasicListingAlgorithm on random subgraphswhich, roughly speaking, contain no more triangles than they have edges. This is achieved byrandomly coloring vertices with a carefully chosen number of colors, and iterating over tripartitegraphs obtained by taking vertices of all triples of colors.Then, we introduce MainListingAlgorithm, which deals with the possibility of actual numberof triangles being larger than t . It does so in a very simple way: picking vertices at random withsome probability p and calling InnerListingAlgorithm on the obtained subgraph. We do severaliterations with various p , in order to make sure that the inner algorithm is likely to be invoked atleast once on a subgraph of G with Θ( t ) triangles. Case t ∗ t : InnerListingAlgorithm Let r = tm > ζ . As mentioned before, we are going to randomly assign r colors to vertices, anditerate over tripartite graphs, one for every triple of colors. The expected number of triangles insuch a subgraph should match its number of edges.First, however, we need to preprocess the graph to get rid of high-degree vertices. For everyvertex v ∈ G with deg v > mr , and for every edge ( u, w ) ∈ E , the algorithm checks whether ( v, u, w )is a triangle and possibly outputs it. After this, v is removed from G . There are no more than 2 r such vertices, so this step works in O ( r · m ) = O ( t ) time. From now on we may assume that thedegree of any vertex in G is at most mr .Let q = mr = tr = m t . The algorithm repeats O (log m ) times the following pattern:1. Assign to every v ∈ V a random color c v ∈ { , , . . . , r } .2. For each of the (cid:0) r (cid:1) triples of distinct colors consider the tripartite graph ˆ G = ( ˆ V , ˆ E ), whichonly retains the vertices of these three colors, and the edges between any distinct two of them.14 If | ˆ E | > ζ · q , output nothing. (For the sake of analysing the algorithm later, we marksuch a triple as failed .) • If | ˆ E | ζ · q , use BasicListingAlgorithm to list and output up to ζ · q triangles of ˆ G . (Ifthere are exactly ζ · q listed triangles, mark such a triple as vulnerable .) Lemma 26. For any G with m edges and t ∗ triangles, if t ∗ t , then InnerListingAlgorithm listsall triangles in G with high probability. If t ∗ > t , some subset of triangles is listed. The runningtime of the algorithm is always e O (cid:16) ( tm ) · T ( m t ) (cid:17) .Proof. The running time of each of O (cid:0) log m (cid:1) iterations is clearly O (cid:0) r · T ( q ) (cid:1) = O (cid:16) ( tm ) · T ( m t ) (cid:17) ,regardless of the number of triangles in G . Observe that InnerListingAlgorithm only lists triangleswhich appear in G , so the output is always a subset of all triangles.Now we assume that there are no more than t triangles in G and prove that all will be listedwith high probability. To do this, we pick an arbitrary triangle ∆ = ( x, y, z ) of G and prove that inany single iteration it is listed with probability at least 1 / 2. If we do so, we can conclude that afterΘ(log m ) iterations, the probability of ∆ not being listed goes down to poly ( m ) , with arbitrarily large poly ( m ). As there are no more than m triangles, with high probability we did not miss anything.Not listing a triangle ∆ = ( x, y, z ) can happen for one of the three reasons stated below. It isenough to prove that with the constant ζ large enough, the probability of each of them is less than1 / c x , c y , c z are not distinct. The chance of c x being equal to c y is 1 /r , so the totalchance of this bad event is no more than r < ζ .Case 2. The colors c x , c y , c z are distinct, but the triple ( c x , c y , c z ) is a failed triple. Recall that wedenote the subgraph of the chosen colors by ˆ G = ( ˆ V , ˆ E ). Let us then compute the expectedvalue of | ˆ E | . For every edge e with no endpoint in { x, y, z } , the probability of e ∈ ˆ E is r ,as its endpoints must receive two distinct colors from { c x , c y , c z } . For every edge adjacentto x , the probability is r , as the other endpoint must be colored with either c y or c z . Thereare at most m edges outside of ∆ and at most mr adjacent to it, as every vertex has degreeat most mr ; there are also three edges of ∆. By linearity of expectation, the total expectednumber of edges in ˆ G does not exceed 3 + mr = 12 q + 3 q . Therefore the probabilityof not listing ∆ because of too many edges is, by the Markov inequality, no more than ζ .Case 3. The colors c x , c y , c z are distinct, but the triple ( c x , c y , c z ) is a vulnerable triple, having morethan ζ · q triangles, which can lead to missing ∆. This time, we calculate the expectednumber of triangles in ˆ G . Let us split all the original triangles of G into four classes: • The triangles disjoint with ∆. Such a triangle appears in ˆ G if it receives some permu-tation of colors ( c x , c y , c z ) for its vertices – the chance is r and there are at most t such triangles. • The triangles with exactly one vertex common with ∆. Assume that the commonvertex is x . For any such triangle ( x, u, v ) we know that ( u, v ) is an edge in G whichis colored with ( c y , c z ) or ( c z , c y ). The probability of this is r and there are 3 m suchtriangles, as every one is uniquely determined by a vertex of ∆ and an edge of G . • The triangles with exactly two vertices of ∆. Assume ( x, y, v ) to be such a triangle.Then v must be a neighbour of x (there are at most deg x mr of them), and receivecolor c z . The probability is r , and there are no more than mr such triangles.15 The single triangle ∆.The total expected number of triangles is tr + mr + mr +1 q . Using Markov’s inequalityagain, we deduce that the probability of the triple being vulnerable cannot exceed ζ . General case: MainListingAlgorithm The main algorithm uses InnerListingAlgorithm as a subroutine, invoking it for random subgraphsof G of increasing sizes. We are going to ask InnerListingAlgorithm to list 32 t triangles. Notethat this does not increase the asymptotic running time. Moreover, the inner algorithm’s internalassumption – that the triangles to edges ratio exceeds ζ – still holds, since we only increase thedesired number of triangles and decrease the number of edges in a subgraph. As we shall see, oneof the subgraphs is expected to contain between t and 32 t triangles, and thus w.h.p. one of the callsgives us the desired answer.Let G = ( V, E ) be the input graph. Let T be the set of all listed triangles, initially T = ∅ . Weconsider every s = 0 , , . . . , log m , and for each of these values, we execute the following subroutine:1. Choose a subset e V ⊆ V by taking every vertex v ∈ V with probability p = 2 − s . Let e G be thesubgraph induced by e V .2. Call InnerListingAlgorithm on e G to list 32 t triangles, add all listed triangles to T .3. If |T | > t , stop the algorithm. Lemma 27. With at least / probability, there is at least one call of InnerListingAlgorithm with e G having between t and t triangles.Proof. Denote by T ∗ the set of all triangles in G . In every iteration of MainListingAlgorithm wepick vertices of G with probability p = 2 − s . At least one iteration must satisfy 2 t p |T ∗ | t ,so let us consider this very iteration. Let X = | f T ∗ | be the random variable that counts the numberof triangles in e G , and let us analyze the values of E [ X ] and V ar [ X ].By linearity of expectation, we have E [ X ] = P ∆ ∈T ∗ P r [∆ ∈ f T ∗ ] = p |T ∗ | . Denote this valueby µ . To compute V ar [ X ] = E [ X ] − E [ X ] , observe that E [ X ] is the expected number of orderedpairs of triangles in e G , and thus it is equal to P (∆ , ∆ ) ∈T ∗ ×T ∗ P r [∆ ∈ f T ∗ ∧ ∆ ∈ f T ∗ ]. Considerthree cases, depending on the number of common vertices of ∆ and ∆ :Case 1. For ∆ and ∆ disjoint, there are no more than |T ∗ | such pairs, and the chance for sucha pair to appear is p .Case 2. For ∆ and ∆ having one or two common vertices, we show a one-to-one mapping fromsuch pairs to T ∗ × E . If ∆ = ( a, b , c ) and ∆ = ( a, b , c ), we map (∆ , ∆ ) to(∆ , ( b , c )). If ∆ = ( a, b, c ) and ∆ = ( a, b, c ), we map (∆ , ∆ ) to (∆ , ( a, c )). It iseasy to see that we can always reconstruct (∆ , ∆ ) from its assigned pair (thus confirmingit is a one-to-one mapping), and that for (∆ , ∆ ) to appear we need at least ∆ and c to be in e G . Thus there are at most |T ∗ | · m such pairs, and the chance for a specific oneto appear is at most p .Case 3. For ∆ = ∆ , there are |T ∗ | such pairs, with p chance for each of them to appear.16e can now bound E [ X ] from above by p |T ∗ | + p |T ∗ | m + p |T ∗ | µ + µ · ( m + 1). Therefore, V ar [ X ] µ · ( m + 1) µ , as µ > t > m + 16. Using Chebyshev inequality we deduce that: P r [ X < t ∨ X > t ] P r [ | X − µ | > µ ] . This means we have no less than 3 / e G with at least t and at most 32 t triangles. By Lemma 26 this will, in turn, yield t triangles withhigh probability (in particular, with at least 3 / / O (cid:0) log m (cid:1) calls of In-nerListingAlgorithm, each one of them taking e O (cid:16) ( tm ) · T ( m t ) (cid:17) time. As stated in Lemma 27,one of the iterations succeeds, with high probability, in listing at least t triangles. Plugging in T ( m ) = m c we obtain the declared result: Theorem 17. Assume that there is an algorithm which can list up to m triangles in a graph with m edges in e O ( m c ) time, for a constant c . Then t > m triangles can be listed in (randomized, MonteCarlo) e O (cid:0) m c − t − c (cid:1) time. In this section we present an online algorithm for RangeEqPairsQuery . Our goal is to match,for q = Θ( n ), the offline runtime following from Theorem 6, and improve upon it for q significantlydifferent than n . Thanks to Lemma 8 and its generalization Theorem 13, we automatically obtainonline algorithms – with the same running time, up to polylogarithmic factors – for all the rangequery problems in our equivalence class.For a parameter β ∈ (0 , n β consecutiveblocks, each consisting of n − β consecutive elements. First, we aim to compute a matrix B , of size n β × n β , such that B [ i ][ j ] equals to the number of pairs of equal elements, the first element of apair in the i -th block, the second element in the j -th block.If a value appears in the input array at least n − γ times (for a parameter γ ∈ (0 , 1) to bedetermined later), we call it frequent , and otherwise we call it rare . We will separately computethe contribution of the frequent and rare elements to the matrix B .Note that there are at most n γ different frequent values. We construct a matrix M of size n β × n γ such that M [ i ][ j ] is the number of elements in the i -th block which are equal to the j -th frequentvalue. Then we use a fast matrix multiplication algorithm to compute the product B F = M · M T .Now we need to take into account the rare values. We initialize B R to the zero matrix of size n β × n β . For every pair ( i, j ) of equal rare elements (i.e. A [ i ] = A [ j ] and A [ i ] is rare) we calculateindices of the blocks b ( i ) and b ( j ) containing i and j , respectively, and increment B R [ b ( i )][ b ( j )] byone. We have to iterate over at most n − γ such pairs, since each rare element can appear in atmost n − γ pairs.Observe that B = B F + B R . Now, we compute a matrix S , of size ( n β + 1) × ( n β + 1),such that S [ i ][ j ] = P i ′ j . To correct for thisfact we subtract the length of the subrange and divide the result by 2. Finally, we use arrays I v toinclude pairs with at least one of the elements in one of two “tails”, at the beginning and at theend of the range, each of length at most the size of a block, i.e. n − β .The preprocessing runs in O (cid:0) n ω ( β,γ,β ) + n − γ (cid:1) time. Recall that ω ( a, b, c ) denotes the exponentin time required to multiply an n a × n b matrix by an n b × n c matrix. In particular, ω ( a, a, a ) = a · ω .After the preprocessing, each query takes O (cid:0) n − β log n (cid:1) time. In total the running time of thealgorithm is O (cid:0) n ω ( β,γ,β ) + n − γ + qn − β log n (cid:1) .For q = Θ( n ), it is optimal to set β = γ = ω +1 , and we get the time complexity e O (cid:16) n ωω +1 (cid:17) , whichmatches the upper bound following from the reduction to EdgeTriangleCounting (Theorem 6)and the current fastest algorithm for that problem [4].When n and q differ significantly from each other, optimizing the parameters β and γ leadsto a multiplication of rectangular matrices. We use a naive bound ω ( a, b, c ) a + b + c − (3 − ω ) · min( a, b, c ), which follows from a block-splitting argument. It is possible to obtain betterbounds [21], however they require numerical analysis for each particular set of values a, b, c , and thusdo not yield any meaningful closed-form formula for the running time of our algorithm. Moreover,if ω = 2, the above naive bound turns out to be tight. Let α denote log q log n . We optimize by setting β = αω +1 when q n , β = − α + ω · ( α +1) ω +1 when q > n , and in both cases γ = 1 + β − α , which givesthe following running times: Theorem 9. RangeEqPairsQuery can be solved online in time T ( n, q ) = e O (cid:16) nq ω − ω +1 (cid:17) if q n e O (cid:16) n ω − ω +1 q ω +1 (cid:17) if q > n. 18n the above description we assume implicitly that we know the number of queries q in advanceand can adjust parameters β and γ accordingly. Without this optimistic assumption we starthypothesizing q = 1, and whenever the actual number of queries exceeds the present guess of q ,we multiply it by 2, update the parameters and rerun the preprocessing. Doing so we lose only aconstant multiplicative factor.Let us compare this running time against a lower bound that follows from the set disjointnessframework of Kopelowitz, Pettie and Porat [18]. Theorem 28 (Kopelowitz, Pettie, Porat [18] (rephrased)) . Unless the SUM Hypothesis fails, forany constants λ < , ε > , there is no O (cid:0) N − ε (cid:1) time algorithm that determines disjointnessfor each of Θ (cid:0) N λ (cid:1) pairs of sets from a family of Θ( N ) sets of size Θ (cid:0) N − λ (cid:1) each. Note that the above set disjointness problem easily reduces to withΘ (cid:0) N λ (cid:1) queries in an array of length Θ (cid:0) N · N − λ (cid:1) . Therefore we have T ( N − λ , N λ ) = Ω (cid:0) N − ε (cid:1) ,for any 0 λ < 1, which finally yields the following corollary. Corollary 29. Unless the SUM Hypothesis fails, there is no O (cid:0) ( nq ) / − ε (cid:1) time algorithm for RangeEqPairsQuery for any constant ε > . This even holds restricted to instances with q = n α ± o (1) , for arbitrarily chosen α < . See Figure 2 for a visual comparison of these bounds. (min , max) -product Theorem 21. If for q = n can be solved offline in T ( n ) time, then the (min , max) -product of two n × n matrices can be computed in e O (cid:0) T ( n ) (cid:1) time.Proof. Let A and B be the input matrices. For every i = 1 , , . . . , n let A i denote a permutationof the column indices { , , . . . , n } sorted by their corresponding values in the i -th row of A , thatis A [ i ][ A i [ k ]] A [ i ][ A i [ k + 1]] for every k . Analogously, for every j = 1 , , . . . , n let B j denote apermutation of the row indices of the j -th column of B sorted in nondecreasing order of the entries.We concatenate all A i ’s and all B j ’s together to form a single array T .The key idea behind our reduction is the following simple equivalence. C [ i ][ j ] = min k max( A [ i ][ k ] , B [ k ][ j ]) x ⇐⇒ { k : A [ i ][ k ] x } ∩ { k : B [ k ][ j ] x } 6 = ∅ Observe that the two sets on the right-hand side are sets of elements of a prefix of A i and a prefixof B j . Therefore, we can learn if a particular C [ i ][ j ] is below or above a given threshold by askinga single query whether two ranges in T have disjoint sets of elements. The lengths of the relevantprefixes can be computed just before with a simple binary search in O (log n ) time. With n querieswe can learn this for the entire matrix C , and nothing forbids us from specifying a different thresholdfor each matrix cell.We can assume that the entries in A and B , and therefore also in C , are integers in [1 , n ].Indeed, if they were not, we could replace each entry with its position in the overall sorted order ofall entries in A or B . Hence, it takes O (log n ) steps of a parallel binary search – each consisting ofsolving an (offline) instance of with n queries in an array of n elements– to compute the matrix C . 19 Open problems A notable absence in our triangle-related problems landscape is TriangleCounting – finding thetotal number of all triangles in an m -edge graph. The fastest known algorithm is the one providedby Alon, Yuster and Zwick [4], working in O (cid:0) m ω/ ( ω +1) (cid:1) time, which anyway solves EdgeTrian-gleCounting as a byproduct. While a possible faster algorithm for TriangleCounting has notbeen (conditionally) ruled out, we believe that there may exist a reduction proving the equivalenceof EdgeTriangleCounting and TriangleCounting . Open Problem 1. Are TriangleCounting and EdgeTriangleCounting equivalent? If not,can we solve TriangleCounting faster than O (cid:0) m ω/ ( ω +1) (cid:1) time? The equivalent triangle and range query problems considered in this paper have a (conditional)lower bound of m / − o (1) and an upper bound of O (cid:0) m ω/ ( ω +1) (cid:1) O (cid:0) m . (cid:1) . Bridging this gap is along-standing open question. Obviously, if ω = 2, the question would be resolved. Suppose, however,that ω > e O (cid:0) m / (cid:1) time) algorithm is found for EdgeTriangleCounting andthus, by Theorems 6 and 13, for all our offline range query problems. Would it also imply fasteronline algorithms? In other words, can we use an offline range query algorithm as a black-boxto find an online algorithm of the same complexity? As of now, we can neither provide such anequivalence, nor prove a higher conditional lower bound for online variants. Open Problem 2. Are the offline and online variants of our range query problems equivalent? Finally, as can be seen in Figure 2, our lower bound and upper bound for range query problemsdo not match when the number of queries is sublinear in n , even if ω = 2. For example, for q = n / ± o (1) the lower bound becomes trivial Ω( n ), and the upper bound is e O (cid:0) n (3 ω +1) / (2 ω +2) (cid:1) ,which is at best e O (cid:0) n / (cid:1) , if ω = 2. Open Problem 3. What is the complexity of the range query problems for q = n α ± o (1) and α ∈ (0 , ? A Mo’s algorithm Mo’s algorithm became a standard tool in the competitive programming community, but it seemsvirtually nonexistent in the theoretical computer science literature. For the sake of completeness,in this section we present the original offline algorithm, and propose how to generalize it for onlineproblems by using persistent data structures. A.1 Offline algorithm For common range query problems the following observation holds: it is possible – usually with ahelp of a simple data structure, e.g. a binary search tree – to quickly transform the answer for thecurrent range into the answer for a range one element shorter or longer at either end, and thenupdate the data structure, so that successive such transformations can be applied again and again.If that operation can be performed in polylogarithmic time, then a straightforward algorithm cananswer q queries in an array of length n in e O (cid:0) n + q (cid:1) time, by precomputing all possible queries. Tosimplify further analysis we will assume q n , otherwise the above algorithm is optimal. Anothernaive approach is to do no preprocessing and compute the answer to each query from scratch, intime e O ( nq ). Mo’s technique provides a simple framework reducing the runtime down to e O (cid:0) n √ q (cid:1) .20ecall that we denote the i -th query by [ l i , r i ], for i = 1 , , . . . , q . Observe that we can answerall the queries, one after the other, by performing P i (cid:0) | l i − l i − | + | r i − r i − | (cid:1) operations on theunderlying data structure, each taking polylogarithmic time. Mo’s central idea is to make this sumsmall by leveraging the fact that the algorithm works offline, i.e. it knows all the queries in advance,and thus can handle them in a favorable order. Therefore, for a parameter B to be determinedlater, it sorts the queries by ⌊ l i /B ⌋ and in case of a tie by r i . To avoid double indexing, in theanalysis below we work with this rearranged order.Observe that P i | l i − l i − | O ( n + B · q ), because | l i − l i − | = ( l i − l i − ) + 2 · max( l i − − l i , P i ( l i − l i − ) = l q − l n , while the ordering guarantees l i − − l i B . On the other hand, P i | r i − r i − | O (( n/B ) · n ), as there are at most n/B different values of ⌊ l i /B ⌋ and the queriesare sorted by increasing values of r i ’s within each value of ⌊ l i /B ⌋ . This gives the total runningtime of e O ( B · q + ( n/B ) · n + n + q ). We optimize it by setting B = n/ √ q (thanks to the q n assumption we are guaranteed that B > e O (cid:0) n √ q (cid:1) time bound. A.2 Online algorithm Mo’s algorithm can only be used offline, i.e. when all the queries are known beforehand. Thereare other general methods for solving range query problems, which do work in the online setting,most notably a square root decomposition method, i.e. dividing the array into √ n consecutiveblocks. However, for some problems, e.g. calculating the number of distinct elements within arange, these methods do not seem to apply, while Mo’s algorithm gives an immediate (albeit offline-only) solution. Fortunately, for usual range query problems Mo’s algorithm uses common datastructures, ones which are known to have fully persistent equivalents – a circumstance we shallexploit to design an online algorithm. Our solution matches the time complexity of the originalMo’s algorithm, but it requires e O (cid:0) n √ q (cid:1) space while the offline version uses only linear space.A data structure is called persistent if it supports access to its older versions, called snapshots .A persistent data structure is called fully persistent if its snapshots can be modified, and thereforeit allows working with a branched history. Many common data structures have been shown to havefully persistent equivalents with desirable properties, i.e. polylogarithmic access and update timesand constant space utilization per update [10, 25].Suppose that it is possible to transform the answer for a given range into the answer for a rangeone element longer at either end with a fully persistent data structure S with polylogarithmicaccess and update times. In the preprocessing phase we choose a parameter B and for each j = 0 , , . . . , ⌊ n/B ⌋ we incrementally compute (and store) the results for hypothetical queries[ B · j, k ] for each k ∈ { B · j, . . . , n } . That is, we keep one instance of S per each j , and we take asnapshot of it for each k . By virtue of the properties of fully persistent data structures, this takes e O (( n/B ) · n ) time and space.When a query [ l, r ] arrives, we take the precomputed result and the related data structuresnapshot for the hypothetical query (cid:2) B · ⌈ l/B ⌉ , r (cid:3) (unless B · ⌈ l/B ⌉ > r , in which case we create anad hoc instance of the data structure for the one-element [ r, r ] range). We then extend the resultin e O ( B ) time by adding elements at the front of the range, one element at a time, until we reach[ l, r ].If we have an a priori bound on the number of queries, we optimize by setting B = n/ √ q , justlike for the offline Mo’s algorithm, and obtain an e O (cid:0) n √ q (cid:1) running time. Without such knowledge,we proceed analogously as in the algorithm of Theorem 9: We start hypothesizing q = 1, and Note that, unlike in standard Mo’s algorithm, we do not require computing the answer for a range one elementshorter. q , we multiply it by 2, adjust B and rerun the preprocessing. Doing so we only lose a constant multiplicative factor. References [1] Amir Abboud, Fabrizio Grandoni, and Virginia Vassilevska Williams. Subcubic equivalencesbetween graph centrality problems, APSP and diameter. In Proceedings of the Twenty-SixthAnnual ACM-SIAM Symposium on Discrete Algorithms, SODA 2015, San Diego, CA, USA,January 4-6, 2015 , pages 1681–1697, 2015.[2] Amir Abboud and Virginia Vassilevska Williams. Popular conjectures imply strong lowerbounds for dynamic problems. In , pages 434–443, 2014.[3] Udit Agarwal and Vijaya Ramachandran. Fine-grained complexity for sparse graphs. In Proceedings of the 50th Annual ACM SIGACT Symposium on Theory of Computing, STOC2018, Los Angeles, CA, USA, June 25-29, 2018 , pages 239–252, 2018.[4] Noga Alon, Raphael Yuster, and Uri Zwick. Finding and counting given length cycles. Algo-rithmica , 17(3):209–223, Mar 1997.[5] Bertie Ancona, Monika Henzinger, Liam Roditty, Virginia Vassilevska Williams, and NicoleWein. Algorithms and Hardness for Diameter in Dynamic Graphs. In Christel Baier, IoannisChatzigiannakis, Paola Flocchini, and Stefano Leonardi, editors, , volume 132 of Leibniz In-ternational Proceedings in Informatics (LIPIcs) , pages 13:1–13:14, Dagstuhl, Germany, 2019.Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik.[6] Michael A. Bender and Mart´ın Farach-Colton. The LCA problem revisited. In LATIN 2000:Theoretical Informatics , pages 88–94, Berlin, Heidelberg, 2000. Springer Berlin Heidelberg.[7] Andreas Bj¨orklund, Rasmus Pagh, Virginia Vassilevska Williams, and Uri Zwick. Listingtriangles. In Automata, Languages, and Programming - 41st International Colloquium, ICALP2014, Copenhagen, Denmark, July 8-11, 2014, Proceedings, Part I , pages 223–234, 2014.[8] Karl Bringmann, Marvin K¨unnemann, and Karol Wegrzycki. Approximating APSP withoutscaling: Equivalence of approximate min-plus and exact min-max. In Proc. STOC , pages943–954. ACM, 2019.[9] Gerth Stølting Brodal, Beat Gfeller, Allan Grønlund Jørgensen, and Peter Sanders. Towardsoptimal range medians. Theoretical Computer Science , 412(24):2588–2601, 2011. Selected Pa-pers from 36th International Colloquium on Automata, Languages and Programming (ICALP2009).[10] James R. Driscoll, Neil Sarnak, Daniel D. Sleator, and Robert E. Tarjan. Making data struc-tures persistent. J. Comput. Syst. Sci. , 38(1):86–124, February 1989.[11] Ran Duan and Seth Pettie. Fast algorithms for (max, min)-matrix multiplication and bot-tleneck shortest paths. In Proceedings of the Twentieth Annual ACM-SIAM Symposium onDiscrete Algorithms, SODA 2009, New York, NY, USA, January 4-6, 2009 , pages 384–391,2009. 2212] Bart lomiej Dudek and Pawe l Gawrychowski. Computing quartet distance is equivalent tocounting 4-cycles. In Proceedings of the 51st Annual ACM SIGACT Symposium on Theory ofComputing, STOC 2019, Phoenix, AZ, USA, June 23-26, 2019. , pages 733–743, 2019.[13] Harold N. Gabow, Jon Louis Bentley, and Robert E. Tarjan. Scaling and related techniquesfor geometry problems. In Proceedings of the Sixteenth Annual ACM Symposium on Theoryof Computing , STOC ’84, pages 135–143, New York, NY, USA, 1984. ACM.[14] Omer Gold and Micha Sharir. Dominance Product and High-Dimensional Closest Pair under L ∞ . In Yoshio Okamoto and Takeshi Tokuyama, editors, , volume 92 of Leibniz International Proceedings inInformatics (LIPIcs) , pages 39:1–39:12, Dagstuhl, Germany, 2017. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik.[15] Daniel Graf, Karim Labib, and Przemys law Uzna´nski. Hamming distance completeness andsparse matrix multiplication. CoRR , abs/1711.03887, 2017.[16] Alon Itai and Michael Rodeh. Finding a minimum circuit in a graph. SIAM J. Computing ,7(4):413–423, 1978.[17] Carmel Kent, Gad M. Landau, and Michal Ziv-Ukelson. On the complexity of sparse exon as-sembly. In Combinatorial Pattern Matching , pages 201–218, Berlin, Heidelberg, 2005. SpringerBerlin Heidelberg.[18] Tsvi Kopelowitz, Seth Pettie, and Ely Porat. Higher lower bounds from the 3SUM conjecture.In Proceedings of the Twenty-seventh Annual ACM-SIAM Symposium on Discrete Algorithms ,SODA ’16, pages 1272–1287, Philadelphia, PA, USA, 2016. Society for Industrial and AppliedMathematics.[19] Karim Labib, Przemys law Uzna´nski, and Daniel Wolleb-Graf. Hamming Distance Complete-ness. In Nadia Pisanti and Solon P. Pissis, editors, , volume 128 of Leibniz International Proceedings in Informatics(LIPIcs) , pages 14:1–14:17, Dagstuhl, Germany, 2019. Schloss Dagstuhl–Leibniz-Zentrum fuerInformatik.[20] Fran¸cois Le Gall. Powers of tensors and fast matrix multiplication. In Proceedings of the 39thInternational Symposium on Symbolic and Algebraic Computation , ISSAC ’14, pages 296–303,New York, NY, USA, 2014. ACM.[21] Fran¸cois Le Gall and Florent Urrutia. Improved rectangular matrix multiplication using powersof the Coppersmith-Winograd tensor. In Proceedings of the Twenty-Ninth Annual ACM-SIAMSymposium on Discrete Algorithms , SODA ’18, pages 1029–1046, Philadelphia, PA, USA, 2018.Society for Industrial and Applied Mathematics.[22] Andrea Lincoln, Virginia Vassilevska Williams, and R. Ryan Williams. Tight hardness forshortest cycles and paths in sparse graphs. In Proceedings of the Twenty-Ninth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2018, New Orleans, LA, USA, January 7-10,2018 , pages 1236–1252, 2018.[23] Jiˇr´ı Matouˇsek. Computing dominances in E n . Inf. Process. Lett. , 38(5):277–278, 1991.[24] Jaroslav Neˇsetˇril and Svatopluk Poljak. On the complexity of the subgraph problem. Com-mentationes Math. Universitatis Carolinae , 26(2):415–419, 1985.2325] Chris Okasaki. Purely Functional Data Structures . Cambridge University Press, New York,NY, USA, 1998.[26] Mihai Pˇatra¸scu. Towards polynomial lower bounds for dynamic problems. In Proceedings ofthe Forty-second ACM Symposium on Theory of Computing , STOC ’10, pages 603–610, NewYork, NY, USA, 2010. ACM.[27] Liam Roditty and Virginia Vassilevska Williams. Minimum weight cycles and triangles: Equiva-lences and algorithms. In IEEE 52nd Annual Symposium on Foundations of Computer Science,FOCS 2011, Palm Springs, CA, USA, October 22-25, 2011 , pages 180–189, 2011.[28] Thomas Schank and Dorothea Wagner. Finding, counting and listing all triangles in largegraphs, an experimental study. In Experimental and Efficient Algorithms , pages 606–609,Berlin, Heidelberg, 2005. Springer Berlin Heidelberg.[29] Virginia Vassilevska, Ryan Williams, and Raphael Yuster. All-pairs bottleneck paths for gen-eral graphs in truly sub-cubic time. In Proceedings of the 39th Annual ACM Symposium onTheory of Computing, San Diego, California, USA, June 11-13, 2007 , pages 585–589, 2007.[30] Virginia Vassilevska, Ryan Williams, and Raphael Yuster. All pairs bottleneck paths andmax-min matrix products in truly subcubic time. Theory of Computing , 5(1):173–189, 2009.[31] Virginia Vassilevska Williams. Multiplying matrices faster than Coppersmith-Winograd. In Proceedings of the 44th Symposium on Theory of Computing Conference, STOC 2012, NewYork, NY, USA, May 19 - 22, 2012 , pages 887–898, 2012.[32] Virginia Vassilevska Williams. Homework 2 of CS367 at Stanford from 2015 (and 2014). http://theory.stanford.edu/~virgi/cs367/hw2.pdf , 2015.[33] Virginia Vassilevska Williams and Ryan Williams. Subcubic equivalences between path, matrixand triangle problems. In51th Annual IEEE Symposium on Foundations of Computer Science,FOCS 2010, October 23-26, 2010, Las Vegas, Nevada, USA