Introduction
In min-plus multiplication and sequential dynamic programming, each output is a minimum over candidate rows whose costs include a row-dependent offset. When the transition matrix is Monge, SMAWK [1 ] computes the product of an arbitrary n × n n \times n n × n matrix with that transition matrix in O ( n 2 ) O(n^2) O ( n 2 ) time, and the algorithms of Wilber and of Larmore and Schieber [31 , 17 ] evaluate a triangular Monge recurrence in linear time. We study how these running times depend on the number of adjacent Monge inequalities violated by local rewards or interval adjustments to the transition costs.
For fixed row and column orders, define the adjacent mixed difference of a cost array C C C by
Δ C p , q = C ( p + 1 , q ) + C ( p , q + 1 ) − C ( p , q ) − C ( p + 1 , q + 1 ) . \Delta C_{p,q} = C(p + 1,q) + C(p,q + 1) - C(p,q) - C(p + 1,q + 1). Δ C p , q = C ( p + 1 , q ) + C ( p , q + 1 ) − C ( p , q ) − C ( p + 1 , q + 1 ) .
and measure its negative support by
N ( C ) = { ( p , q ) : Δ C p , q < 0 } , s ( C ) = ∣ N ( C ) ∣ . \mathcal{N}(C) = \{(p,q) : \Delta C_{p,q} < 0\}, \qquad s(C) = |\mathcal{N}(C)|. N ( C ) = {( p , q ) : Δ C p , q < 0 } , s ( C ) = ∣ N ( C ) ∣.
The adjacent Monge inequalities require Δ C p , q ≥ 0 \Delta C_{p,q} \ge0 Δ C p , q ≥ 0 at every cell, and algorithms for core-sparse Monge multiplication [25 , 22 , 14 ] use the number δ ( C ) \delta(C) δ ( C ) of nonzero adjacent differences. The parameter s ( C ) s(C) s ( C ) counts the cells that violate the inequality, so an array with small s ( C ) s(C) s ( C ) can have Θ ( n 2 ) \Theta(n^2) Θ ( n 2 ) positive differences. Adding row and column potentials a k + b j a_k + b_j a k + b j preserves every mixed difference and hence s ( C ) s(C) s ( C ) , including when the row potentials are entries A i k A_{ik} A ik of a fixed row of the left factor or prefix optima D [ k ] D[k] D [ k ] in a recurrence.
Main results
We write L = ⌈ log 2 ( n + 1 ) ⌉ L = \lceil\log_{2}(n + 1) \rceil L = ⌈ log 2 ( n + 1 )⌉ and use the same tree of row minima for matrix products, where the offsets are supplied with each input row, and for sequential recurrences, where the computation supplies an offset when it reaches the corresponding state. Table 1 gives the bounds for each input representation.
Table 1 . Time and working space for products and partitioning, with L = ⌈ log 2 ( n + 1 ) ⌉ L = \lceil\log_{2}(n + 1) \rceil L = ⌈ log 2 ( n + 1 )⌉ and constant-time entry or penalty oracles. Space for convex transitions is given per vector. For s ( B ) ≤ n 1 + α s(B) \le n^{1+\alpha} s ( B ) ≤ n 1 + α and fixed 3 − c A P S P < α ≤ 1 3 - c_{\mathrm{APSP}} < \alpha\le1 3 − c APSP < α ≤ 1 , the product lower exponent is c A P S P − 1 + α c_{\mathrm{APSP}} - 1 + \alpha c APSP − 1 + α .
Table 1. Time and working space for products and partitioning, with L = ⌈ log 2 ( n + 1 ) ⌉ L = \lceil\log_{2}(n + 1) \rceil L = ⌈ log 2 ( n + 1 )⌉ and constant-time entry or penalty oracles. Space for convex transitions is given per vector. For s ( B ) ≤ n 1 + α s(B) \le n^{1+\alpha} s ( B ) ≤ n 1 + α and fixed 3 − c A P S P < α ≤ 1 3 - c_{\mathrm{APSP}} < \alpha\le1 3 − c APSP < α ≤ 1 , the product lower exponent is c A P S P − 1 + α c_{\mathrm{APSP}} - 1 + \alpha c APSP − 1 + α .
Min-plus matrix multiplication. For explicit finite n × n n \times n n × n matrices A , B A, B A , B with s = s ( B ) s = s(B) s = s ( B ) , Theorem 3.5 computes A ⊗ B A \otimes B A ⊗ B and the smallest minimizing index for each entry in O ( n 2 L + n s L 3 ) \mathcal{O}(n^{2}L + nsL^{3}) O ( n 2 L + n s L 3 ) time and O ( n 2 ) \mathcal{O}(n^{2}) O ( n 2 ) space, which gives O ( n 2 L 3 ) \mathcal{O}(n^{2}L^{3}) O ( n 2 L 3 ) time when s = O ( n ) s = \mathcal{O}(n) s = O ( n ) and allows every other cell of Δ B \Delta B Δ B to be strictly positive.
Sequential partitioning. Given a Monge background oracle M M M with query time T M T_{M} T M and r r r rectangles I ℓ × J ℓ I_{\ell} \times J_{\ell} I ℓ × J ℓ with signed weights α ℓ ∈ R \alpha_{\ell} \in\mathbb{R} α ℓ ∈ R , Theorem 3.6 evaluates the recurrence
D [ j ] = min 0 ≤ k < j { D [ k ] + M ( k , j ) + ∑ ℓ = 1 r α ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } } D[j] = \min_{0 \le k < j} \left\{D[k] + M(k,j) + \sum_{\ell=1}^{r} \alpha_{\ell} \mathbf{1}\{k \in I_{\ell}\}\mathbf{1}\{j \in J_{\ell}\}\right\} D [ j ] = 0 ≤ k < j min { D [ k ] + M ( k , j ) + ℓ = 1 ∑ r α ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } }
and reconstructs an optimal partition in O ( ( n + r ) L 2 ( L + T M ) ) \mathcal{O}((n + r)L^{2}(L + T_{M})) O (( n + r ) L 2 ( L + T M )) time and O ( n + r ) \mathcal{O}(n + r) O ( n + r ) working space. Given constant-time access to C C C and the complete list of its s s s negative legal differences, a persistent segment tree evaluates M M M in O ( L ) \mathcal{O}(L) O ( L ) time per query, giving O ( ( n + s ) L 3 ) \mathcal{O}((n + s)L^{3}) O (( n + s ) L 3 ) total time and O ( n + s L ) \mathcal{O}(n + sL) O ( n + s L ) additional space (Corollary 3.7). Applying the sweep to each layer of the recurrence for exactly K K K blocks takes O ( K ( n + r ) L 2 ( L + T M ) ) \mathcal{O}(K(n + r)L^{2}(L + T_{M})) O ( K ( n + r ) L 2 ( L + T M )) time (Corollary 3.8).
Convex transitions and contiguous partitions. For a convex transition cost ϕ ( y j − x k ) \phi(y_{j} - x_{k}) ϕ ( y j − x k ) with r r r interval surcharges or discounts, s ( B ) ≤ 2 r s(B) \le2r s ( B ) ≤ 2 r and the list of rules gives an O ( n L + r L 3 ) \mathcal{O}(nL + rL^{3}) O ( n L + r L 3 ) -time vector product (Corollary 4.2 ). For a contiguous block with convex load cost ϕ ( S j − S k ) \phi(S_{j} - S_{k}) ϕ ( S j − S k ) and internal rewards ∑ e ⊆ ( k , j ] w e \sum_{e \subseteq(k,j]} w_{e} ∑ e ⊆ ( k , j ] w e , each of the h h h edges or hyperedges supplies one rectangle, so processing the incidence input of size N N N and running the sweep takes O ( N + ( n + h ) L 3 ) \mathcal{O}(N + (n + h)L^{3}) O ( N + ( n + h ) L 3 ) time for a constant-time penalty. § 4 gives the resulting algorithms for ordered graph modularity [21 ] , weighted contiguous cluster editing, all-or-nothing HyperLam [30 ] , bounded-rank strict hypergraph modularity [16 ] , and FENNEL with a fixed number of blocks [26 ] .
Product lower bounds. For fixed 0 < α ≤ 1 0 < \alpha\le1 0 < α ≤ 1 , Theorem 5.1 reduces general min-plus multiplication on polynomially bounded integer entries to O ( n 1 − α ) \mathcal{O}(n^{1-\alpha}) O ( n 1 − α ) products with s ( B ) ≤ n 1 + α s(B) \le n^{1+\alpha} s ( B ) ≤ n 1 + α , so a deterministic O ( n β ) O(n^\beta) O ( n β ) -time algorithm for these products gives an O ( n 1 − α + β + n 3 − α ) O(n^{1-\alpha+\beta}+n^{3-\alpha}) O ( n 1 − α + β + n 3 − α ) -time algorithm for the general problem. For 3 − c A P S P < α ≤ 1 3-c_{\mathrm{APSP}}<\alpha\le1 3 − c APSP < α ≤ 1 , the resulting lower exponent c A P S P − 1 + α c_{\mathrm{APSP}}-1+\alpha c APSP − 1 + α and the sweep’s upper exponent 2 + α 2+\alpha 2 + α differ by 3 − c A P S P 3-c_{\mathrm{APSP}} 3 − c APSP . The right factors used in the reduction have background ( j − k ) 2 (j-k)^2 ( j − k ) 2 , at most n 1 + α n^{1+\alpha} n 1 + α interval discounts, Θ ( n 2 ) \Theta(n^2) Θ ( n 2 ) positive mixed differences, and a negative difference at every remaining cell (§ 5 ).
The column sweep
Rectangle corrections. The indicator Q p , q ( k , j ) = 1 { k ≤ p } 1 { j > q } Q_{p,q}(k,j)=1\{k\le p\}1\{j>q\} Q p , q ( k , j ) = 1 { k ≤ p } 1 { j > q } has adjacent mixed difference 1 1 1 at ( p , q ) (p,q) ( p , q ) and 0 0 0 at every other cell.
By linearity, adding R ( k , j ) = ∑ ( p , q ) ∈ N ( C ) ( − Δ C p , q ) Q p , q ( k , j ) R(k,j)=\sum_{(p,q)\in\mathcal{N}(C)}(-\Delta C_{p,q})Q_{p,q}(k,j) R ( k , j ) = ∑ ( p , q ) ∈ N ( C ) ( − Δ C p , q ) Q p , q ( k , j ) to C C C gives Δ ( C + R ) p , q = max { Δ C p , q , 0 } \Delta(C+R)_{p,q}=\max\{\Delta C_{p,q},0\} Δ ( C + R ) p , q = max { Δ C p , q , 0 } , so telescoping shows that M = C + R M=C+R M = C + R is Monge and C = M − R C=M-R C = M − R uses s ( C ) s(C) s ( C ) rectangles, each consisting of a row prefix and a column suffix.
Table 1 (PDF p. 3).
For a supplied rectangle I ℓ × J ℓ I_\ell\times J_\ell I ℓ × J ℓ of weight α ℓ \alpha_\ell α ℓ , the sweep adds α ℓ \alpha_\ell α ℓ on I ℓ I_\ell I ℓ at column min J ℓ \min J_\ell min J ℓ and subtracts it at max J ℓ + 1 \max J_\ell+1 max J ℓ + 1 if that column is in the domain, giving at most 2 r 2r 2 r interval additions for r r r rectangles.
Lower envelopes of rows. At column j j j an active row k k k defines a function f k ( x ) = v k + M ( k , x ) f_k(x)=v_k+M(k,x) f k ( x ) = v k + M ( k , x ) for x ≥ j x\ge j x ≥ j , where v k v_k v k is the base potential plus the weights of the rectangles currently covering the row. For two nonempty sets of active rows A , B A,B A , B with every row of A A A preceding every row of B B B , the difference of their lower envelopes F A ( x ) − F B ( x ) F_A(x)-F_B(x) F A ( x ) − F B ( x ) is nondecreasing by Lemma 3.2 , so the columns where F B ( x ) < F A ( x ) F_B(x)<F_A(x) F B ( x ) < F A ( x ) form a possibly empty suffix whose first column determines the switch between the two sets.
Our balanced binary tree T T T on [ 0 , n − 1 ] [0,n-1] [ 0 , n − 1 ] follows Russo’s switching-point trees [22 ] , with each internal node u u u storing the switch column θ u \theta_u θ u of its children and a lazy addition z u z_u z u . Adding β \beta β to all active rows in a subtree shifts both child envelopes by β \beta β and preserves all switches in the subtree, so ADD ( I , β ) \operatorname{ADD}(I,\beta) ADD ( I , β ) stores lazy additions at O ( L ) O(L) O ( L ) fully covered subtrees and uses binary search to rebuild switches at O ( L ) O(L) O ( L ) partially covered ancestors in O ( L 2 ( L + T M ) ) O(L^2(L+T_M)) O ( L 2 ( L + T M )) total time.
Row activation. For a vector product, all row potentials x k x_k x k are available at column 0 0 0 , so the tree activates the leaves together and constructs the switches from the leaves to the root in O ( n L ( 1 + T M ) ) O(nL(1+T_M)) O ( n L ( 1 + T M )) time. In a sequential recurrence the sweep activates row k = j − 1 k=j-1 k = j − 1 after computing D [ k ] D[k] D [ k ] , using a Fenwick tree H H H that records the total weight H j ( k ) = ∑ ℓ α ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } H_j(k)=\sum_\ell\alpha_\ell1\{k\in I_\ell\}1\{j\in J_\ell\} H j ( k ) = ∑ ℓ α ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } for every row, including rectangles whose entry event preceded activation. Each event updates H H H in O ( L ) O(L) O ( L ) time and updates the envelope tree on the part of its row interval in [ 0 , j − 2 ] [0,j-2] [ 0 , j − 2 ] , after which a point query in H H H gives the new row its potential D [ k ] + H j ( k ) D[k]+H_j(k) D [ k ] + H j ( k ) .
Interval rewards and the product reduction. An edge or hyperedge e e e belongs to the block ( k , j ) (k,j) ( k , j ) precisely when k < min e k<\min e k < min e and j ≥ max e j\ge\max e j ≥ max e , so a scan of its ∣ e ∣ |e| ∣ e ∣ vertices gives the rectangle [ 0 , min e − 1 ] × [ max e , n ] [0,\min e-1]\times[\max e,n] [ 0 , min e − 1 ] × [ max e , n ] of weight − w e -w_e − w e used with the convex block cost ϕ ( S j − S k ) \phi(S_j-S_k) ϕ ( S j − S k ) . In the product reduction of Theorem 5.1 , scaling the integer costs by λ = 2 n 2 + 1 \lambda=2n^2+1 λ = 2 n 2 + 1 and adding a squared-distance background gives an adjusted cost λ t − 2 k j \lambda t-2kj λ t − 2 k j for a candidate of original cost t t t , where 0 ≤ 2 k j < λ 0\le2kj<\lambda 0 ≤ 2 k j < λ , so dividing the adjusted minimum by λ \lambda λ and rounding up recovers the original entry.
Related work
Monge matrix products. SMAWK [1 ] finds the row minima of a totally monotone n × n n\times n n × n matrix in O ( n ) O(n) O ( n ) evaluations, and Tiskin [25 ] gave an O ( n log n ) O(n\log n) O ( n log n ) multiplication algorithm for simple unit-Monge matrices. For general Monge factors, Russo [22 , 23 ] developed switching-point trees whose product construction depends on the core size of the left factor, and Gawrychowski, Gorbachev, and Kociumaka [14 ] compute the condensed product of two condensed Monge matrices in O ( n + δ log ( 1 + δ ) ) O(n+\delta\log(1+\delta)) O ( n + δ log ( 1 + δ )) time for total input core size δ \delta δ . Appendix § 9 .§ 1 derives the time bound of Theorem 3.5 for product values by encoding the negative differences of the right factor in an auxiliary Monge matrix and querying an antidiagonal of Russo’s implicit product.
Monge recurrences and convolutions. In online algorithms for Monge recurrences and shortest paths [31 , 17 , 13 ] , rows become available sequentially and retain their assigned potentials, while the data structure of Charalampopoulos et al. [8 ] supports sub-row increments in O ( log 3 n ) O(\log^3 n) O ( log 3 n ) time per update when each intermediate matrix is Monge. In our sweep an interval addition shifts the selected rows uniformly over future columns and activation supplies the next row potential, so at each step the active functions v k + M ( k , x ) v_k+M(k,x) v k + M ( k , x ) form a Monge array, and changes in the row offsets from one step to the next can give the complete transition matrix C C C negative differences.
For displacement costs g ( j − k ) g(j-k) g ( j − k ) , Felzenszwalb and Huttenlocher [12 ] give linear-time convex distance transforms, and applying the convex-kernel convolution bound of Brand and Lassota [5 ] to the convex pieces of a kernel with t t t negative second differences takes O ( n ( t + 1 ) ) O(n(t+1)) O ( n ( t + 1 )) time. Our rectangle representation allows independent row and column intervals for each correction to a convex coordinate cost. Carmel, Tsur, and Ziv-Ukelson [6 , 7 ] bound the number of nonzero density entries of either sign in the all-scores matrix of an alignment grid with b b b bridges by O ( n ( b + 1 ) ) O(n(b+1)) O ( n ( b + 1 )) .
Contiguous partitioning and APSP. Patania, Allard, and Young [21 ] give exact algorithms for graph modularity in O ( n 2 ) O(n^2) O ( n 2 ) time for a linear order and O ( n 3 ) O(n^3) O ( n 3 ) time for a cyclic order (see also Li, Cao, and Zhang [18 ] ), and Ahrens [2 ] obtains near-linear algorithms for contiguous communication objectives under quadrangle monotonicity. The block costs for modularity [20 ] , HyperLam [30 ] , strict hypergraph modularity [16 ] , FENNEL [26 ] , and ordered cluster editing [29 , 4 , 19 ] admit a convex penalty and internal rewards, which can give mixed differences of both signs.
Vassilevska Williams and Williams [27 ] established subcubic equivalences between APSP, min-plus products, and triangle problems, and Heeger, Nichterlein, and Niedermeier [15 ] studied parameterized cross-compositions for Negative Triangle. For polynomially bounded integer weights, Alman and Vassilevska Williams [3 ] gave a deterministic O ( n 2.99942 ) O(n^{2.99942}) O ( n 2.99942 ) algorithm for APSP and min-plus multiplication, and Saha and Ye [24 ] improved the multiplication bound to O ~ ( n 2.9964 ) \widetilde{O}(n^{2.9964}) O ( n 2.9964 ) .
Preliminaries
We index square matrices by [ 0 , n − 1 ] [0,n-1] [ 0 , n − 1 ] and partitions of n n n ordered vertices by cuts 0 , … , n 0,\ldots,n 0 , … , n , with ( k , j ] (k,j] ( k , j ] denoting the vertices after cut k k k and up to cut j j j . All intervals are integer intervals, with [ a , b ] [a,b] [ a , b ] empty for a > b a>b a > b , and we write 1 { P } \mathbf{1}\{P\} 1 { P } for the indicator of a predicate P P P and L = ⌈ log 2 ( n + 1 ) ⌉ L=\lceil\log_2(n+1)\rceil L = ⌈ log 2 ( n + 1 )⌉ as in Table 2 .
Table 2. Notation.
Monge arrays and mixed differences. On the square [ 0 , n − 1 ] 2 [0,n-1]^2 [ 0 , n − 1 ] 2 or the triangular domain T n = { ( k , j ) : 0 ≤ k < j ≤ n } \mathcal{T}_n=\{(k,j):0\le k<j\le n\} T n = {( k , j ) : 0 ≤ k < j ≤ n } , a cost array M M M is Monge if
M ( a , x ) + M ( b , y ) ≤ M ( a , y ) + M ( b , x ) (1) M(a,x)+M(b,y)\le M(a,y)+M(b,x) \tag*{(1)} M ( a , x ) + M ( b , y ) ≤ M ( a , y ) + M ( b , x ) (1)
for all rows a < b a<b a < b and columns x < y x<y x < y for which the four entries are defined, a condition that requires b < x b<x b < x on T n \mathcal{T}_n T n . A cell ( p , q ) (p,q) ( p , q ) is legal when all four entries of Δ C p , q \Delta C_{p,q} Δ C p , q belong to the domain, which on T n \mathcal{T}_n T n means p ≥ 0 p\ge0 p ≥ 0 , p + 1 < q p+1<q p + 1 < q and q + 1 ≤ n q+1\le n q + 1 ≤ n . Summing these differences over a rectangle gives
∑ p = a b − 1 ∑ q = x y − 1 Δ C p , q = C ( b , x ) + C ( a , y ) − C ( a , x ) − C ( b , y ) , (2) \sum_{p=a}^{b-1}\sum_{q=x}^{y-1}\Delta C_{p,q}=C(b,x)+C(a,y)-C(a,x)-C(b,y), \tag*{(2)} p = a ∑ b − 1 q = x ∑ y − 1 Δ C p , q = C ( b , x ) + C ( a , y ) − C ( a , x ) − C ( b , y ) , (2)
so C C C is Monge if and only if Δ C p , q ≥ 0 \Delta C_{p,q} \ge0 Δ C p , q ≥ 0 on every legal cell. Moreover, for arbitrary row and column potentials a k , b j a_k, b_j a k , b j ,
Δ ( C ( k , j ) + a k + b j ) p , q = Δ C p , q . (3) \Delta(C(k,j)+a_k+b_j)_{p,q}=\Delta C_{p,q}. \tag*{(3)} Δ ( C ( k , j ) + a k + b j ) p , q = Δ C p , q . (3)
We count exact arithmetic operations and comparisons at unit cost and charge T M T_M T M for an entry query to a supplied Monge background M M M . For polynomially bounded integer inputs and fixed-degree polynomial costs with polynomially bounded integer coefficients, the intermediate values fit in O ( log n ) O(\log n) O ( log n ) bits and the same bounds hold on the word RAM. The input representation determines the preprocessing. A scan of an explicit matrix finds the negative cells, a rectangle list supplies the row updates for a given Monge background, and a list of negative cells together with an oracle for the full cost supplies the data for constructing that background.
Matrix products and contiguous partitions
For finite n × n n\times n n × n matrices A , B A,B A , B indexed by [ 0 , n − 1 ] [0,n-1] [ 0 , n − 1 ] , their min-plus product is ( A ⊗ B ) i j = min 0 ≤ k < n { A i k + B k j } (A\otimes B)_{ij}=\min_{0\le k<n}\{A_{ik}+B_{kj}\} ( A ⊗ B ) ij = min 0 ≤ k < n { A ik + B k j } , and a witness is a minimizing index k k k . For contiguous partitioning of [ 1 , n ] [1,n] [ 1 , n ] , a partition is given by cut positions 0 = b 0 < b 1 < ⋯ < b K = n 0=b_0<b_1<\cdots<b_K=n 0 = b 0 < b 1 < ⋯ < b K = n with total cost ∑ i = 1 K C ( b i − 1 , b i ) \sum_{i=1}^{K}C(b_{i-1},b_i) ∑ i = 1 K C ( b i − 1 , b i ) . With an unrestricted number of blocks, the minimum cost D [ n ] D[n] D [ n ] satisfies
D [ 0 ] = 0 , D [ j ] = min 0 ≤ k < j { D [ k ] + C ( k , j ) } ( 1 ≤ j ≤ n ) , (4) D[0]=0,\qquad D[j]=\min_{0\le k<j}\{D[k]+C(k,j)\}\quad(1\le j\le n), \tag*{(4)} D [ 0 ] = 0 , D [ j ] = 0 ≤ k < j min { D [ k ] + C ( k , j )} ( 1 ≤ j ≤ n ) , (4)
with optimal cuts reconstructed from π [ j ] \pi[j] π [ j ] (breaking ties toward the smallest cut). With an exact block count K K K , the layered recurrence is
D b [ j ] = min 0 ≤ k < j { D b − 1 [ k ] + C ( k , j ) } ( 1 ≤ b ≤ K , 1 ≤ j ≤ n ) , (5) D_b[j]=\min_{0\le k<j}\{D_{b-1}[k]+C(k,j)\}\quad(1\le b\le K,\ 1\le j\le n), \tag*{(5)} D b [ j ] = 0 ≤ k < j min { D b − 1 [ k ] + C ( k , j )} ( 1 ≤ b ≤ K , 1 ≤ j ≤ n ) , (5)
initialized by D 0 [ 0 ] = 0 D_0[0]=0 D 0 [ 0 ] = 0 , D 0 [ j ] = + ∞ D_0[j]=+\infty D 0 [ j ] = + ∞ for j > 0 j>0 j > 0 , and D b [ 0 ] = + ∞ D_b[0]=+\infty D b [ 0 ] = + ∞ for b > 0 b>0 b > 0 .
The APSP exponent
The product lower bounds are expressed in terms of the deterministic exponent for APSP on polynomially bounded integer weights, for which truly subcubic algorithms are known [3 , 24 ] .
Definition 2.1 (APSP exponent and γ \gamma γ -APSP hypothesis). Let c A P S P c_{\mathrm{APSP}} c APSP be the infimum of the exponents c c c for which a deterministic algorithm solves APSP on n n n -vertex directed graphs with polynomially bounded integer weights in O ( n c ) O(n^c) O ( n c ) time, and for a constant γ ∈ ( 2 , 3 ] \gamma\in(2,3] γ ∈ ( 2 , 3 ] let the γ \gamma γ -APSP hypothesis assert c A P S P ≥ γ c_{\mathrm{APSP}}\ge\gamma c APSP ≥ γ . The output size gives c A P S P ≥ 2 c_{\mathrm{APSP}}\ge2 c APSP ≥ 2 , and the algorithm of Saha and Ye [24 ] gives c A P S P ≤ 2.9964 c_{\mathrm{APSP}}\le2.9964 c APSP ≤ 2.9964 .
The classical reductions between APSP and min-plus multiplication (see [27 ] ) preserve the exponent up to polylogarithmic factors in running time, so the deterministic exponent of min-plus multiplication for polynomially bounded integer n × n n\times n n × n matrices is also c A P S P c_{\mathrm{APSP}} c APSP .
Matrix products and recurrences with rectangle corrections
The sweep represents a cost array by a Monge background and a list of rectangles, processes the rectangle endpoints in column order, and maintains the minimum over active rows in a tree that supports interval additions and row activation (Appendix § 7 ).
Decomposition by negative mixed differences
Lemma 3.1 (Decomposition by negative differences). Let C C C be a finite rectangular or triangular cost array with negative support N ( C ) \mathcal{N}(C) N ( C ) . For each ( p , q ) ∈ N ( C ) (p,q) \in\mathcal{N}(C) ( p , q ) ∈ N ( C ) , define w p , q = − Δ C p , q > 0 w_{p,q}=-\Delta C_{p,q}>0 w p , q = − Δ C p , q > 0 , and set
R ( k , j ) = ∑ ( p , q ) ∈ N ( C ) w p , q 1 { k ≤ p } 1 { j > q } , M = C + R . (6) R(k,j)=\sum_{(p,q)\in\mathcal{N}(C)} w_{p,q}1\{k\le p\}1\{j>q\},\qquad M=C+R. \tag*{(6)} R ( k , j ) = ( p , q ) ∈ N ( C ) ∑ w p , q 1 { k ≤ p } 1 { j > q } , M = C + R . (6) Then Δ M p , q = max { Δ C p , q , 0 } \Delta M_{p,q}=\max\{\Delta C_{p,q},0\} Δ M p , q = max { Δ C p , q , 0 } at every legal cell, so M M M is Monge and C = M − R C=M-R C = M − R .
Proof. The indicator Q p , q ( k , j ) = 1 { k ≤ p } 1 { j > q } Q_{p,q}(k,j)=1\{k\le p\}1\{j>q\} Q p , q ( k , j ) = 1 { k ≤ p } 1 { j > q } has mixed difference 0 + 1 − 0 − 0 = 1 0+1-0-0=1 0 + 1 − 0 − 0 = 1 at ( p , q ) (p,q) ( p , q ) and zero at all other legal cells, so linearity gives Δ M p , q = Δ C p , q + ∑ ( p ′ , q ′ ) ∈ N ( C ) w p ′ , q ′ 1 { ( p ′ , q ′ ) = ( p , q ) } = max { Δ C p , q , 0 } \Delta M_{p,q}=\Delta C_{p,q}+\sum_{(p',q')\in\mathcal{N}(C)}w_{p',q'}1\{(p',q')=(p,q)\}=\max\{\Delta C_{p,q},0\} Δ M p , q = Δ C p , q + ∑ ( p ′ , q ′ ) ∈ N ( C ) w p ′ , q ′ 1 {( p ′ , q ′ ) = ( p , q )} = max { Δ C p , q , 0 } . On both domains the cells in each rectangle of (2) are legal, so their nonnegative sum proves the Monge inequality for M M M .
More generally, consider any cost array given in the signed-rectangle representation
C ( k , j ) = M ( k , j ) + ∑ ℓ = 1 r α ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } . (7) C(k,j)=M(k,j)+\sum_{\ell=1}^{r}\alpha_\ell1\{k\in I_\ell\}1\{j\in J_\ell\}. \tag*{(7)} C ( k , j ) = M ( k , j ) + ℓ = 1 ∑ r α ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } . (7)
where M M M is Monge, I ℓ I_\ell I ℓ and J ℓ J_\ell J ℓ are integer intervals, and α ℓ ∈ R \alpha_\ell\in\mathbb{R} α ℓ ∈ R may have either sign. During a left-to-right column sweep j j j , a rectangle with J ℓ = [ a ℓ , b ℓ ] J_\ell=[a_\ell,b_\ell] J ℓ = [ a ℓ , b ℓ ] generates an entry event ( I ℓ , + α ℓ ) (I_\ell,+\alpha_\ell) ( I ℓ , + α ℓ ) at column a ℓ a_\ell a ℓ and an exit event ( I ℓ , − α ℓ ) (I_\ell,-\alpha_\ell) ( I ℓ , − α ℓ ) at column b ℓ + 1 b_\ell+1 b ℓ + 1 (if b ℓ + 1 b_\ell+1 b ℓ + 1 lies in the column domain). Bucketing these at most 2 r 2r 2 r events takes O ( n + r ) O(n+r) O ( n + r ) time and space. Lemma 3.1 corresponds to r = s ( C ) r=s(C) r = s ( C ) prefix rectangles [ 0 , p ] × [ q + 1 , ν ] [0,p]\times[q+1,\nu] [ 0 , p ] × [ q + 1 , ν ] with weights − w p , q -w_{p,q} − w p , q .
Lower envelopes of active rows
At sweep column j j j , an active row k k k with effective potential v k v_k v k defines the cost function f k ( x ) = v k + M ( k , x ) f_k(x)=v_k+M(k,x) f k ( x ) = v k + M ( k , x ) for j ≤ x ≤ ν j\le x\le\nu j ≤ x ≤ ν , where the last column is ν = n − 1 \nu=n-1 ν = n − 1 for a square matrix and ν = n \nu=n ν = n for a triangular recurrence.
Lemma 3.2 (Lower envelopes of ordered row sets). For nonempty sets A A A , B B B of active rows with a < b a<b a < b for every a ∈ A a\in A a ∈ A and b ∈ B b\in B b ∈ B , let F A ( x ) = min a ∈ A f a ( x ) F_A(x)=\min_{a\in A}f_a(x) F A ( x ) = min a ∈ A f a ( x ) and F B ( x ) = min b ∈ B f b ( x ) F_B(x)=\min_{b\in B}f_b(x) F B ( x ) = min b ∈ B f b ( x ) . Their difference F A ( x ) − F B ( x ) F_A(x)-F_B(x) F A ( x ) − F B ( x ) is nondecreasing on [ j , ν ] [j,\nu] [ j , ν ] , so the set of columns on which F B ( x ) < F A ( x ) F_B(x)<F_A(x) F B ( x ) < F A ( x ) is a suffix of this interval.
Proof. For j ≤ x < y ≤ ν j\le x<y\le\nu j ≤ x < y ≤ ν , choose a ∈ A a\in A a ∈ A attaining F A ( y ) F_A(y) F A ( y ) and b ∈ B b\in B b ∈ B attaining F B ( x ) F_B(x) F B ( x ) . The four entries lie in the domain, with a < b < j ≤ x < y a<b<j\le x<y a < b < j ≤ x < y in the triangular case, so the Monge inequality (1) gives f a ( y ) − f b ( y ) ≥ f a ( x ) − f b ( x ) f_a(y)-f_b(y)\ge f_a(x)-f_b(x) f a ( y ) − f b ( y ) ≥ f a ( x ) − f b ( x ) and therefore
F A ( y ) − F B ( y ) ≥ f a ( y ) − f b ( y ) ≥ f a ( x ) − f b ( x ) ≥ F A ( x ) − F B ( x ) . F_A(y)-F_B(y)\ge f_a(y)-f_b(y)\ge f_a(x)-f_b(x)\ge F_A(x)-F_B(x). F A ( y ) − F B ( y ) ≥ f a ( y ) − f b ( y ) ≥ f a ( x ) − f b ( x ) ≥ F A ( x ) − F B ( x ) .
Each node u u u of the balanced binary tree T T T on the row indices [ 0 , n − 1 ] [0,n-1] [ 0 , n − 1 ] stores its row interval K ( u ) K(u) K ( u ) and its number of active leaves, and each internal node stores a lazy uniform addition z u z_u z u and a switch column θ u \theta_u θ u . At column j j j , rebuilding a switch sets θ u \theta_u θ u to the first x ∈ [ j , ν ] x\in[j,\nu] x ∈ [ j , ν ] where the right child’s envelope is strictly smaller, with θ u = j \theta_u=j θ u = j when only the right child is nonempty and θ u = ν + 1 \theta_u=\nu+1 θ u = ν + 1 when the right child is empty or never strictly smaller. A tie goes to the left child, giving the smallest minimizing row index, and a switch recorded at an earlier step remains valid on the smaller domain of future columns, where a switch below j j j sends every query to the right child.
Lemma 3.3 (Operations on the envelope tree). The tree T T T takes O ( n ) O(n) O ( n ) space and O ( n ) O(n) O ( n ) time to initialize and supports the following operations at sweep column j j j .
EVAL ( T . r o o t , x ) (T.\mathrm{root},x) ( T . root , x ) (x ≥ j x\ge j x ≥ j ) returns min k a c t i v e { v k + M ( k , x ) } \min_{k\ active}\{v_k+M(k,x)\} min k a c t i v e { v k + M ( k , x )} and its smallest minimizing row in O ( L + T M ) O(L+T_M) O ( L + T M ) time.
ADD(T . r o o t , I , β , j T.\mathrm{root}, I, \beta, j T . root , I , β , j ) adds β \beta β to all active rows in I I I in O ( L 2 ( L + T M ) ) O(L^2(L + T_M)) O ( L 2 ( L + T M )) time.
ACTIVATE(T . r o o t , k , v , j T.\mathrm{root}, k, v, j T . root , k , v , j ) activates leaf k k k with potential v v v in O ( L 2 ( L + T M ) ) O(L^2(L + T_M)) O ( L 2 ( L + T M )) time.
Querying the minimum at x ≥ j x \ge j x ≥ j restricted to active rows in a contiguous interval F j F_j F j takes O ( L ( L + T M ) ) O(L(L + T_M)) O ( L ( L + T M )) time.
Proof. An evaluation follows one root-to-leaf path according to x < θ u x < \theta_u x < θ u , adds the lazy tags on that path, and queries M ( k , x ) M(k,x) M ( k , x ) once at the leaf, for a total cost of O ( L + T M ) O(L + T_M) O ( L + T M ) . By Lemma 3.2 , PULL( u , j ) (u,j) ( u , j ) finds the switch by binary search with endpoint ν + 1 \nu+ 1 ν + 1 , using O ( L ) O(L) O ( L ) evaluations in O ( L ( L + T M ) ) O(L(L + T_M)) O ( L ( L + T M )) time. For ADD( I , β ) (I,\beta) ( I , β ) , a fully covered active leaf receives β \beta β directly and a fully covered nonempty internal node adds β \beta β to its lazy tag, which shifts both child envelopes equally and preserves their switches. Rebuilding the switches of the O ( L ) O(L) O ( L ) partially covered ancestors takes O ( L 2 ( L + T M ) ) O(L^2(L + T_M)) O ( L 2 ( L + T M )) time, as does activating a leaf and rebuilding its ancestors (Algorithms 1 and 2).
For a query restricted to F j F_j F j , the descent partitions F j F_j F j into O ( L ) O(L) O ( L ) canonical subtrees and carries the sum of the lazy tags of their strict ancestors, so adding this sum to each subtree’s evaluation and taking the lexicographically smallest pair of value and row index takes O ( L ( L + T M ) ) O(L(L + T_M)) O ( L ( L + T M )) time. A query with no active row in F j F_j F j returns ( + ∞ , − 1 ) (+\infty,-1) ( + ∞ , − 1 ) .
Vector and matrix products
When the row potentials x 0 , … , x n − 1 x_0,\ldots,x_{n-1} x 0 , … , x n − 1 are available at column 0 0 0 , the algorithm activates all leaves together and computes the switches from the leaves to the root.
Theorem 3.4 (Vector products with rectangle corrections). Given a constant-time Monge oracle M M M and r r r signed rectangles defining an n × n n \times n n × n matrix C C C by (7) , the sweep groups events by column in O ( n + r ) O(n+r) O ( n + r ) time and space, after which it computes x ⊗ C x \otimes C x ⊗ C and the smallest minimizing index for each coordinate of any finite x ∈ R n x \in\mathbb{R}^n x ∈ R n in O ( n L + r L 3 ) O(nL+rL^3) O ( n L + r L 3 ) time and O ( n + r ) O(n+r) O ( n + r ) working space.
Proof. Algorithm 3 installs x k x_k x k at leaf k k k and runs PULL( u , 0 ) (u,0) ( u , 0 ) from the leaves to the root, spending O ( ( h + 1 ) L ) O((h+1)L) O (( h + 1 ) L ) time at a node of height h h h and O ( n L ∑ h ≥ 0 ( h + 1 ) / 2 h ) = O ( n L ) O\left(nL\sum_{h\ge0}(h+1)/2^h\right)=O(nL) O ( n L ∑ h ≥ 0 ( h + 1 ) / 2 h ) = O ( n L ) time over the tree. At each column j = 0 , … , n − 1 j=0,\ldots,n-1 j = 0 , … , n − 1 , the algorithm applies the events in bucket j j j using ADD, which gives row k k k the potential x k + ∑ ℓ = 1 r α ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } x_k+\sum_{\ell=1}^{r}\alpha_\ell1\{k\in I_\ell\}1\{j\in J_\ell\} x k + ∑ ℓ = 1 r α ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } , so EVAL( T . r o o t , j ) (T.\mathrm{root},j) ( T . root , j ) returns ( x ⊗ C ) j (x\otimes C)_j ( x ⊗ C ) j and its smallest witness. The sweep makes at most 2 r 2r 2 r updates in O ( r L 3 ) O(rL^3) O ( r L 3 ) time and n n n queries in O ( n L ) O(nL) O ( n L ) time.
Theorem 3.5 (Matrix products with sparse negative differences). For explicit finite n × n n \times n n × n matrices A A A , B B B with arbitrary A A A and s = s ( B ) s=s(B) s = s ( B ) , the product A ⊗ B A\otimes B A ⊗ B and the smallest minimizing index for each entry can be computed in O ( n 2 L + n s L 3 ) O(n^2L+nsL^3) O ( n 2 L + n s L 3 ) time and O ( n 2 ) O(n^2) O ( n 2 ) space, giving O ( n 2 L 3 ) O(n^2L^3) O ( n 2 L 3 ) time when s = O ( n ) s=O(n) s = O ( n ) for any number of positive differences up to Θ ( n 2 ) \Theta(n^2) Θ ( n 2 ) .
Proof. A scan of Δ B \Delta B Δ B identifies the s s s cells in N ( B ) \mathcal{N}(B) N ( B ) , and two-dimensional prefix sums construct R ( k , j ) = ∑ ( p , q ) ∈ N ( B ) ( − Δ B p , q ) 1 { k ≤ p } 1 { j > q } R(k,j)=\sum_{(p,q)\in\mathcal{N}(B)}(-\Delta B_{p,q})1\{k\le p\}1\{j>q\} R ( k , j ) = ∑ ( p , q ) ∈ N ( B ) ( − Δ B p , q ) 1 { k ≤ p } 1 { j > q } in O ( n 2 ) O(n^2) O ( n 2 ) time. By Lemma 3.1 , M = B + R M=B+R M = B + R is Monge and the representation B = M − R B=M-R B = M − R gives one event ( [ 0 , p ] , Δ B p , q ) ([0,p],\Delta B_{p,q}) ([ 0 , p ] , Δ B p , q ) at column q + 1 q+1 q + 1 for each negative cell, so Theorem 3.4 computes the product row and its witnesses for x = A i , ∗ x=A_{i,*} x = A i , ∗ in O ( n L + s L 3 ) O(nL+sL^3) O ( n L + s L 3 ) time, reusing the O ( n ) O(n) O ( n ) tree storage across rows (Algorithm 12). For ∣ B k j ∣ ≤ U |B_{k j}|\le U ∣ B k j ∣ ≤ U , the bound 0 ≤ R ( k , j ) ≤ 4 ( n − 1 ) 2 U 0\le R(k,j)\le4(n-1)^2U 0 ≤ R ( k , j ) ≤ 4 ( n − 1 ) 2 U gives word-sized background entries on polynomially bounded integer inputs.
Adaptive queries with a fixed right factor. For a fixed explicit B B B , the O ( n 2 ) O(n^2) O ( n 2 ) preprocessing constructs the background and event buckets once, so a batch of h h h finite vectors, each of which may depend on the answers to previous queries, takes
O ( n 2 + h ( n L + s ( B ) L 3 ) ) O\left(n^2+h\left(nL+s(B)L^3\right)\right) O ( n 2 + h ( n L + s ( B ) L 3 ) )
total time, since each query initializes its own envelope tree and returns the smallest minimizing index for every output coordinate. Processing the queries in sequence uses O ( n 2 ) O(n^2) O ( n 2 ) working space, and writing the output takes Ω ( n ) \Omega(n) Ω ( n ) time for a vector and Ω ( n 2 ) \Omega(n^2) Ω ( n 2 ) for a matrix product. Corollary 5.6 bounds the amortized query time for quadratic preprocessing.
Sequential partitioning
In recurrence (4) , row k k k becomes active at column k + 1 k+1 k + 1 with the newly computed prefix value D [ k ] D[k] D [ k ] , and its initial potential must include the weights of rectangles already covering that row. At column j j j the envelope tree applies each interval addition to the previously considered rows in [ 0 , j − 2 ] [0,j-2] [ 0 , j − 2 ] , and a Fenwick tree H H H over a difference array on [ 0 , n − 1 ] [0,n-1] [ 0 , n − 1 ] records the sum for every row,
H j ( k ) = ∑ ℓ = 1 r α ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } . H_j(k)=\sum_{\ell=1}^{r}\alpha_\ell1\{k\in I_\ell\}1\{j\in J_\ell\}. H j ( k ) = ℓ = 1 ∑ r α ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } .
Each event ( I , β ) (I,\beta) ( I , β ) updates H H H in O ( L ) O(L) O ( L ) time, and querying H j ( k ) H_j(k) H j ( k ) takes O ( L ) O(L) O ( L ) time.
Theorem 3.6 (Sequential partitioning with rectangle corrections). Given (7) on T n \mathcal{T}_n T n with background query time T M T_M T M , the recurrence (4) and an optimal partition can be computed in O ( ( n + r ) L 2 ( L + T M ) ) O((n+r)L^2(L+T_M)) O (( n + r ) L 2 ( L + T M )) time and O ( n + r ) O(n+r) O ( n + r ) working space (excluding background oracle storage). The same bounds hold when each state j j j restricts its predecessors to a supplied interval F j ⊆ [ 0 , j − 1 ] F_j\subseteq[0,j-1] F j ⊆ [ 0 , j − 1 ] .
Proof. Immediately before the query at column j j j , the active leaves are the reachable states k < j k<j k < j and row k k k has effective potential D [ k ] + H j ( k ) D[k]+H_j(k) D [ k ] + H j ( k ) . Processing bucket j j j updates H j − 1 H_{j-1} H j − 1 to H j H_j H j and applies ADD ( T . r o o t , I ∩ [ 0 , j − 2 ] , β , j ) \operatorname{ADD}(T.\mathrm{root},I\cap[0,j-2],\beta,j) ADD ( T . root , I ∩ [ 0 , j − 2 ] , β , j ) to the active part of each affected interval, after which a finite D [ j − 1 ] D[j-1] D [ j − 1 ] activates row j − 1 j-1 j − 1 with potential D [ j − 1 ] + H j ( j − 1 ) D[j-1]+H_j(j-1) D [ j − 1 ] + H j ( j − 1 ) . The minimum over F j F_j F j therefore equals min k ∈ F j { D [ k ] + H j ( k ) + M ( k , j ) } = min k ∈ F j { D [ k ] + C ( k , j ) } \min_{k\in F_j}\{D[k]+H_j(k)+M(k,j)\}=\min_{k\in F_j}\{D[k]+C(k,j)\} min k ∈ F j { D [ k ] + H j ( k ) + M ( k , j )} = min k ∈ F j { D [ k ] + C ( k , j )} , which proves the recurrence by induction. By Lemma 3.3 , the at most 2 r 2r 2 r events, n n n activations and n n n queries take O ( ( n + r ) L 2 ( L + T M ) ) O((n+r)L^2(L+T_M)) O (( n + r ) L 2 ( L + T M )) time (Algorithm 4), and the stored predecessors reconstruct an optimal partition whenever the final value is finite, with + ∞ +\infty + ∞ denoting infeasibility.
Corollary 3.7 (Sequential partitioning from a list of negative differences). Given constant-time access to C C C on T n \mathcal{T}_n T n and the complete list of its s s s negative legal adjacent differences, (4) can be solved in O ( ( n + s ) L 3 ) O((n+s)L^3) O (( n + s ) L 3 ) time and O ( n + s L ) O(n+sL) O ( n + s L ) additional space.
Proof. Grouping negative cells by q q q gives a persistent segment tree on row gaps [ 0 , n − 1 ] [0,n-1] [ 0 , n − 1 ] whose version V j V_j V j stores the weights w p , q = − Δ C p , q w_{p,q}=-\Delta C_{p,q} w p , q = − Δ C p , q for q < j q<j q < j , so M ( k , j ) = C ( k , j ) + SuffixSum ( V j , k ) M(k,j)=C(k,j)+\operatorname{SuffixSum}(V_j,k) M ( k , j ) = C ( k , j ) + SuffixSum ( V j , k ) takes O ( L ) O(L) O ( L ) time per query after O ( n + s L ) O(n+sL) O ( n + s L ) construction time and space (Algorithm 6). Applying Theorem 3.6 with r = s r=s r = s gives the stated O ( ( n + s ) L 3 ) O((n+s)L^3) O (( n + s ) L 3 ) bound, and an explicit triangular array can supply the negative list by an initial O ( n 2 ) O(n^2) O ( n 2 ) scan.
Corollary 3.8 (Partitions into K K K blocks). The layered recurrence (5) for exactly K K K blocks can be solved in O ( K ( n + r ) L 2 ( L + T M ) ) O(K(n+r)L^2(L+T_M)) O ( K ( n + r ) L 2 ( L + T M )) time using O ( n + r ) O(n+r) O ( n + r ) working space with rolling arrays, plus O ( K n ) O(Kn) O ( K n ) space if all predecessor pointers are retained for reconstruction.
Applications
For convex state transitions the input specifies the row and column coordinates and a list of interval adjustments, and for contiguous partitions it specifies vertex masses and the edges or hyperedges rewarded inside each block. In both cases these data give the Monge background and the rectangle events directly.
Convex transition costs
For nondecreasing coordinates x 0 ≤ ⋯ ≤ x n − 1 x_0 \le\cdots\le x_{n-1} x 0 ≤ ⋯ ≤ x n − 1 and y 0 ≤ ⋯ ≤ y n − 1 y_0 \le\cdots\le y_{n-1} y 0 ≤ ⋯ ≤ y n − 1 and a convex function ϕ : R → R \phi: \mathbb{R} \to\mathbb{R} ϕ : R → R evaluable in constant time, the transition matrix with r r r interval surcharges or discounts has entries
B k j = ϕ ( y j − x k ) + ∑ ℓ = 1 r α ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } . (8) B_{kj} = \phi(y_j - x_k) + \sum_{\ell=1}^{r} \alpha_\ell1\{k \in I_\ell\}1\{j \in J_\ell\}. \tag*{(8)} B k j = ϕ ( y j − x k ) + ℓ = 1 ∑ r α ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } . (8)
Lemma 4.1 (Mixed differences of a rectangle). In (8) , the background M ( k , j ) = ϕ ( y j − x k ) M(k,j) = \phi(y_j - x_k) M ( k , j ) = ϕ ( y j − x k ) is Monge and each signed rectangle contributes at most four nonzero adjacent mixed differences, at most two of which are negative, so s ( B ) ≤ 2 r s(B) \le2r s ( B ) ≤ 2 r .
Proof. For p ∈ [ 0 , n − 2 ] p \in[0,n-2] p ∈ [ 0 , n − 2 ] and q ∈ [ 0 , n − 2 ] q \in[0,n-2] q ∈ [ 0 , n − 2 ] , put z = y q − x p + 1 z = y_q - x_{p+1} z = y q − x p + 1 , u = x p + 1 − x p ≥ 0 u = x_{p+1} - x_p \ge0 u = x p + 1 − x p ≥ 0 , and v = y q + 1 − y q ≥ 0 v = y_{q+1} - y_q \ge0 v = y q + 1 − y q ≥ 0 . Convexity implies that increments ϕ ( t + u ) − ϕ ( t ) \phi(t+u) - \phi(t) ϕ ( t + u ) − ϕ ( t ) are nondecreasing in t t t , so
Δ M p , q = ϕ ( z ) + ϕ ( z + u + v ) − ϕ ( z + u ) − ϕ ( z + v ) ≥ 0. \Delta M_{p,q} = \phi(z) + \phi(z+u+v) - \phi(z+u) - \phi(z+v) \ge0. Δ M p , q = ϕ ( z ) + ϕ ( z + u + v ) − ϕ ( z + u ) − ϕ ( z + v ) ≥ 0. For a single rectangle α 1 { k ∈ I } 1 { j ∈ J } \alpha1\{k \in I\}1\{j \in J\} α 1 { k ∈ I } 1 { j ∈ J } , writing a k = 1 { k ∈ I } a_k = 1\{k \in I\} a k = 1 { k ∈ I } and b j = 1 { j ∈ J } b_j = 1\{j \in J\} b j = 1 { j ∈ J } gives
Δ ( α a k b j ) p , q = − α ( a p + 1 − a p ) ( b q + 1 − b q ) , \Delta(\alpha a_k b_j)_{p,q} = -\alpha(a_{p+1} - a_p)(b_{q+1} - b_q), Δ ( α a k b j ) p , q = − α ( a p + 1 − a p ) ( b q + 1 − b q ) , which can be nonzero only at the four corner gaps where both indicators change, with at most two negative entries because the signs alternate, so the union of the negative cells of the r r r rectangles has size at most 2 r 2r 2 r and contains every negative cell of B B B .
For ϕ ( z ) = z 2 \phi(z) = z^2 ϕ ( z ) = z 2 the background difference is 2 ( x p + 1 − x p ) ( y q + 1 − y q ) 2(x_{p+1} - x_p)(y_{q+1} - y_q) 2 ( x p + 1 − x p ) ( y q + 1 − y q ) , so with strictly increasing coordinates at least ( n − 1 ) 2 − 4 r (n-1)^2 - 4r ( n − 1 ) 2 − 4 r positive differences remain after the r r r rectangles modify at most 4 r 4r 4 r cells.
Corollary 4.2 (Vector products and layered recurrences). Let B B B be given by the coordinates, the constant-time oracle for ϕ \phi ϕ , and the r r r rectangle rules in (8) .
After O ( n + r ) O(n+r) O ( n + r ) preprocessing, the algorithm computes v ⊗ B v \otimes B v ⊗ B and its witnesses for any finite vector v v v in O ( n L + r L 3 ) O(nL+rL^3) O ( n L + r L 3 ) time and O ( n + r ) O(n+r) O ( n + r ) space, and using the same rules for every row of A A A computes A ⊗ B A \otimes B A ⊗ B in O ( n 2 L + n r L 3 ) O(n^2L+nrL^3) O ( n 2 L + n r L 3 ) time.
For an ℓ \ell ℓ -layer chain d t ( j ) = u t ( j ) + min k { d t − 1 ( k ) + ( B t ) k j } d_t(j) = u_t(j) + \min_k\{d_{t-1}(k) + (B_t)_{kj}\} d t ( j ) = u t ( j ) + min k { d t − 1 ( k ) + ( B t ) k j } with arbitrary finite unary costs u t ( j ) u_t(j) u t ( j ) and r t r_t r t rules at layer t t t , computing d ℓ d_\ell d ℓ and an optimal path takes O ( ℓ n L + L 3 ∑ t = 1 ℓ r t ) O(\ell nL + L^3 \sum_{t=1}^{\ell} r_t) O ( ℓ n L + L 3 ∑ t = 1 ℓ r t ) time.
One chain uses O ( n + max t r t ) O(n+\max_t r_t) O ( n + max t r t ) working space beyond the supplied layers, with another O ( ℓ n ) O(\ell n) O ( ℓ n ) space for all predecessors if a path is to be recovered in O ( ℓ ) O(\ell) O ( ℓ ) time. Applying the transfer to each of n n n initial vectors gives all source-to-terminal costs in O ( ℓ n 2 L + n L 3 ∑ t r t ) O(\ell n^2L+nL^3\sum_t r_t) O ( ℓ n 2 L + n L 3 ∑ t r t ) time from the same rules.
Toeplitz costs and alignment grids. For B k j = g ( j − k ) B_{kj} = g(j-k) B k j = g ( j − k ) , the mixed difference at ( p , q ) (p,q) ( p , q ) is g ( z − 1 ) + g ( z + 1 ) − 2 g ( z ) g(z-1) + g(z+1) - 2g(z) g ( z − 1 ) + g ( z + 1 ) − 2 g ( z ) with z = q − p z = q-p z = q − p , so each of the t t t negative second differences of g g g contributes a diagonal of at most n − 1 n-1 n − 1 cells and s ( B ) ≤ ( n − 1 ) t s(B) \le(n-1)t s ( B ) ≤ ( n − 1 ) t . Splitting g g g into at most t + 1 t+1 t + 1 convex pieces and taking the componentwise minimum of their convolutions [5 ] gives O ( n ( t + 1 ) ) O(n(t+1)) O ( n ( t + 1 )) time per vector and O ( n 2 ( t + 1 ) ) O(n^2(t+1)) O ( n 2 ( t + 1 )) time for a matrix product, while (8) allows arbitrary nondecreasing coordinates and separately specified row and column intervals.
For an m × n m \times n m × n alignment grid with longest common subsequence scores and b > 1 b > 1 b > 1 positively weighted bridges, Carmel, Tsur, and Ziv-Ukelson [6 ] construct a finite all-scores matrix in O ( b ( n m + n 2 ) ) O(b(nm+n^2)) O ( b ( nm + n 2 )) time by assigning score j − i j-i j − i when i > j i > j i > j . This completion has O ( n ( b + 1 ) ) O(n(b+1)) O ( n ( b + 1 )) nonzero density entries, so negating its scores and applying Theorem 3.5 takes a further O ~ ( n 2 ( b + 1 ) ) \widetilde{O}(n^2(b+1)) O ( n 2 ( b + 1 )) time.
Contiguous partitions with convex costs and internal rewards
Let a 1 , … , a n ≥ 0 a_1,\ldots,a_n \ge0 a 1 , … , a n ≥ 0 be vertex masses with prefix sums S j = ∑ i = 1 j a i S_j=\sum_{i=1}^j a_i S j = ∑ i = 1 j a i (S 0 = 0 S_0=0 S 0 = 0 ), let ϕ : R ≥ 0 → R \phi:\mathbb{R}_{\ge0}\to\mathbb{R} ϕ : R ≥ 0 → R be a convex load penalty evaluable in T ϕ T_\phi T ϕ time, and let E \mathcal{E} E be a list of h h h nonempty interactions (edges or hyperedges) e ⊆ [ 1 , n ] e\subseteq[1,n] e ⊆ [ 1 , n ] with weights w e ≥ 0 w_e\ge0 w e ≥ 0 and total incidence size N = ∑ e ∈ E ∣ e ∣ N=\sum_{e\in\mathcal{E}}|e| N = ∑ e ∈ E ∣ e ∣ . Consider the contiguous block cost
C ( k , j ) = ϕ ( S j − S k ) − ∑ e ⊆ ( k , j ] w e . (9) C(k,j)=\phi(S_j-S_k)-\sum_{e\subseteq(k,j]}w_e. \tag*{(9)} C ( k , j ) = ϕ ( S j − S k ) − e ⊆ ( k , j ] ∑ w e . (9)
Lemma 4.3 (The rectangle for an internal reward). In (9), the background M ( k , j ) = ϕ ( S j − S k ) M(k,j)=\phi(S_j-S_k) M ( k , j ) = ϕ ( S j − S k ) is Monge and each interaction e ∈ E e\in\mathcal{E} e ∈ E contributes the rectangle [ 0 , min e − 1 ] × [ max e , n ] [0,\min e-1]\times[\max e,n] [ 0 , min e − 1 ] × [ max e , n ] with weight − w e -w_e − w e , giving s ( C ) ≤ h s(C)\le h s ( C ) ≤ h .
Proof. For 0 ≤ a < b < x < y ≤ n 0\le a<b<x<y\le n 0 ≤ a < b < x < y ≤ n , set z = S x − S b ≥ 0 z=S_x-S_b\ge0 z = S x − S b ≥ 0 , u = S b − S a ≥ 0 u=S_b-S_a\ge0 u = S b − S a ≥ 0 and v = S y − S x ≥ 0 v=S_y-S_x\ge0 v = S y − S x ≥ 0 , so convexity gives ϕ ( z + u ) + ϕ ( z + v ) ≤ ϕ ( z ) + ϕ ( z + u + v ) \phi(z+u)+\phi(z+v)\le\phi(z)+\phi(z+u+v) ϕ ( z + u ) + ϕ ( z + v ) ≤ ϕ ( z ) + ϕ ( z + u + v ) and hence the Monge inequality for M M M . An interaction satisfies e ⊆ ( k , j ] e\subseteq(k,j] e ⊆ ( k , j ] precisely when k < min e k<\min e k < min e and j ≥ max e j\ge\max e j ≥ max e , which gives the stated rectangle, whose mixed difference is supported at ( min e − 1 , max e − 1 ) (\min e-1,\max e-1) ( min e − 1 , max e − 1 ) if that cell is legal. Since the background has nonnegative differences, the negative support lies among these at most h h h cells.
Theorem 4.4 (Contiguous partitions with internal rewards). An optimal contiguous partition for (9) can be computed in O ( N + n + ( n + h ) L 2 ( L + T ϕ ) ) O(N+n+(n+h)L^2(L+T_\phi)) O ( N + n + ( n + h ) L 2 ( L + T ϕ )) time and O ( n + h ) O(n+h) O ( n + h ) working space beyond the incidence input, and an optimal partition with exactly K K K blocks takes O ( N + n + K ( n + h ) L 2 ( L + T ϕ ) ) O(N+n+K(n+h)L^2(L+T_\phi)) O ( N + n + K ( n + h ) L 2 ( L + T ϕ )) time. For T ϕ = O ( 1 ) T_\phi=O(1) T ϕ = O ( 1 ) the respective time bounds are O ( N + ( n + h ) L 3 ) O(N+(n+h)L^3) O ( N + ( n + h ) L 3 ) and O ( N + K ( n + h ) L 3 ) O(N+K(n+h)L^3) O ( N + K ( n + h ) L 3 ) .
Proof. Computing S j S_j S j and all endpoint pairs ( min e , max e ) (\min e,\max e) ( min e , max e ) takes O ( N + n ) O(N+n) O ( N + n ) time. Lemma 4.3 supplies a Monge oracle with T M = T ϕ T_M=T_\phi T M = T ϕ and h h h rectangles, so Theorem 3.6 and Corollary 3.8 apply directly (Algorithm 8).
A direct dynamic program groups interactions by their right endpoint and, at column j j j , adds the weights of the new interactions at their left endpoints before scanning the cuts backward to compute the internal rewards by suffix sums. This takes O ( N + n 2 T ϕ ) O(N+n^2T_\phi) O ( N + n 2 T ϕ ) time over all columns, or O ( N + K n 2 ) O(N+Kn^2) O ( N + K n 2 ) time for K K K layers if the penalty takes constant time and the block costs are stored once. A fixed charge per block amounts to adding a constant to ϕ \phi ϕ .
Table 3 gives the running times for the following objectives, whose block costs are derived in Appendix § 8 .
Table 3. Running times for contiguous partitions in a fixed vertex order, with m m m graph edges, h h h hyperedges of total incidence size N N N , and q q q listed pairs. The strict modularity bound assumes bounded rank, and FENNEL uses a constant-time exact penalty oracle.
Ordered and cyclic graph modularity. For a loopless undirected graph with nonnegative edge weights and total weight W > 0 W>0 W > 0 , scaling modularity by − 4 W 2 -4W^2 − 4 W 2 gives C ( k , j ) = ( S j − S k ) 2 − 4 W E ( ( k , j ] ) C(k,j)=(S_j-S_k)^2-4W E((k,j]) C ( k , j ) = ( S j − S k ) 2 − 4 W E (( k , j ]) with vertex masses a i = d i a_i=d_i a i = d i and rewards w e = 4 W b e w_e=4Wb_e w e = 4 W b e [20 , 21 ] . If b u v b_{uv} b uv is the total weight of edges between u , v u,v u , v (zero for a missing pair), every legal cell satisfies
Δ C p , q = 2 d p + 1 d q + 1 − 4 W b p + 1 , q + 1 . \Delta C_{p,q}=2d_{p+1}d_{q+1}-4Wb_{p+1,q+1}. Δ C p , q = 2 d p + 1 d q + 1 − 4 W b p + 1 , q + 1 .
Thus s ( C ) ≤ m s(C)\le m s ( C ) ≤ m , and the m m m edge records supply the events for a sweep taking O ( ( n + m ) L 3 ) O((n+m)L^3) O (( n + m ) L 3 ) time in a linear order or O ( n ( n + m ) L 3 ) O(n(n+m)L^3) O ( n ( n + m ) L 3 ) time over the n n n possible starting cuts of a cyclic order (Algorithm 9).
Weighted cluster editing. With uniform insertion price η > 0 \eta>0 η > 0 for missing pairs and deletion price b e ≥ 0 b_e\ge0 b e ≥ 0 for edge e e e , the cost is ∑ e b e + ∑ I ∈ P [ η ( ∣ I ∣ 2 ) − ∑ e ⊂ I ( η + b e ) ] \sum_e b_e+\sum_{I\in\mathcal P}[\eta\binom{|I|}{2}-\sum_{e\subset I}(\eta+b_e)] ∑ e b e + ∑ I ∈ P [ η ( 2 ∣ I ∣ ) − ∑ e ⊂ I ( η + b e )] , so the algorithm runs in O ( ( n + m ) L 3 ) O((n+m)L^3) O (( n + m ) L 3 ) time for all ratios b e / η b_e/\eta b e / η , including the unweighted LambdaCC objective [29 ] with η = λ \eta=\lambda η = λ and b e = 1 − λ b_e=1-\lambda b e = 1 − λ for 0 < λ ≤ 1 0<\lambda\le1 0 < λ ≤ 1 .
Hypergraph clustering. For all-or-nothing HyperLam [30 ] with vertex weights μ i ≥ 0 \mu_i\ge0 μ i ≥ 0 and resolution λ ≥ 0 \lambda\ge0 λ ≥ 0 , the cost C ( k , j ) = λ 2 ( S j − S k ) 2 − # { e ⊆ ( k , j ] } C(k,j)=\frac{\lambda}{2}(S_j-S_k)^2-\#\{e\subseteq(k,j]\} C ( k , j ) = 2 λ ( S j − S k ) 2 − # { e ⊆ ( k , j ]} gives O ( ( N + ( n + h ) L 3 ) O((N+(n+h)L^3) O (( N + ( n + h ) L 3 ) time for arbitrary hyperedge ranks. For strict hypergraph modularity [16 ] with h ρ h_\rho h ρ edges of rank ρ \rho ρ , the penalty is ϕ ( x ) = ∑ ρ ≥ 1 h ρ ( x / N ) ρ \phi(x)=\sum_{\rho\ge1}h_\rho(x/N)^\rho ϕ ( x ) = ∑ ρ ≥ 1 h ρ ( x / N ) ρ , which reduces to h ( x / N ) ρ h(x/N)^\rho h ( x / N ) ρ on a ρ \rho ρ -uniform hypergraph. Horner evaluation takes constant time for bounded maximum rank, giving the same O ( ( N + ( n + h ) L 3 ) O((N+(n+h)L^3) O (( N + ( n + h ) L 3 ) bound, and for unrestricted rank the running time is O ( N + ( n + h ) L 2 ( L + T ϕ ) ) O(N+(n+h)L^2(L+T_\phi)) O ( N + ( n + h ) L 2 ( L + T ϕ )) with T ϕ T_\phi T ϕ denoting the exact evaluation time of the polynomial.
FENNEL with K K K blocks. For β ≥ 0 \beta\ge0 β ≥ 0 and γ ≥ 1 \gamma\ge1 γ ≥ 1 , minimizing cutweight ( P ) + β ∑ I ∈ P ∣ I ∣ γ \operatorname{cutweight}(\mathcal P)+\beta\sum_{I\in\mathcal P}|I|^\gamma cutweight ( P ) + β ∑ I ∈ P ∣ I ∣ γ over K K K contiguous blocks takes O ( m + K ( n + m ) L 3 ) O(m+K(n+m)L^3) O ( m + K ( n + m ) L 3 ) time given a constant-time exact oracle for ϕ ( x ) = β x γ \phi(x)=\beta x^\gamma ϕ ( x ) = β x γ [26 ] , and this is a word-RAM bound for fixed integer γ \gamma γ when a fixed rational scaling gives polynomially bounded integer data.
Unweighted and finite-support cluster editing. With unit prices b e = η = 1 b_e=\eta=1 b e = η = 1 , every optimal block ending at j j j has at most 2 d j − + 1 2d_j^-+1 2 d j − + 1 vertices, where d j − d_j^- d j − counts the neighbors preceding j j j , giving an O ( n + m ) O(n+m) O ( n + m ) -time algorithm (Theorem B.1 ). When blocks may contain only listed pairs, the number of such pairs incident to each right endpoint gives an O ( n + q ) O(n+q) O ( n + q ) -time algorithm for a list of q q q pairs (Theorem B.2 ).
Product lower bounds and the graph of negative differences
The reductions in this section bound the exponents for matrix products, vector queries, and weighted triangles in terms of the number of negative differences or the graph formed by their row and column indices.
Reduction to a squared-distance matrix with discounts
Partitioning the middle indices expresses a general integer min-plus product as the entrywise minimum of group products, each of which can be recovered from a product whose right factor has a squared-distance background and interval discounts.
Theorem 5.1 (Reduction to a quadratic background). Fix 0 < α ≤ 1 0<\alpha\le1 0 < α ≤ 1 and suppose a deterministic O ( n β ) O(n^\beta) O ( n β ) -time algorithm computes A ⊗ B A\otimes B A ⊗ B for n × n n\times n n × n polynomially bounded integer matrices with
B k j = ( j − k ) 2 − ∑ ℓ = 1 r w ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } , w ℓ > 0 , r ≤ n 1 + α , (10) B_{kj}=(j-k)^2-\sum_{\ell=1}^{r}w_\ell\mathbf{1}\{k\in I_\ell\}\mathbf{1}\{j\in J_\ell\},\qquad w_\ell>0,\qquad r\le n^{1+\alpha}, \tag*{(10)} B k j = ( j − k ) 2 − ℓ = 1 ∑ r w ℓ 1 { k ∈ I ℓ } 1 { j ∈ J ℓ } , w ℓ > 0 , r ≤ n 1 + α , (10) where each I ℓ I_\ell I ℓ is a prefix or suffix, each J ℓ J_\ell J ℓ is a suffix, s ( B ) ≤ n 1 + α s(B)\le n^{1+\alpha} s ( B ) ≤ n 1 + α , and all mixed differences are nonzero with Θ ( n 2 ) \Theta(n^2) Θ ( n 2 ) of them positive. With B B B supplied either explicitly or by the rectangle list, this algorithm gives a deterministic O ( n 1 − α + β + n 3 − α ) O(n^{1-\alpha+\beta}+n^{3-\alpha}) O ( n 1 − α + β + n 3 − α ) -time algorithm for general integer min-plus multiplication and hence for APSP with polynomially bounded integer weights.
Proof sketch , with details in Appendix § 9 . For arbitrary integer matrices A , B ∈ [ − U , U ] n × n A,B \in[-U,U]^{n \times n} A , B ∈ [ − U , U ] n × n and fixed α \alpha α , the finitely many sizes with n α < 4 n^\alpha< 4 n α < 4 can be solved directly, and for larger n n n the middle indices are partitioned into Q = ⌈ n / b ⌉ = O ( n 1 − α ) Q=\lceil n/b\rceil=O(n^{1-\alpha}) Q = ⌈ n / b ⌉ = O ( n 1 − α ) groups of size a ≤ b = ⌊ n α / 4 ⌋ a\le b=\lfloor n^{\alpha}/4\rfloor a ≤ b = ⌊ n α /4 ⌋ . For a group κ 0 , … , κ a − 1 \kappa_0,\ldots,\kappa_{a-1} κ 0 , … , κ a − 1 , place its columns of A A A and rows of B B B in positions k < a k<a k < a of A ( g ) , B ( g ) A^{(g)},B^{(g)} A ( g ) , B ( g ) and set A i k ( g ) = 2 U + 1 A^{(g)}_{ik}=2U+1 A ik ( g ) = 2 U + 1 , B k j ( g ) = 0 B^{(g)}_{kj}=0 B k j ( g ) = 0 for k ≥ a k\ge a k ≥ a , so each padded path has weight 2 U + 1 > 2 U 2U+1>2U 2 U + 1 > 2 U and ( A ⊗ B ) i j = min 0 ≤ g < Q ( A ( g ) ⊗ B ( g ) ) i j (A\otimes B)_{ij}=\min_{0\le g<Q}(A^{(g)}\otimes B^{(g)})_{ij} ( A ⊗ B ) ij = min 0 ≤ g < Q ( A ( g ) ⊗ B ( g ) ) ij .
All nonzero differences D p q = Δ B p q ( g ) D_{pq}=\Delta B^{(g)}_{pq} D pq = Δ B pq ( g ) occur in the first a a a row gaps, so the telescoping representation B k j ( g ) = u k + v j + R k j B^{(g)}_{kj}=u_k+v_j+R_{kj} B k j ( g ) = u k + v j + R k j has at most a ( n − 1 ) ≤ b ( n − 1 ) a(n-1)\le b(n-1) a ( n − 1 ) ≤ b ( n − 1 ) nonzero terms in R k j = − ∑ p < k , q < j D p q R_{kj}=-\sum_{p<k,q<j}D_{pq} R k j = − ∑ p < k , q < j D pq . With λ = 2 n 2 + 1 \lambda=2n^2+1 λ = 2 n 2 + 1 , the two factors are
A ^ i k = λ ( A i k ( g ) + u k ) − k 2 , B k j ∗ = ( j − k ) 2 + λ R k j − F [ j ] , \widehat{A}_{ik}=\lambda(A^{(g)}_{ik}+u_k)-k^2,\qquad B^*_{kj}=(j-k)^2+\lambda R_{kj}-F[j], A ik = λ ( A ik ( g ) + u k ) − k 2 , B k j ∗ = ( j − k ) 2 + λ R k j − F [ j ] ,
where F [ j ] F[j] F [ j ] collects the column terms from the identity c 1 { k > p } 1 { j > q } = c 1 { j > q } − c 1 { k ≤ p } 1 { j > q } c1\{k>p\}1\{j>q\}=c1\{j>q\}-c1\{k\le p\}1\{j>q\} c 1 { k > p } 1 { j > q } = c 1 { j > q } − c 1 { k ≤ p } 1 { j > q } for each positive coefficient c c c . Substitution gives
A ^ i k + B k j ∗ = λ ( A i k ( g ) + B k j ( g ) ) − 2 k j + ( j 2 − λ v j − F [ j ] ) . \widehat{A}_{ik}+B^*_{kj}=\lambda(A^{(g)}_{ik}+B^{(g)}_{kj})-2kj+(j^2-\lambda v_j-F[j]). A ik + B k j ∗ = λ ( A ik ( g ) + B k j ( g ) ) − 2 k j + ( j 2 − λ v j − F [ j ]) .
Because 0 ≤ 2 k j ≤ 2 ( n − 1 ) 2 < λ 0\le2kj\le2(n-1)^2<\lambda 0 ≤ 2 k j ≤ 2 ( n − 1 ) 2 < λ for all k , j ∈ [ 0 , n − 1 ] k,j\in[0,n-1] k , j ∈ [ 0 , n − 1 ] , subtracting the column potential j 2 − λ v j − F [ j ] j^2-\lambda v_j-F[j] j 2 − λ v j − F [ j ] from S i j = ( A ^ ⊗ B ∗ ) i j S_{ij}=(\widehat{A}\otimes B^*)_{ij} S ij = ( A ⊗ B ∗ ) ij to get S ~ i j \widetilde{S}_{ij} S ij recovers the exact integer product entry via
( A ( g ) ⊗ B ( g ) ) i j = ⌈ S ~ i j λ ⌉ . (A^{(g)}\otimes B^{(g)})_{ij}=\left\lceil\frac{\widetilde{S}_{ij}}{\lambda}\right\rceil. ( A ( g ) ⊗ B ( g ) ) ij = ⌈ λ S ij ⌉ .
The differences Δ B p q ∗ = 2 + λ D p q \Delta B^*_{pq}=2+\lambda D_{pq} Δ B pq ∗ = 2 + λ D pq are all nonzero, have negative sign precisely at the negative cells of D D D , and are positive on at least ( n − 1 − a ) ( n − 1 ) = Θ ( n 2 ) (n-1-a)(n-1)=\Theta(n^2) ( n − 1 − a ) ( n − 1 ) = Θ ( n 2 ) cells, with s ( B ∗ ) ≤ r ≤ b ( n − 1 ) ≤ n 1 + α s(B^*)\le r\le b(n-1)\le n^{1+\alpha} s ( B ∗ ) ≤ r ≤ b ( n − 1 ) ≤ n 1 + α . Preparing and solving the Q = O ( n 1 − α ) Q=O(n^{1-\alpha}) Q = O ( n 1 − α ) instances therefore takes O ( n 1 − α + β + n 3 − α ) O(n^{1-\alpha+\beta}+n^{3-\alpha}) O ( n 1 − α + β + n 3 − α ) time.
Corollary 5.2 (Product exponents under γ \gamma γ -APSP). For every fixed α ∈ ( 3 − c A P S P , 1 ] \alpha\in(3-c_{\mathrm{APSP}},1] α ∈ ( 3 − c APSP , 1 ] , any deterministic algorithm for the promise problem in Theorem 5.1 (and hence for A ⊗ B A\otimes B A ⊗ B under s ( B ) ≤ n 1 + α s(B)\le n^{1+\alpha} s ( B ) ≤ n 1 + α ) has complexity exponent β ≥ c A P S P − 1 + α \beta\ge c_{\mathrm{APSP}}-1+\alpha β ≥ c APSP − 1 + α . In particular, under the γ \gamma γ -APSP Hypothesis (Definition 2.1 ), no O ( n γ − 1 + α − ϵ ) O(n^{\gamma-1+\alpha-\epsilon}) O ( n γ − 1 + α − ϵ ) -time algorithm exists for any fixed α ∈ ( 3 − γ , 1 ] \alpha\in(3-\gamma,1] α ∈ ( 3 − γ , 1 ] and ϵ > 0 \epsilon>0 ϵ > 0 .
Proof. By Theorem 5.1 and the definition of c A P S P c_{\mathrm{APSP}} c APSP , we have max { 1 − α + β , 3 − α } ≥ c A P S P \max\{1-\alpha+\beta,3-\alpha\}\ge c_{\mathrm{APSP}} max { 1 − α + β , 3 − α } ≥ c APSP , and the assumption α > 3 − c A P S P \alpha>3-c_{\mathrm{APSP}} α > 3 − c APSP gives 3 − α < c A P S P 3-\alpha<c_{\mathrm{APSP}} 3 − α < c APSP , so 1 − α + β ≥ c A P S P 1-\alpha+\beta\ge c_{\mathrm{APSP}} 1 − α + β ≥ c APSP as claimed.
For polynomially bounded integer inputs the upper exponent is at most min { 2 + α , c A P S P } \min\{2+\alpha,c_{\mathrm{APSP}}\} min { 2 + α , c APSP } by taking the faster of the sweep and a general product algorithm, and the Ω ( n 2 ) \Omega(n^2) Ω ( n 2 ) output time together with Corollary 5.2 gives the lower exponent max { 2 , c A P S P − 1 + α } \max\{2,c_{\mathrm{APSP}}-1+\alpha\} max { 2 , c APSP − 1 + α } for all 0 ≤ α ≤ 1 0\le\alpha\le1 0 ≤ α ≤ 1 . At α = 1 \alpha=1 α = 1 the reduction uses a constant number of instances and quadratic preparation, so the class with the fixed quadratic background has exponent c A P S P c_{\mathrm{APSP}} c APSP in both input representations, since four corner updates per rectangle followed by a two-dimensional prefix sum materialize B B B in O ( n 2 + r ) O(n^2+r) O ( n 2 + r ) time.
Remark 5.3 (Distances in a three-layer graph with nonnegative weights). For complete bipartite arcs between consecutive layers, the product entries are exactly the first-to-third distances, and Theorem 3.5 returns a minimizing intermediate vertex for each pair. Shifting A A A and B B B uniformly by c A = max { 0 , − min i , k A i k } c_A=\max\{0,-\min_{i,k}A_{ik}\} c A = max { 0 , − min i , k A ik } and c B = max { 0 , − min k , j B k j } c_B=\max\{0,-\min_{k,j}B_{kj}\} c B = max { 0 , − min k , j B k j } makes all edge weights nonnegative and adds c A + c B c_A+c_B c A + c B to every first-to-third distance. The shift preserves Δ B \Delta B Δ B , so the exponent lower bound of Corollary 5.2 also holds for computing these distances under the same negative-support bound. For the instances in (10) , the shifted quadratic background is ( j − k ) 2 + c B (j-k)^2+c_B ( j − k ) 2 + c B .
The negative-support graph and repeated products
The bipartite negative-support graph G − ( B ) G_-(B) G − ( B ) has n − 1 n-1 n − 1 row gaps and n − 1 n-1 n − 1 column gaps as vertices, with an edge ( p , q ) (p,q) ( p , q ) whenever Δ B p , q < 0 \Delta B_{p,q}<0 Δ B p , q < 0 . Let s = ∣ E ( G − ( B ) ) ∣ s=|E(G_-(B))| s = ∣ E ( G − ( B )) ∣ , τ = vc ( G − ( B ) ) \tau=\operatorname{vc}(G_-(B)) τ = vc ( G − ( B )) (vertex cover number), Δ − = max v deg G − ( B ) ( v ) \Delta_-=\max_v \deg_{G_-(B)}(v) Δ − = max v deg G − ( B ) ( v ) (maximum degree), and t = tw ( G − ( B ) ) t=\operatorname{tw}(G_-(B)) t = tw ( G − ( B )) (treewidth). Since s ≤ ( n − 1 ) Δ − s\le(n-1)\Delta_- s ≤ ( n − 1 ) Δ − and a graph of treewidth t t t on 2 ( n − 1 ) 2(n-1) 2 ( n − 1 ) vertices is t t t -degenerate (s ≤ 2 ( n − 1 ) t s\le2(n-1)t s ≤ 2 ( n − 1 ) t ), Theorem 3.5 gives O ~ ( n 2 ( Δ − + 1 ) ) \widetilde{O}(n^2(\Delta_-+1)) O ( n 2 ( Δ − + 1 )) and O ~ ( n 2 ( t + 1 ) ) \widetilde{O}(n^2(t+1)) O ( n 2 ( t + 1 )) multiplication bounds. Cutting at the gaps of a vertex cover of size at most 2 τ 2\tau 2 τ partitions B B B into Monge submatrices on which SMAWK computes column minima.
Global row and column cuts partition B B B into Monge rectangles if and only if the chosen gaps cover every edge of G − ( B ) G_-(B) G − ( B ) , since an uncovered negative cell lies inside a block and violates its adjacent inequality, and telescoping the nonnegative differences of a block gives the Monge inequality throughout that block. The minimum number of such cuts is therefore τ \tau τ .
For n ≥ 2 n\ge2 n ≥ 2 and a permutation σ \sigma σ of [ 0 , n − 2 ] [0,n-2] [ 0 , n − 2 ] , consider the matrix
P ( i , j ) = ∣ { p < i : σ ( p ) < j } ∣ , B i j = − i j + 2 P ( i , j ) . P(i,j)=|\{p<i:\sigma(p)<j\}|,\qquad B_{ij}=-ij+2P(i,j). P ( i , j ) = ∣ { p < i : σ ( p ) < j } ∣ , B ij = − ij + 2 P ( i , j ) .
Here Δ B p , q = 1 − 21 { q = σ ( p ) } \Delta B_{p,q}=1-2\mathbf{1}\{q=\sigma(p)\} Δ B p , q = 1 − 2 1 { q = σ ( p )} , so all ( n − 1 ) 2 (n-1)^2 ( n − 1 ) 2 differences are nonzero and the negative-support graph is a perfect matching with s = τ = n − 1 s=\tau=n-1 s = τ = n − 1 and Δ − = t = 1 \Delta_-=t=1 Δ − = t = 1 . More generally, the matrix B i j = − ∑ p < i , q < j F p , q B_{ij}=-\sum_{p<i,q<j}F_{p,q} B ij = − ∑ p < i , q < j F p , q realizes any specified mixed-difference array F F F .
Theorem 5.4 (Product bounds from the negative-support graph).
Vertex cover. Given explicit n × n n\times n n × n matrices A , B A,B A , B , Algorithm 14 uses the endpoints of a maximal matching as a vertex cover and computes A ⊗ B A\otimes B A ⊗ B in O ( n 2 ( τ ( B ) + 1 ) ) O(n^2(\tau(B)+1)) O ( n 2 ( τ ( B ) + 1 )) time and O ( n 2 ) O(n^2) O ( n 2 ) space.
Exponent lower bounds. For every fixed α ∈ ( 3 − c A P S P , 1 ] \alpha\in(3-c_{\mathrm{APSP}},1] α ∈ ( 3 − c APSP , 1 ] , any deterministic algorithm for A ⊗ B A\otimes B A ⊗ B under any single promise s ( B ) ≤ n 1 + α s(B)\le n^{1+\alpha} s ( B ) ≤ n 1 + α , τ ( B ) ≤ n α \tau(B)\le n^\alpha τ ( B ) ≤ n α , Δ − ( B ) ≤ n α \Delta_-(B)\le n^\alpha Δ − ( B ) ≤ n α , or t ( B ) ≤ n α t(B)\le n^\alpha t ( B ) ≤ n α requires exponent β ≥ c A P S P − 1 + α \beta\ge c_{\mathrm{APSP}}-1+\alpha β ≥ c APSP − 1 + α .
The algorithms for support size, maximum degree, and treewidth obtain their input from a scan of the mixed differences, and in each case the running time can be bounded by the smaller of the stated bound and the time for direct cubic multiplication.
For arbitrary finite X 0 X_0 X 0 , Algorithm 15 computes X 0 ⊗ B 1 ⊗ ⋯ ⊗ B ℓ X_0\otimes B_1\otimes\cdots\otimes B_\ell X 0 ⊗ B 1 ⊗ ⋯ ⊗ B ℓ from left to right in O ( ℓ n 2 L + n L 3 ∑ t = 1 ℓ s ( B t ) ) O(\ell n^2L+nL^3\sum_{t=1}^{\ell}s(B_t)) O ( ℓ n 2 L + n L 3 ∑ t = 1 ℓ s ( B t )) time and O ( n 2 ) O(n^2) O ( n 2 ) working space beyond the supplied matrices. Storing the witnesses at each layer takes another O ( ℓ n 2 ) O(\ell n^2) O ( ℓ n 2 ) space and permits path reconstruction for every source and terminal, including when an intermediate product has the quadratic negative support in the following example.
Example 5.5 (Negative differences in a product). For 0 ≤ i , k , j < n 0\le i,k,j<n 0 ≤ i , k , j < n , define
A i k = { i k = 0 , 0 k > 0 , B k j = { n k > 0 and j odd , 0 otherwise . A_{ik}=
\begin{cases}
i & k=0,\\
0 & k>0,
\end{cases}
\qquad
B_{kj}=
\begin{cases}
n & k>0\text{ and }j\text{ odd},\\
0 & \text{otherwise}.
\end{cases} A ik = { i 0 k = 0 , k > 0 , B k j = { n 0 k > 0 and j odd , otherwise .
The matrix A A A is Monge and B B B has s ( B ) = ⌊ n / 2 ⌋ s(B)=\lfloor n/2\rfloor s ( B ) = ⌊ n /2 ⌋ negative differences on its first row gap, while the product ( A ⊗ B ) i j = i 1 { j odd } (A\otimes B)_{ij}=i\mathbf{1}\{j\text{ odd}\} ( A ⊗ B ) ij = i 1 { j odd } has differences alternating between − 1 -1 − 1 and + 1 +1 + 1 along each row gap, giving s ( A ⊗ B ) = ( n − 1 ) ⌊ n / 2 ⌋ = Θ ( n 2 ) s(A\otimes B)=(n-1)\lfloor n/2\rfloor=\Theta(n^2) s ( A ⊗ B ) = ( n − 1 ) ⌊ n /2 ⌋ = Θ ( n 2 ) .
Vector queries and weighted triangles
Corollary 5.6 (Amortized vector queries). For fixed 3 − c A P S P < α ≤ 1 3-c_{\mathrm{APSP}}<\alpha\le1 3 − c APSP < α ≤ 1 , consider a deterministic data structure that preprocesses a polynomially bounded integer matrix B B B with s ( B ) ≤ n 1 + α s(B)\le n^{1+\alpha} s ( B ) ≤ n 1 + α in O ( n 2 ) O(n^2) O ( n 2 ) time and answers n n n products with polynomially bounded integer vectors in amortized time O ( n η ) O(n^\eta) O ( n η ) per vector. Its query exponent satisfies η ≥ c A P S P − 2 + α \eta\ge c_{\mathrm{APSP}}-2+\alpha η ≥ c APSP − 2 + α , including for the right factors of Theorem 5.1 .
Proof. Querying the n n n rows of an arbitrary polynomially bounded integer matrix A A A computes A ⊗ B A \otimes B A ⊗ B in O ( n 2 + n 1 + η ) O(n^2+n^{1+\eta}) O ( n 2 + n 1 + η ) time, so Corollary 5.2 and c A P S P − 1 + α > 2 c_{\mathrm{APSP}}-1+\alpha>2 c APSP − 1 + α > 2 give 1 + η ≥ c A P S P − 1 + α 1+\eta\ge c_{\mathrm{APSP}}-1+\alpha 1 + η ≥ c APSP − 1 + α . These queries are fixed in advance and hence form a valid query sequence for a structure that also accepts adaptive queries.
For explicit matrices A , B , Z A,B,Z A , B , Z , write
Tri ( A , B , Z ) = min i , k , j ( A i k + B k j + Z j i ) = min i , j ( ( A ⊗ B ) i j + Z j i ) . \operatorname{Tri}(A,B,Z)=\min_{i,k,j}(A_{ik}+B_{kj}+Z_{ji})=\min_{i,j}((A\otimes B)_{ij}+Z_{ji}). Tri ( A , B , Z ) = i , k , j min ( A ik + B k j + Z j i ) = i , j min (( A ⊗ B ) ij + Z j i ) .
Minimum-Weight Triangle returns this value and Negative Triangle tests its sign, so scanning the n 2 n^2 n 2 entries after multiplication solves either problem in O ( n 2 L + n s L 3 ) O(n^2L+nsL^3) O ( n 2 L + n s L 3 ) or O ( n 2 ( τ + 1 ) ) O(n^2(\tau+1)) O ( n 2 ( τ + 1 )) time and O ( n 2 ) O(n^2) O ( n 2 ) space. The case A = 0 A=0 A = 0 , B k j = ( j − k ) 2 B_{kj}=(j-k)^2 B k j = ( j − k ) 2 has s = τ = Δ − = t = 0 s=\tau=\Delta_-=t=0 s = τ = Δ − = t = 0 and every product entry equal to zero, so on an all-zero Z Z Z a deterministic algorithm must inspect all n 2 n^2 n 2 entries to distinguish this input from one with a single negative entry.
Let c △ c_{\triangle} c △ be the infimum of the deterministic time exponents for general Negative Triangle with polynomially bounded integer weights, so computing a full product and scanning it gives c △ ≤ c A P S P c_{\triangle}\le c_{\mathrm{APSP}} c △ ≤ c APSP . Vassilevska Williams and Williams [27 ] relate APSP and Negative Triangle by reductions preserving truly subcubic time, and the two triangle problems have the same exponent because subtracting a threshold from Z Z Z tests whether the optimum is below that threshold, allowing binary search over the integer weight range with O ( log n ) O(\log n) O ( log n ) sign tests.
Proposition 5.7 (Exponent transfer for weighted triangles). Fix 0 < α ≤ 1 0<\alpha\le1 0 < α ≤ 1 and impose any one of the four promises on B B B in Theorem 5.4 . A deterministic O ( n β ) O(n^\beta) O ( n β ) algorithm for either triangle problem under that promise gives a deterministic O ( n 1 − α + β + n 3 − α ) O(n^{1-\alpha+\beta}+n^{3-\alpha}) O ( n 1 − α + β + n 3 − α ) algorithm for general Negative Triangle. A restricted minimum-weight solver also computes the general minimum weight within the same time bound. For the promise s ( B ) ≤ n 1 + α s(B)\le n^{1+\alpha} s ( B ) ≤ n 1 + α this also holds with the fixed quadratic background and interval discounts of Theorem 5.1 , in either input representation. Consequently β ≥ c △ − 1 + α \beta\ge c_{\triangle}-1+\alpha β ≥ c △ − 1 + α whenever 3 − c △ < α ≤ 1 3-c_{\triangle}<\alpha\le1 3 − c △ < α ≤ 1 .
Proof. For a bound U U U on the absolute entries of A A A , B B B , Z Z Z , use the groups of Theorem 5.1 with padding H = 5 U + 1 H=5U+1 H = 5 U + 1 in A ( g ) A^{(g)} A ( g ) and zero in B ( g ) B^{(g)} B ( g ) , so a padded triangle weighs at least H − U > 3 U H-U>3U H − U > 3 U and the minimum over the groups equals the original optimum. For the fixed quadratic background use the factors A ^ \widehat{A} A , B ∗ B^* B ∗ and quantities λ \lambda λ , v j v_j v j , F [ j ] F[j] F [ j ] from the product reduction, with third factor
Z j i ∗ = λ ( Z j i + v j ) − j 2 + F [ j ] + 2 n 2 . Z^*_{ji}=\lambda(Z_{ji}+v_j)-j^2+F[j]+2n^2. Z j i ∗ = λ ( Z j i + v j ) − j 2 + F [ j ] + 2 n 2 .
A triangle of integer weight T = A i k ( g ) + B k j ( g ) + Z j i T=A^{(g)}_{ik}+B^{(g)}_{kj}+Z_{ji} T = A ik ( g ) + B k j ( g ) + Z j i now weighs λ T + 2 n 2 − 2 k j \lambda T+2n^2-2kj λ T + 2 n 2 − 2 k j , where 0 ≤ 2 n 2 − 2 k j < λ 0\le2n^2-2kj<\lambda 0 ≤ 2 n 2 − 2 k j < λ , so the transformed sum is negative exactly for T < 0 T<0 T < 0 , is nonnegative for T = 0 T=0 T = 0 , and gives the group optimum ⌊ Tri ( A ^ , B ∗ , Z ∗ ) / λ ⌋ \lfloor\operatorname{Tri}(\widehat{A},B^*,Z^*)/\lambda\rfloor ⌊ Tri ( A , B ∗ , Z ∗ ) / λ ⌋ after minimization. The flat α ≤ [ n α / 4 ] \alpha\le[n^\alpha/4] α ≤ [ n α /4 ] row gaps cover all negative cells, and taking those gaps together with one successive column gap in each bag gives a path decomposition of width at most α \alpha α , with singleton bags for isolated vertices.
For the maximum-degree promise, the cyclic block construction in the proof of Theorem 5.4 with filler H = 5 U + 1 H=5U+1 H = 5 U + 1 retains each original entry of B B B in one block and gives every triangle using a filler weight at least H − 2 U > 3 U H-2U>3U H − 2 U > 3 U . Each construction prepares O ( n 1 − α ) O(n^{1-\alpha}) O ( n 1 − α ) instances in O ( n 2 ) O(n^2) O ( n 2 ) time per instance, and the disjunction of the sign tests gives the decision answer while the least recovered group optimum gives the exact answer. When α > 3 − c △ \alpha>3-c_{\triangle} α > 3 − c △ the preparation exponent 3 − α 3-\alpha 3 − α is below c △ c_{\triangle} c △ , giving 1 − α + β ≥ c △ 1-\alpha+\beta\ge c_{\triangle} 1 − α + β ≥ c △ from the definition of the exponent.
For bounded-error algorithms the same transfer holds with the randomized Negative Triangle exponent, since O ( log n ) O(\log n) O ( log n ) independent repetitions per instance bound the error probability of the disjunction by 1 / 3 1/3 1/3 and preserve the time exponents.
Conclusions and open problems
For an arbitrary left factor, s ( B ) = O ( n ) s(B) = O(n) s ( B ) = O ( n ) gives a near-quadratic min-plus product, and a constant-time Monge oracle with O ( n ) O(n) O ( n ) rectangle corrections gives near-linear sequential partitioning, including the convex-load objectives on sparse ordered graphs. For s ( B ) ≤ n 1 + α s(B) \le n^{1+\alpha} s ( B ) ≤ n 1 + α with 3 − c A P S P < α ≤ 1 3-c_{\mathrm{APSP}} < \alpha\le1 3 − c APSP < α ≤ 1 , the sweep has upper exponent 2 + α 2+\alpha 2 + α and the squared-distance reduction gives lower exponent c A P S P − 1 + α c_{\mathrm{APSP}} - 1 + \alpha c APSP − 1 + α , with equality to the general product exponent at α = 1 \alpha= 1 α = 1 as shown in § 5 .
The running time of a single recurrence and the cost of successive sweeps give the following open problems. Appendix § 10 discusses the input representation and the choice of order.
Dependence on the number of rectangles. Classical Monge recurrences take O ( n ) O(n) O ( n ) time when r = 0 r = 0 r = 0 [31 , 17 ] , and an O ( n + r p o l y l o g n ) O(n + r\mathop{\mathrm{polylog}} n) O ( n + r polylog n ) bound for rectangle corrections would retain this linear term, including for internal rewards whose events at j = max e j = \max e j = max e affect rows k < min e k < \min e k < min e .
Lower bounds for one recurrence. Theorem 5.1 bounds the exponent for a batch of matrix products, and the corresponding problem for a single recurrence (4) is to determine a conditional lower bound in terms of n n n and the number r r r of supplied rectangles.
Vertex cover and treewidth in sequential DP. A bound in terms of the vertex cover number τ ( C ) \tau(C) τ ( C ) or treewidth t ( C ) t(C) t ( C ) of the negative-support graph would extend Theorem 5.4 to a triangular recurrence, where the order of the block computations must respect the availability of the prefix values D [ k ] D[k] D [ k ] .
Cyclic orders and successive layers. Each rotation of a cyclic order in Algorithm 9 and each layer of fixed-K K K partitioning in Algorithm 5 starts a new sweep, leaving open whether the envelope information from one run can reduce the total work over all rotations or layers.
Pseudocode for the column sweep
In the balanced tree T T T of § 3 , each node u u u stores its interval K ( u ) K(u) K ( u ) and the number of active leaves, and each internal node stores a lazy addition z u z_u z u and switch column θ u \theta_u θ u . For a nonempty node, APPLY( u , β ) (u,\beta) ( u , β ) adds β \beta β to the stored potential v k v_k v k at a leaf or to the tag z u z_u z u at an internal node, and for an empty node the operation returns immediately. The operation PUSH( u ) (u) ( u ) applies z u z_u z u to both children and then sets z u z_u z u to zero.
Algorithm 1 Envelope evaluation and switch columns
1: function EVAL(u, x)
2: if u is empty then return (+∞, −1) end if
3: if u is the leaf for k then return (v_k + M(k, x), k) end if
4: if x < θ_u then (val, idx) ← EVAL(left(u), x) else (val, idx) ← EVAL(right(u), x) end if
5: return (val + z_u, idx)
6: end function
7: function PULL(u, j)
8: a ← left(u); b ← right(u); recompute active count of u from a, b
9: if b is empty then θ_u ← v + 1; return end if
10: if a is empty then θ_u ← j; return end if
11: l ← j; h ← v + 1
12: while l < h do
13: x ← ⌊(l + h)/2⌋
14: if EVAL(b, x).value < EVAL(a, x).value then h ← x else l ← x + 1 end if
15: end while
16: θ_u ← l
17: end function
Algorithm 2 Interval addition and row activation
1: function ADD(u , I , β , j u, I, \beta, j u , I , β , j ) 2: if K ( u ) ∩ I = ∅ K(u) \cap I = \emptyset K ( u ) ∩ I = ∅ or u u u is empty then return end if 3: if K ( u ) ⊆ I K(u) \subseteq I K ( u ) ⊆ I then APPLY(u , β u, \beta u , β ); return end if 4: PUSH(u u u ); ADD(left(u ) , I , u), I, u ) , I , \beta, j) ; A D D ( r i g h t ( ); ADD(right( ) ; A D D ( r i g h t ( u), I, β , j \beta, j β , j ); PULL(u , j u, j u , j ) 5: end function 6: function ACTIVATE(u , k , v , j u, k, v, j u , k , v , j ) 7: if u u u is a leaf then v k ← v v_k \leftarrow v v k ← v ; set active count to 1; return end if 8: PUSH(u u u ); let c c c be the child of u u u containing k k k 9: ACTIVATE(c , k , v , j c, k, v, j c , k , v , j ); PULL(u , j u, j u , j ) 10: end function
Algorithm 3 Vector product STATICTRANSFER(x , M , E x, M, E x , M , E )
1: ν ← n − 1 \nu\leftarrow n - 1 ν ← n − 1 ; build balanced binary tree T T T on [ 0 , n − 1 ] [0, n - 1] [ 0 , n − 1 ] 2: At leaf k k k , set v k ← x k v_k \leftarrow x_k v k ← x k and mark active (if x k = + ∞ x_k = +\infty x k = + ∞ , leave inactive); set all z u ← 0 z_u \leftarrow0 z u ← 0 3: for each internal node u u u in bottom-up order do PULL(u , 0 u, 0 u , 0 ) end for 4: for j = 0 , … , n − 1 j = 0, \ldots, n - 1 j = 0 , … , n − 1 do 5: for each event ( I , β ) (I, \beta) ( I , β ) in bucket E [ j ] E[j] E [ j ] do ADD(T . r o o t , I , β , j T.\mathrm{root}, I, \beta, j T . root , I , β , j ) end for 6: ( y j , π j ) ← (y_j, \pi_j) \leftarrow ( y j , π j ) ← EVAL(T . r o o t , j T.\mathrm{root}, j T . root , j ) 7: end for 8: return y , π y, \pi y , π
Algorithm 4 Sequential partitioning with rectangle corrections
1: ν ← n \nu\leftarrow n ν ← n ; bucket entry ( I ℓ , + α ℓ ) (I_\ell, +\alpha_\ell) ( I ℓ , + α ℓ ) at a ℓ a_\ell a ℓ and exit ( I ℓ , − α ℓ ) (I_\ell, -\alpha_\ell) ( I ℓ , − α ℓ ) at b ℓ + 1 b_\ell+ 1 b ℓ + 1 (if b ℓ < n b_\ell< n b ℓ < n ) 2: Initialize empty envelope tree T T T and zero difference-array Fenwick tree H H H on [ 0 , n − 1 ] [0, n - 1] [ 0 , n − 1 ] 3: D [ 0 ] ← 0 D[0] \leftarrow0 D [ 0 ] ← 0 4: for j = 1 , … , n j = 1, \ldots, n j = 1 , … , n do 5: for each event ( I , β ) (I, \beta) ( I , β ) in bucket j j j do 6: H . a d d ( I , β ) H.\mathrm{add}(I, \beta) H . add ( I , β ) ; ADD(T . r o o t , I ∩ [ 0 , j − 2 ] , β , j T.\mathrm{root}, I \cap[0, j - 2], \beta, j T . root , I ∩ [ 0 , j − 2 ] , β , j ) 7: end for 8: k ← j − 1 k \leftarrow j - 1 k ← j − 1 9: if D [ k ] < + ∞ D[k] < +\infty D [ k ] < + ∞ then ACTIVATE(T . r o o t , k , D [ k ] + H . p o i n t ( k ) , j T.\mathrm{root}, k, D[k] + H.\mathrm{point}(k), j T . root , k , D [ k ] + H . point ( k ) , j ) end if 10: ( D [ j ] , π [ j ] ) ← (D[j], \pi[j]) \leftarrow ( D [ j ] , π [ j ]) ← minimum at column j j j over F j F_j F j (default F j = [ 0 , j − 1 ] F_j = [0, j - 1] F j = [ 0 , j − 1 ] ) 11: end for 12: return ( D , π ) (D, \pi) ( D , π )
Algorithm 5 Partition into K K K blocks
1: P [ 0 ] ← 0 P[0] \leftarrow0 P [ 0 ] ← 0 ; P [ 1.. n ] ← + ∞ P[1..n] \leftarrow+\infty P [ 1.. n ] ← + ∞ 2: for b = 1 , … , K b = 1, \ldots, K b = 1 , … , K do 3: Initialize Q [ 0.. n ] ← + ∞ Q[0..n] \leftarrow+\infty Q [ 0.. n ] ← + ∞ 4: Run Algorithm 4, activating row k k k with P [ k ] + H . p o i n t ( k ) P[k] + H.\mathrm{point}(k) P [ k ] + H . point ( k ) whenever P [ k ] < + ∞ P[k] < +\infty P [ k ] < + ∞ , writing answers to Q [ j ] Q[j] Q [ j ] and predecessors to π b [ j ] \pi_b[j] π b [ j ] 5: P ← Q P \leftarrow Q P ← Q 6: end for 7: return P [ n ] P[n] P [ n ] and partition reconstructed via ( b , j ) ← ( b − 1 , π b [ j ] ) (b, j) \leftarrow(b - 1, \pi_b[j]) ( b , j ) ← ( b − 1 , π b [ j ])
Algorithm 6 Monge oracle from a list of negative cells
1: Bucket negative cells ( p , q , w p , q ) (p, q, w_{p,q}) ( p , q , w p , q ) by column q q q ; V 0 ← V_0 \leftarrow V 0 ← zero segment tree on [ 0 , n − 1 ] [0, n - 1] [ 0 , n − 1 ] 2: for j = 1 , … , n j = 1, \ldots, n j = 1 , … , n do 3: V j ← V j − 1 V_j \leftarrow V_{j-1} V j ← V j − 1 4: for each ( p , j − 1 , w ) (p, j - 1, w) ( p , j − 1 , w ) in bucket j − 1 j - 1 j − 1 do V j ← V_j \leftarrow V j ← PersistentPointAdd(V j , p , w V_j, p, w V j , p , w ) end for 5: end for Algorithm 6 Monge oracle from a list of negative cells (continued)
6: Define M ( k , j ) = C ( k , j ) + SuffixSum ( V j , k ) M(k,j) = C(k,j) + \operatorname{SuffixSum}(V_j,k) M ( k , j ) = C ( k , j ) + SuffixSum ( V j , k ) and create rectangles ( [ 0 , p ] , [ q + 1 , n ] , − w p , q ) ([0,p], [q+1,n], -w_{p,q}) ([ 0 , p ] , [ q + 1 , n ] , − w p , q )
7: return output of Algorithm 4 with background M M M and these rectangles
Algorithms for contiguous partitions and convex transitions
Algorithm 7 Layered recurrence with convex transitions
1: d ← d 0 d \leftarrow d_0 d ← d 0
2: for t = 1 , … , ℓ t = 1,\ldots,\ell t = 1 , … , ℓ do
3: Bucket ( I , α ) (I,\alpha) ( I , α ) at a a a and ( I , − α ) (I,-\alpha) ( I , − α ) at b + 1 b+1 b + 1 ( b + 1 < n ) (b+1<n) ( b + 1 < n ) for B t B_t B t to form E t E_t E t ; define M t ( k , j ) = ϕ t ( y j ( t ) − x k ( t ) ) M_t(k,j) = \phi_t(y_j^{(t)} - x_k^{(t)}) M t ( k , j ) = ϕ t ( y j ( t ) − x k ( t ) )
4: ( z , π t ) ← STATICTRANSFER ( d , M t , E t ) (z,\pi_t) \leftarrow\operatorname{STATICTRANSFER}(d,M_t,E_t) ( z , π t ) ← STATICTRANSFER ( d , M t , E t ) (Algorithm 3)
5: d ( j ) ← z ( j ) + u t ( j ) d(j) \leftarrow z(j)+u_t(j) d ( j ) ← z ( j ) + u t ( j ) for all j ∈ [ 0 , n − 1 ] j \in[0,n-1] j ∈ [ 0 , n − 1 ] ; retain π t \pi_t π t if reconstruction is required
6: end for
7: return d d d and retained predecessor arrays
Algorithm 8 Contiguous partitions with internal rewards
1: Compute prefix sums S j = ∑ i = 1 j a i S_j = \sum_{i=1}^{j} a_i S j = ∑ i = 1 j a i ( S 0 = 0 ) (S_0=0) ( S 0 = 0 )
2: for each interaction e ∈ E e \in\mathcal{E} e ∈ E do compute u e = min e u_e=\min e u e = min e , v e = max e v_e=\max e v e = max e , and append rectangle ( [ 0 , u e − 1 ] , [ v e , n ] , − w e ) ([0,u_e-1],[v_e,n],-w_e) ([ 0 , u e − 1 ] , [ v e , n ] , − w e ) end for
3: Define M ( k , j ) = ϕ ( S j − S k ) M(k,j)=\phi(S_j-S_k) M ( k , j ) = ϕ ( S j − S k ) and run Algorithm 4 (or Algorithm 5 for K K K blocks)
Graph modularity. For a loopless undirected graph G = ( [ 1 , n ] , E ) G=([1,n],E) G = ([ 1 , n ] , E ) with edge weights b e ≥ 0 b_e \ge0 b e ≥ 0 , let W = ∑ e b e > 0 W=\sum_e b_e>0 W = ∑ e b e > 0 and d i = ∑ e ∋ i b e d_i=\sum_{e\ni i}b_e d i = ∑ e ∋ i b e . Multiplying Q ( P ) = ∑ I ∈ P ( E ( I ) / W − vol ( I ) 2 / ( 4 W 2 ) ) Q(\mathcal{P})=\sum_{I\in\mathcal{P}}(E(I)/W-\operatorname{vol}(I)^2/(4W^2)) Q ( P ) = ∑ I ∈ P ( E ( I ) / W − vol ( I ) 2 / ( 4 W 2 )) by − 4 W 2 -4W^2 − 4 W 2 gives C ( k , j ) = ( S j − S k ) 2 − 4 W E ( ( k , j ] ) C(k,j)=(S_j-S_k)^2-4WE((k,j]) C ( k , j ) = ( S j − S k ) 2 − 4 W E (( k , j ]) , so Theorem 4.4 with a i = d i a_i=d_i a i = d i , ϕ ( x ) = x 2 \phi(x)=x^2 ϕ ( x ) = x 2 and w e = 4 W b e w_e=4Wb_e w e = 4 W b e computes an optimal linear partition in O ( ( n + m ) L 3 ) O((n+m)L^3) O (( n + m ) L 3 ) time.
In a cyclic order, every partition with at least two blocks has a boundary at one of the n n n gaps, and a partition consisting of a single block is feasible for every starting cut. Choosing a boundary as the start of the linear order puts each block of the cyclic partition in a single interval, so the best of the n n n linear optima is the cyclic optimum. Each rotation returns its modularity as − D [ n ] / ( 4 W 2 ) -D[n]/(4W^2) − D [ n ] / ( 4 W 2 ) , where D [ n ] D[n] D [ n ] is the minimum block cost for the rotated order.
Algorithm 9 Cyclic graph modularity
Set Q ∗ ← − ∞ Q^* \leftarrow-\infty Q ∗ ← − ∞ .
For each gap, rotate the order so that vertex 1 1 1 follows the gap.
For this rotation, run Algorithm 8 with a i = d i a_i=d_i a i = d i , ϕ ( x ) = x 2 \phi(x)=x^2 ϕ ( x ) = x 2 , w e = 4 W b e w_e=4Wb_e w e = 4 W b e .
Retain the best − D [ n ] / ( 4 W 2 ) -D[n]/(4W^2) − D [ n ] / ( 4 W 2 ) and its partition in the cyclic order.
Return the retained partition.
Algorithm 9 translates the selected cuts back to the given order and reuses the storage on each rotation, giving O ( n ( n + m ) L 3 ) O(n(n+m)L^3) O ( n ( n + m ) L 3 ) time and O ( n + m ) O(n+m) O ( n + m ) space.
Weighted cluster editing. Relative to the cost ∑ e b e \sum_e b_e ∑ e b e of deleting every edge, a block I I I pays η \eta η for each missing pair and saves b e b_e b e on each retained edge, giving a contribution η ( ∣ I ∣ 2 ) − ∑ e ⊆ I ( η + b e ) \eta\binom{|I|}{2}-\sum_{e\subseteq I}(\eta+b_e) η ( 2 ∣ I ∣ ) − ∑ e ⊆ I ( η + b e ) , so Theorem 4.4 applies with a i = 1 a_i=1 a i = 1 , ϕ ( x ) = η x ( x − 1 ) / 2 \phi(x)=\eta x(x-1)/2 ϕ ( x ) = η x ( x − 1 ) /2 and w e = η + b e w_e=\eta+b_e w e = η + b e in O ( ( n + m ) L 3 ) O((n+m)L^3) O (( n + m ) L 3 ) time.
Hypergraph objectives. For all-or-nothing HyperLam [30 ] , the objective cut ( P ) + λ ∑ u < v co-clustered μ u μ v \operatorname{cut}(\mathcal{P})+\lambda\sum_{u<v\text{ co-clustered}}\mu_u\mu_v cut ( P ) + λ ∑ u < v co-clustered μ u μ v equals h − λ 2 ∑ i μ i 2 + ∑ I ∈ P [ λ 2 ( ∑ i ∈ I μ i ) 2 − # { e ⊆ I } ] h-\frac{\lambda}{2}\sum_i\mu_i^2+\sum_{I\in\mathcal{P}}[\frac{\lambda}{2}(\sum_{i\in I}\mu_i)^2-\#\{e\subseteq I\}] h − 2 λ ∑ i μ i 2 + ∑ I ∈ P [ 2 λ ( ∑ i ∈ I μ i ) 2 − # { e ⊆ I }] , so Theorem 4.4 with a i = μ i a_i=\mu_i a i = μ i , ϕ ( x ) = λ x 2 / 2 \phi(x)=\lambda x^2/2 ϕ ( x ) = λ x 2 /2 and w e = 1 w_e=1 w e = 1 gives O ( N + ( n + h ) L 3 ) O(N+(n+h)L^3) O ( N + ( n + h ) L 3 ) time for arbitrary ranks. For strict hypergraph modularity [16 ] , the incidence degrees a i = d i a_i=d_i a i = d i have sum N N N , and the objective is
Q H ( P ) = 1 h ∑ I ∈ P [ # { e ⊆ I } − ∑ ρ ≥ 1 h ρ ( vol ( I ) / N ) ρ ] . Q_H(\mathcal{P})=\frac{1}{h}\sum_{I\in\mathcal{P}}\left[\#\{e\subseteq I\}-\sum_{\rho\ge1}h_\rho\left(\operatorname{vol}(I)/N\right)^\rho\right]. Q H ( P ) = h 1 I ∈ P ∑ [ # { e ⊆ I } − ρ ≥ 1 ∑ h ρ ( vol ( I ) / N ) ρ ] .
The polynomial ϕ ( x ) = ∑ ρ ≥ 1 h ρ ( x / N ) ρ \phi(x)=\sum_{\rho\ge1}h_\rho(x/N)^\rho ϕ ( x ) = ∑ ρ ≥ 1 h ρ ( x / N ) ρ is convex on R ≥ 0 \mathbb{R}_{\ge0} R ≥ 0 because its coefficients are nonnegative, and when ρ max = O ( 1 ) \rho_{\max}=O(1) ρ m a x = O ( 1 ) its constant evaluation time gives O ( N + ( n + h ) L 3 ) O(N+(n+h)L^3) O ( N + ( n + h ) L 3 ) total time. At bounded rank, multiplying by N ρ max N^{\rho_{\max}} N ρ m a x gives integer costs of polynomial magnitude for polynomially bounded incidence size, so the computation is exact on the word RAM.
FENNEL with K K K blocks. Since cutweight ( P ) = W − ∑ I ∈ P E ( I ) \operatorname{cutweight}(\mathcal{P})=W-\sum_{I\in\mathcal{P}}E(I) cutweight ( P ) = W − ∑ I ∈ P E ( I ) , Theorem 4.4 with a i = 1 a_i=1 a i = 1 , ϕ ( x ) = β x γ \phi(x)=\beta x^\gamma ϕ ( x ) = β x γ and w e = b e w_e=b_e w e = b e gives O ( m + K ( n + m ) L 3 ) O(m+K(n+m)L^3) O ( m + K ( n + m ) L 3 ) time for K K K blocks when the penalty takes constant time to evaluate.
Theorem B.1 (Unweighted contiguous cluster editing). For a simple graph on n n n ordered vertices with m m m edges, unweighted contiguous cluster editing (η = b e = 1 \eta=b_e=1 η = b e = 1 ) can be solved in O ( n + m ) O(n+m) O ( n + m ) time and O ( n ) O(n) O ( n ) working space beyond the edges, bucketed by their larger endpoint (Algorithm 10).
Proof. Let d j − d_j^- d j − count the neighbors of j j j preceding it and let d I ( j ) d_I(j) d I ( j ) count its neighbors in the last block I I I of an optimal partition of [ 1 , j ] [1,j] [ 1 , j ] . If ∣ I ∣ = ℓ |I|=\ell ∣ I ∣ = ℓ , splitting off { j } \{j\} { j } changes the cost by 2 d I ( j ) − ( ℓ − 1 ) 2d_I(j)-(\ell-1) 2 d I ( j ) − ( ℓ − 1 ) , so optimality gives ℓ − 1 ≤ 2 d I ( j ) ≤ 2 d j − \ell-1\le2d_I(j)\le2d_j^- ℓ − 1 ≤ 2 d I ( j ) ≤ 2 d j − [19 ] . With edges grouped by their larger endpoint j j j , maintaining B [ u ] = # { e d g e s ( u , v ) : u < v ≤ j } B[u]=\#\{edges\ (u,v):u<v\le j\} B [ u ] = # { e d g es ( u , v ) : u < v ≤ j } and scanning k k k down from j − 1 j-1 j − 1 to max { 0 , j − 2 d j − − 1 } \max\{0,j-2d_j^- -1\} max { 0 , j − 2 d j − − 1 } evaluates at most ∑ j = 1 n ( 2 d j − + 1 ) = n + 2 m \sum_{j=1}^n(2d_j^-+1)=n+2m ∑ j = 1 n ( 2 d j − + 1 ) = n + 2 m candidates in O ( n + m ) O(n+m) O ( n + m ) total time.
Theorem B.2 (Finite-support weighted contiguous cluster editing). Let L \mathcal{L} L consist of q q q distinct unordered pairs { u , v } \{u,v\} { u , v } with finite signed weights w u v w_{uv} w uv , including zero weights, and let a block be feasible when every pair of its vertices belongs to L \mathcal{L} L . With W + = ∑ { u , v } ∈ L max { w u v , 0 } W_+=\sum_{\{u,v\}\in\mathcal{L}}\max\{w_{uv},0\} W + = ∑ { u , v } ∈ L max { w uv , 0 } , Algorithm 11 minimizes
W + − ∑ I ∈ P ∑ { u , v } ∈ L u , v ∈ I w u v W_+-\sum_{I\in\mathcal{P}}\sum_{\substack{\{u,v\}\in\mathcal{L}\\u,v\in I}}w_{uv} W + − I ∈ P ∑ { u , v } ∈ L u , v ∈ I ∑ w uv over feasible contiguous partitions in O ( n + q ) O(n+q) O ( n + q ) time using O ( n ) O(n) O ( n ) working space beyond the listed pairs, bucketed by their larger endpoint.
Proof. A feasible block ( k , j ] (k,j] ( k , j ] contains only listed pairs, so if f j − f_j^- f j − counts the listed pairs joining j j j to an earlier vertex, its size satisfies j − k ≤ f j − + 1 j-k\le f_j^-+1 j − k ≤ f j − + 1 and its internal pair count equals ( j − k 2 ) \binom{j-k}{2} ( 2 j − k ) . Scanning k k k down from j − 1 j-1 j − 1 to max { 0 , j − f j − − 1 } \max\{0,j-f_j^- -1\} max { 0 , j − f j − − 1 } and testing this count examines at most ∑ j = 1 n ( f j − + 1 ) = n + q \sum_{j=1}^n(f_j^-+1)=n+q ∑ j = 1 n ( f j − + 1 ) = n + q candidates in O ( n + q ) O(n+q) O ( n + q ) time.
Algorithm 10 Unweighted contiguous cluster editing
Bucket edges ( u , j ) (u,j) ( u , j ) (u < j u<j u < j ) by j j j ; B [ 1.. n ] ← 0 B[1..n]\leftarrow0 B [ 1.. n ] ← 0 ; D [ 0 ] ← 0 D[0]\leftarrow0 D [ 0 ] ← 0
for j = 1 , … , n j=1,\ldots,n j = 1 , … , n do
d ← \quad d\leftarrow d ← size of bucket j j j ; for each ( u , j ) (u,j) ( u , j ) in bucket j j j do B [ u ] ← B [ u ] + 1 B[u]\leftarrow B[u]+1 B [ u ] ← B [ u ] + 1 end for
e ← 0 \quad e\leftarrow0 e ← 0 ; D [ j ] ← + ∞ D[j]\leftarrow+\infty D [ j ] ← + ∞
\quad for k = j − 1 , j − 2 , … , max { 0 , j − 2 d − 1 } k=j-1,j-2,\ldots,\max\{0,j-2d-1\} k = j − 1 , j − 2 , … , max { 0 , j − 2 d − 1 } do
e ← e + B [ k + 1 ] \qquad e\leftarrow e+B[k+1] e ← e + B [ k + 1 ] ; update ( D [ j ] , π [ j ] ) (D[j],\pi[j]) ( D [ j ] , π [ j ]) with ( D [ k ] + ( j − k 2 ) − 2 e , k ) (D[k]+\binom{j-k}{2}-2e,k) ( D [ k ] + ( 2 j − k ) − 2 e , k )
\quad end for
end for
return m + D [ n ] m+D[n] m + D [ n ] and partition reconstructed from $\pi
Algorithm 11 Finite-support contiguous cluster editing
Bucket listed pairs ( u , j , w ) (u,j,w) ( u , j , w ) (u < j u<j u < j ) by j j j ; B c [ 1.. n ] ← 0 B_c[1..n]\leftarrow0 B c [ 1.. n ] ← 0 ; B w [ 1.. n ] ← 0 B_w[1..n]\leftarrow0 B w [ 1.. n ] ← 0 ; D [ 0 ] ← 0 D[0]\leftarrow0 D [ 0 ] ← 0
for j = 1 , … , n j=1,\ldots,n j = 1 , … , n do
f ← f\leftarrow f ← size of bucket j j j ; for each ( u , j , w ) (u,j,w) ( u , j , w ) in bucket j j j do B c [ u ] ← B c [ u ] + 1 B_c[u]\leftarrow B_c[u]+1 B c [ u ] ← B c [ u ] + 1 ; B w [ u ] ← B w [ u ] + w B_w[u]\leftarrow B_w[u]+w B w [ u ] ← B w [ u ] + w end for
c ← 0 c\leftarrow0 c ← 0 ; z ← 0 z\leftarrow0 z ← 0 ; D [ j ] ← + ∞ D[j]\leftarrow+\infty D [ j ] ← + ∞
for k = j − 1 , j − 2 , … , max { 0 , j − f − 1 } k=j-1,j-2,\ldots,\max\{0,j-f-1\} k = j − 1 , j − 2 , … , max { 0 , j − f − 1 } do
c ← c + B c [ k + 1 ] c\leftarrow c+B_c[k+1] c ← c + B c [ k + 1 ] ; z ← z + B w [ k + 1 ] z\leftarrow z+B_w[k+1] z ← z + B w [ k + 1 ]
if c = ( j − k 2 ) c=\binom{j-k}{2} c = ( 2 j − k ) then update ( D [ j ] , π [ j ] ) (D[j],\pi[j]) ( D [ j ] , π [ j ]) with ( D [ k ] − z , k ) (D[k]-z,k) ( D [ k ] − z , k ) end if
end for
end for
return W + + D [ n ] W_++D[n] W + + D [ n ] and partition reconstructed from π \pi π
Matrix product algorithms and proofs
Algorithm 12 Matrix product from negative differences
Initialize empty buckets E 0 , … , E n − 1 E_0,\ldots,E_{n-1} E 0 , … , E n − 1 ; R ( n − 1 , j ) ← 0 R(n-1,j)\leftarrow0 R ( n − 1 , j ) ← 0 , R ( k , 0 ) ← 0 R(k,0)\leftarrow0 R ( k , 0 ) ← 0
for p , q = 0 , … , n − 2 p,q=0,\ldots,n-2 p , q = 0 , … , n − 2 do w p , q ← max { − Δ B p , q , 0 } w_{p,q}\leftarrow\max\{-\Delta B_{p,q},0\} w p , q ← max { − Δ B p , q , 0 } ; if w p , q > 0 w_{p,q}>0 w p , q > 0 then append ( [ 0 , p ] , − w p , q ) ([0,p],-w_{p,q}) ([ 0 , p ] , − w p , q ) to E q + 1 E_{q+1} E q + 1 end if end for
for k = n − 2 , … , 0 k=n-2,\ldots,0 k = n − 2 , … , 0 do for j = 1 , … , n − 1 j=1,\ldots,n-1 j = 1 , … , n − 1 do R ( k , j ) ← R ( k + 1 , j ) + R ( k , j − 1 ) − R ( k + 1 , j − 1 ) + w k , j − 1 R(k,j)\leftarrow R(k+1,j)+R(k,j-1)-R(k+1,j-1)+w_{k,j-1} R ( k , j ) ← R ( k + 1 , j ) + R ( k , j − 1 ) − R ( k + 1 , j − 1 ) + w k , j − 1 end for end for
M ← B + R M\leftarrow B+R M ← B + R ; for i = 0 , … , n − 1 i=0,\ldots,n-1 i = 0 , … , n − 1 do ( C i , ∗ , W i , ∗ ) ← STATICTRANSFER ( A i , ∗ , M , E ) (C_{i,*},W_{i,*})\leftarrow\operatorname{STATICTRANSFER}(A_{i,*},M,E) ( C i , ∗ , W i , ∗ ) ← STATICTRANSFER ( A i , ∗ , M , E ) end for
return C , W C,W C , W
Algorithm 13 Reduction to a squared-distance matrix with discounts
U ← max U\leftarrow\max U ← max absolute entry of A , B A,B A , B ; H ← 2 U + 1 H\leftarrow2U+1 H ← 2 U + 1 ; b ← ⌊ n α / 4 ⌋ b\leftarrow\lfloor n^{\alpha/4}\rfloor b ← ⌊ n α /4 ⌋ ; λ ← 2 n 2 + 1 \lambda\leftarrow2n^2+1 λ ← 2 n 2 + 1 ; initialize C i j ← + ∞ C_{ij}\leftarrow+\infty C ij ← + ∞
If b = 0 b=0 b = 0 , return the direct product. Otherwise partition [ 0 , n − 1 ] [0,n-1] [ 0 , n − 1 ] into groups of size a ≤ b a\le b a ≤ b .
for each group κ 0 , … , κ a − 1 \kappa_0,\ldots,\kappa_{a-1} κ 0 , … , κ a − 1 do
Define A i k ( g ) = A i , κ k A_{ik}^{(g)}=A_{i,\kappa_k} A ik ( g ) = A i , κ k (k < a k<a k < a ) else H H H ; B k j ( g ) = B κ k , j B_{kj}^{(g)}=B_{\kappa_k,j} B k j ( g ) = B κ k , j (k < a k<a k < a ) else 0 0 0
u k ← B k , 0 ( g ) u_k\leftarrow B_{k,0}^{(g)} u k ← B k , 0 ( g ) , v j ← B 0 , j ( g ) − B 0 , 0 ( g ) v_j\leftarrow B_{0,j}^{(g)}-B_{0,0}^{(g)} v j ← B 0 , j ( g ) − B 0 , 0 ( g ) , D p q ← Δ B p q ( g ) D_{pq}\leftarrow\Delta B_{pq}^{(g)} D pq ← Δ B pq ( g ) ; A ^ i k ← λ ( A i k ( g ) + u k ) − k 2 \widehat{A}_{ik}\leftarrow\lambda(A_{ik}^{(g)}+u_k)-k^2 A ik ← λ ( A ik ( g ) + u k ) − k 2
Initialize discount list R ← ∅ R\leftarrow\varnothing R ← ∅ and difference array F [ 0.. n ] ← 0 F[0..n]\leftarrow0 F [ 0.. n ] ← 0
for each ( p , q ) (p,q) ( p , q ) with D p q ≠ 0 D_{pq}\ne0 D pq = 0 do
c ← − λ D p q c\leftarrow-\lambda D_{pq} c ← − λ D pq
if c < 0 c<0 c < 0 then append ( [ p + 1 , n − 1 ] , [ q + 1 , n − 1 ] , − c ) ([p+1,n-1],[q+1,n-1],-c) ([ p + 1 , n − 1 ] , [ q + 1 , n − 1 ] , − c ) to R R R
else append ( [ 0 , p ] , [ q + 1 , n − 1 ] , c ) ([0,p],[q+1,n-1],c) ([ 0 , p ] , [ q + 1 , n − 1 ] , c ) to R R R ; F [ q + 1 ] ← F [ q + 1 ] + c F[q+1]\leftarrow F[q+1]+c F [ q + 1 ] ← F [ q + 1 ] + c end if
end for
Prefix-sum F F F . Use B k j ∗ = ( j − k ) 2 − ∑ ( I , J , w ) ∈ R w 1 { k ∈ I } 1 { j ∈ J } B_{kj}^*=(j-k)^2-\sum_{(I,J,w)\in R}w1\{k\in I\}1\{j\in J\} B k j ∗ = ( j − k ) 2 − ∑ ( I , J , w ) ∈ R w 1 { k ∈ I } 1 { j ∈ J } , materializing it if needed.
Query solver for S ← A ^ ⊗ B ∗ S\leftarrow\widehat{A}\otimes B^* S ← A ⊗ B ∗ ; for all i , j i,j i , j , set C i j ← min { C i j , ⌈ ( S i j − j 2 + λ v j + F [ j ] ) / λ ⌉ } C_{ij}\leftarrow\min\{C_{ij},\lceil(S_{ij}-j^2+\lambda v_j+F[j])/\lambda\rceil\} C ij ← min { C ij , ⌈( S ij − j 2 + λ v j + F [ j ]) / λ ⌉}
end for
return C C C
Proof of Theorem 5.1 . For inputs A , B A,B A , B with entries in [ − U , U ] [-U,U] [ − U , U ] , double telescoping in a group of size a ≤ b = ⌊ n α / 4 ⌋ a\le b=\lfloor n^{\alpha/4}\rfloor a ≤ b = ⌊ n α /4 ⌋ of Algorithm 13 gives B k j ( g ) = u k + v j + R k j B_{kj}^{(g)}=u_k+v_j+R_{kj} B k j ( g ) = u k + v j + R k j with R k j = − ∑ p < k , q < j D p q R_{kj}=-\sum_{p<k,q<j}D_{pq} R k j = − ∑ p < k , q < j D pq . Since B k j ( g ) = 0 B_{kj}^{(g)}=0 B k j ( g ) = 0 for k ≥ a k\ge a k ≥ a , every nonzero D p q D_{pq} D pq has p < a p<a p < a and there are at most a ( n − 1 ) ≤ b ( n − 1 ) a(n-1)\le b(n-1) a ( n − 1 ) ≤ b ( n − 1 ) such terms, whose two sign cases give
λ R k j = F [ j ] − ∑ ( I , J , w ) ∈ R w 1 { k ∈ I } 1 { j ∈ J } . \lambda R_{kj}=F[j]-\sum_{(I,J,w)\in R}w1\{k\in I\}1\{j\in J\}. λ R k j = F [ j ] − ( I , J , w ) ∈ R ∑ w 1 { k ∈ I } 1 { j ∈ J } .
The listed discounts therefore give B k j ∗ = ( j − k ) 2 + λ R k j − F [ j ] B_{kj}^*=(j-k)^2+\lambda R_{kj}-F[j] B k j ∗ = ( j − k ) 2 + λ R k j − F [ j ] , and the identity R k j = B k j ( g ) − u k − v j R_{kj}=B_{kj}^{(g)}-u_k-v_j R k j = B k j ( g ) − u k − v j evaluates each explicit entry in constant time. For every i , k , j ∈ [ 0 , n − 1 ] i,k,j\in[0,n-1] i , k , j ∈ [ 0 , n − 1 ] the sum of the two factor entries is
A ^ i k + B k j ∗ = λ ( A i k ( g ) + B k j ( g ) ) − 2 k j + ( j 2 − λ v j − F [ j ] ) . (11) \widehat{A}_{ik}+B_{kj}^*=\lambda(A_{ik}^{(g)}+B_{kj}^{(g)})-2kj+(j^2-\lambda v_j-F[j]). \tag*{(11)} A ik + B k j ∗ = λ ( A ik ( g ) + B k j ( g ) ) − 2 k j + ( j 2 − λ v j − F [ j ]) . (11)
Let T i j ∗ = ( A ( g ) ⊗ B ( g ) ) i j ∈ Z T^{*}_{ij} = (A^{(g)} \otimes B^{(g)})_{ij} \in\mathbb{Z} T ij ∗ = ( A ( g ) ⊗ B ( g ) ) ij ∈ Z . For any minimizing index k ∗ k^{*} k ∗ , we have 0 ≤ 2 k ∗ j ≤ 2 ( n − 1 ) 2 < λ = 2 n 2 + 1 0 \le2k^{*}j \le2(n-1)^2 < \lambda= 2n^2 + 1 0 ≤ 2 k ∗ j ≤ 2 ( n − 1 ) 2 < λ = 2 n 2 + 1 , so λ T i j ∗ − 2 k ∗ j ∈ [ λ T i j ∗ − 2 ( n − 1 ) 2 , λ T i j ∗ ] \lambda T^{*}_{ij} - 2k^{*}j \in[\lambda T^{*}_{ij} - 2(n-1)^2, \lambda T^{*}_{ij}] λ T ij ∗ − 2 k ∗ j ∈ [ λ T ij ∗ − 2 ( n − 1 ) 2 , λ T ij ∗ ] . For any k k k with A i k ( g ) + B k j ( g ) ≥ T i j ∗ + 1 A^{(g)}_{ik} + B^{(g)}_{kj} \ge T^{*}_{ij} + 1 A ik ( g ) + B k j ( g ) ≥ T ij ∗ + 1 , we have λ ( A i k ( g ) + B k j ( g ) ) − 2 k j ≥ λ T i j ∗ + λ − 2 ( n − 1 ) 2 > λ T i j ∗ \lambda(A^{(g)}_{ik} + B^{(g)}_{kj}) - 2kj \ge\lambda T^{*}_{ij} + \lambda- 2(n-1)^2 > \lambda T^{*}_{ij} λ ( A ik ( g ) + B k j ( g ) ) − 2 k j ≥ λ T ij ∗ + λ − 2 ( n − 1 ) 2 > λ T ij ∗ . Hence S ~ i j = S i j − j 2 + λ v j + F [ j ] \widetilde{S}_{ij} = S_{ij} - j^2 + \lambda v_j + F[j] S ij = S ij − j 2 + λ v j + F [ j ] satisfies λ ( T i j ∗ − 1 ) < S ~ i j ≤ λ T i j ∗ \lambda(T^{*}_{ij} - 1) < \widetilde{S}_{ij} \le\lambda T^{*}_{ij} λ ( T ij ∗ − 1 ) < S ij ≤ λ T ij ∗ , so ⌈ S ~ i j / λ ⌉ = T i j ∗ \lceil\widetilde{S}_{ij}/\lambda\rceil= T^{*}_{ij} ⌈ S ij / λ ⌉ = T ij ∗ exactly. All constructed weights satisfy ∣ D p q ∣ ≤ 4 U |D_{pq}| \le4U ∣ D pq ∣ ≤ 4 U and ∣ F [ j ] ∣ = O ( n 4 U ) |F[j]| = O(n^4U) ∣ F [ j ] ∣ = O ( n 4 U ) , preserving O ( log n ) O(\log n) O ( log n ) -bit word size. Constructing all Q = ⌈ n / b ⌉ = O ( n 1 − α ) Q = \lceil n/b \rceil= O(n^{1-\alpha}) Q = ⌈ n / b ⌉ = O ( n 1 − α ) instances takes O ( n 3 − α ) O(n^{3-\alpha}) O ( n 3 − α ) total time, and invoking the O ( n β ) O(n^\beta) O ( n β ) solver Q Q Q times takes O ( n 1 − α + β ) O(n^{1-\alpha+\beta}) O ( n 1 − α + β ) time.
Table 14.
Proof of Theorem 5.4. Vertex cover. In Algorithm 14, a greedy maximal matching of G − ( B ) G_-(B) G − ( B ) finds at most τ ( B ) \tau(B) τ ( B ) disjoint edges in O ( n 2 ) O(n^2) O ( n 2 ) time, and taking both endpoints of each matched edge yields a vertex cover of size at most 2 τ ( B ) 2\tau(B) 2 τ ( B ) , partitioning rows and columns into p + q ≤ 2 τ ( B ) + 2 p+q \le2\tau(B)+2 p + q ≤ 2 τ ( B ) + 2 intervals. By telescoping (2) , every block R a × J b R_a \times J_b R a × J b contains no negative cell in its interior and is therefore Monge, and adding A i k A_{ik} A ik preserves Monge structure. Applying SMAWK [1 ] to each block costs O ( ∣ R a ∣ + ∣ J b ∣ ) O(|R_a|+|J_b|) O ( ∣ R a ∣ + ∣ J b ∣ ) per row i i i , summing to ∑ a = 1 p ∑ b = 1 q ( ∣ R a ∣ + ∣ J b ∣ ) = n q + n p = O ( n ( τ ( B ) + 1 ) ) \sum_{a=1}^{p}\sum_{b=1}^{q}(|R_a|+|J_b|)=nq+np=O(n(\tau(B)+1)) ∑ a = 1 p ∑ b = 1 q ( ∣ R a ∣ + ∣ J b ∣ ) = n q + n p = O ( n ( τ ( B ) + 1 )) per row and O ( n 2 ( τ ( B ) + 1 ) ) O(n^2(\tau(B)+1)) O ( n 2 ( τ ( B ) + 1 )) overall.
Lower bounds. For s , τ , t s,\tau,t s , τ , t , the padded group matrices in the proof of Theorem 5.1 give B ( g ) B^{(g)} B ( g ) with s ( B ( g ) ) ≤ b ( n − 1 ) ≤ n 1 + α s(B^{(g)}) \le b(n-1) \le n^{1+\alpha} s ( B ( g ) ) ≤ b ( n − 1 ) ≤ n 1 + α , τ ( B ( g ) ) ≤ b ≤ n α \tau(B^{(g)}) \le b \le n^\alpha τ ( B ( g ) ) ≤ b ≤ n α , and pathwidth (hence treewidth) t ( B ( g ) ) ≤ b ≤ n α t(B^{(g)}) \le b \le n^\alpha t ( B ( g ) ) ≤ b ≤ n α using bags R ∪ { c } R \cup\{c\} R ∪ { c } where R R R is the set of active row gaps. For maximum degree Δ − \Delta_- Δ − , partition rows and columns into Q = ⌈ n / b ⌉ Q=\lceil n/b\rceil Q = ⌈ n / b ⌉ blocks I 0 , … , I Q − 1 I_0,\ldots,I_{Q-1} I 0 , … , I Q − 1 and J 0 , … , J Q − 1 J_0,\ldots,J_{Q-1} J 0 , … , J Q − 1 of size at most b = ⌊ n α / 4 ⌋ b=\lfloor n^\alpha/4\rfloor b = ⌊ n α /4 ⌋ . For g = 0 , … , Q − 1 g=0,\ldots,Q-1 g = 0 , … , Q − 1 , set B ( g ) [ I a , J c ] = B [ I a , J c ] B^{(g)}[I_a,J_c]=B[I_a,J_c] B ( g ) [ I a , J c ] = B [ I a , J c ] if c ≡ a + g ( m o d Q ) c\equiv a+g\pmod Q c ≡ a + g ( mod Q ) and 2 U + 1 2U+1 2 U + 1 otherwise. Every entry of B B B appears in exactly one B ( g ) B^{(g)} B ( g ) , and every row or column gap touches at most two retained blocks of width ≤ b \le b ≤ b , giving Δ − ( B ( g ) ) ≤ 2 b + 2 ≤ n α \Delta_-(B^{(g)}) \le2b+2 \le n^\alpha Δ − ( B ( g ) ) ≤ 2 b + 2 ≤ n α for sufficiently large n n n . Taking the entrywise minimum of A ⊗ B ( g ) A\otimes B^{(g)} A ⊗ B ( g ) over all Q = O ( n 1 − α ) Q=O(n^{1-\alpha}) Q = O ( n 1 − α ) cyclic shifts recovers A ⊗ B A\otimes B A ⊗ B in O ( n 1 − α + β + n 3 − α ) O(n^{1-\alpha+\beta}+n^{3-\alpha}) O ( n 1 − α + β + n 3 − α ) time.
For successive right factors, Algorithm 15 uses the current product as the left factor, so at layer t t t the running time depends on the negative support of B t B_t B t . To recover a path from source i i i to terminal j j j , one starts in column j j j of the last layer and reads the stored witnesses in reverse order, keeping the source fixed and using each intermediate index as the column in the preceding layer.
When only the final distances are requested, successive products reuse the same working storage.
Table 15.
Product values from Russo’s implicit Monge product
For Monge matrices U , V U,V U , V with constant-time entry access, Russo’s product representation [22 Lemma 6] takes O ( n L + δ ( U ) L 3 ) O(nL+\delta(U)L^3) O ( n L + δ ( U ) L 3 ) construction time and O ( n + δ ( U ) L ) O(n+\delta(U)L) O ( n + δ ( U ) L ) space, where δ ( U ) \delta(U) δ ( U ) is the number of nonzero adjacent differences of U U U , and answers any query to U ⊗ V U\otimes V U ⊗ V in O ( L ) O(L) O ( L ) time.
With w p , q = max { − Δ B p , q , 0 } w_{p,q}=\max\{-\Delta B_{p,q},0\} w p , q = max { − Δ B p , q , 0 } , the prefix sums P ( k , j ) = ∑ p < k , q < j w p , q P(k,j)=\sum_{p<k,q<j}w_{p,q} P ( k , j ) = ∑ p < k , q < j w p , q satisfy Δ P p , q = − w p , q \Delta P_{p,q}=-w_{p,q} Δ P p , q = − w p , q , so M = B − P M=B-P M = B − P is Monge. For a row x = A i , ∗ x=A_{i,*} x = A i , ∗ , the matrix U ( a , k ) = x k + P ( k , n − 1 − a ) U(a,k)=x_k+P(k,n-1-a) U ( a , k ) = x k + P ( k , n − 1 − a ) for 0 ≤ a , k < n 0 \le a,k < n 0 ≤ a , k < n has differences Δ U a , k = w k , n − 2 − a ≥ 0 \Delta U_{a,k} = w_{k,n-2-a} \ge0 Δ U a , k = w k , n − 2 − a ≥ 0 and hence is Monge with core size δ ( U ) = s ( B ) \delta(U) = s(B) δ ( U ) = s ( B ) , while the entries on the antidiagonal of V = U ⊗ M V = U \otimes M V = U ⊗ M satisfy
V ( n − 1 − j , j ) = min 0 ≤ k < n { x k + P ( k , j ) + M ( k , j ) } = ( x ⊗ B ) j . V(n - 1 - j,j) = \min_{0 \le k < n} \{x_k + P(k,j) + M(k,j)\} = (x \otimes B)_j . V ( n − 1 − j , j ) = 0 ≤ k < n min { x k + P ( k , j ) + M ( k , j )} = ( x ⊗ B ) j .
Querying the n n n antidiagonal entries for each row computes A ⊗ B A \otimes B A ⊗ B in O ( n 2 L + n s L 3 ) O(n^2L + nsL^3) O ( n 2 L + n s L 3 ) time and O ( n 2 + s L ) O(n^2 + sL) O ( n 2 + s L ) space using the implicit products, and the envelope sweep of Algorithm 12 computes the values and witnesses in the same time with O ( n 2 ) O(n^2) O ( n 2 ) space.
Further questions
Updates for internal rewards. The three logarithmic factors in O ( ( n + r ) L 3 ) O((n + r)L^3) O (( n + r ) L 3 ) come from visiting the ancestors at the boundary of an interval, searching for a switch at each such ancestor, and evaluating an envelope at each search step. For an internal reward at j = max e j = \max e j = max e , the affected rows satisfy k < min e ≤ j k < \min e \le j k < min e ≤ j , so all earlier events miss row j − 1 j - 1 j − 1 and the sweep can activate it with D [ j − 1 ] D[j - 1] D [ j − 1 ] before processing the current bucket, including singleton interactions, using the envelope tree alone.
Finding rectangle representations. For a cost array supplied by an entry oracle, open problems include determining the number of queries needed to locate N ( C ) \mathcal{N}(C) N ( C ) and finding a representation with the smallest number of signed rectangles, accounting for cancellation where rectangles overlap.
AI assistance
The author used GPT-6-Astra and GPT-6.1-Sol to assist with literature searches and proofs for an earlier version and takes responsibility for the content of the paper.