January 01, 1970
Given a graph, computing distances and reachabilities from a small set of vertices to the whole graph is an important primitive both in theory and in practice. In this paper, we study this problem in various important settings.
In undirected unweighted graphs, while computing single-source shortest path (SSSP) requires \(O(n^2)\) time in dense graphs, all-pairs shortest paths (APSP) can be computed in \(\hat{O}(n^\omega) = O(n^{2.372})\) time [Seidel ’95] providing significant savings over running \(n\) SSSP instances separately. However, if one needs to compute multiple-source shortest paths (MSSP) from a set of \(n^\sigma\) vertices, the previously best known running time was \(\hat{O}(\min\{n^\omega, n^{2 + \sigma}\})\): either by running APSP or running SSSP from each of the \(n^\sigma\) sources. On the other hand, a standard reduction shows that computing MSSP from \(n^\sigma\) sources is at least as hard as computing the Boolean matrix product between an \(n^\sigma \times n\) matrix and an \(n \times n\) matrix. This lower bound has a gap from the state-of-the-art algorithm and therefore, MSSP can potentially be solved much faster. The first main result of our paper is an algorithm for MSSP on undirected unweighted graphs that matches this lower bound. In particular, using fast rectangular matrix multiplication, our algorithm runs in \(\hat{O}(n^{\omega(\sigma, 1, 1)})\) time, which gives a smooth interpolation between the SSSP algorithm and the APSP algorithm. We also extend our algorithm to the case where the graph has small integer weights. The main technical tool behind our first main result is a novel graph decomposition, which may be of independent interest. As applications, we improve the state-of-the-art running times for hop-sets construction and computing \(+4\)-distance emulators.
Next, we study the multiple-source reachability problem, where we need to determine whether a given set of \(n^\sigma\) vertices can reach each of the vertices in a given directed graph. Multiple-source reachability can also be solved in \(\hat{O}(\min\{n^\omega, n^{2 + \sigma}\})\) time, and similarly is as hard as computing Boolean matrix product between an \(n^\sigma \times n\) matrix and an \(n \times n\) matrix. [Elkin and Trehan ’24, ’25] gave the first nontrivial algorithm for multiple-source reachability that runs in \(\hat{O}(n^{1+2\omega(\sigma, 1, 1) / 3})\) time. This only beats the trivial \(\hat{O}(\min\{n^\omega, n^{2 + \sigma}\})\) time for a restricted range of \(\sigma\). We significantly improve their results, by giving an algorithm that runs in \(\hat{O}(n^{\omega(\sigma, 1, 1)})\) time, again matching the running time for Boolean matrix product. Our algorithm for multiple-source reachability can be generalized to MSSP on DAGs with small integer weights. As an application, we provide an \(O(n^{2.084})\) time algorithm for computing an \(\widetilde{O}(n)\)-size shortcut set that reduces diameter to \(O(n^{1/3})\), improving the previous \(\widetilde{O}(n^{7/3})\) time algorithm [Kogan and Parter ’22, ’23].
Computing shortest paths is among the most fundamental problems in computer science. Many of its variants have been studied in the literature, and the All-Pairs Shortest Paths (APSP) problem is one of the most fundamental variants and has been extensively studied.
In APSP, one needs to compute the distance between every pair of nodes in a given \(n\)-vertex graph.2 One could run Dijkstra’s algorithm \(n\) times to obtain an \(O(n^{3})\) running time. An alternative classical algorithm, the Floyd–Warshall algorithm, also achieves an \(O(n^3)\) running time. A long series of works (e.g. [1]–[11]) improved poly-logarithmic factors over the classic \(O(n^3)\) running time, culminating in the current fastest algorithm by Williams [12] with \(n^3 / 2^{\Theta(\sqrt{\log n})}\) running time for general weighted graphs, a super poly-logarithmic improvement over the classic \(O(n^3)\) running time. Due to the lack of polynomial improvements, the APSP hypothesis, stating that there is no \(O(n^{3-\varepsilon})\) time algorithm for any \(\varepsilon>0\) that computes APSP for \(n\)-node graphs, is among the most popular hypotheses in Fine-Grained Complexity.
Faster algorithms are known in unweighted graphs. If the graph is undirected, Seidel [13] gave an algorithm computing APSP in \(\widehat{O}(n^{\omega})\) time.3 More generally, on undirected graphs with positive integer weights bounded by \(B\), APSP can be computed in \(\widehat{O}(Bn^{\omega})\) time [15], [16]. For directed unweighted graphs, the current fastest algorithm was designed by Zwick [17], which runs in \(O(n^{2.528})\) time.
A simpler version of distance problems is reachability problems, where one needs to decide whether a vertex can reach another vertex. All-Pairs Reachability, also popularly known as transitive closure, is another fundamental problem in graph algorithms. It is known to be equivalent to the Boolean Matrix Multiplication problem, and can be solved in \(\widehat{O}(n^\omega)\) time [18], [19].
Computing all the pairwise distances (resp. reachability) gives full distance (resp. reachability) information of the graph, but it also comes with a cost: it is computationally expensive. In contrast, computing the distance between a fixed pair of vertices only takes near-linear time in all the variants mentioned above, though it gives much less information than APSP. A natural question is to study the intermediate cases:
Question 1. Can we compute some distances faster than all distances?
Graphs arising in theory and practice applications often contain a small set of hot spots, where distances between these hot spots and other vertices are more likely to be queried. For instance, in the network connecting all locations in a city, distances from places like grocery stores, shopping malls and parks are more likely to be queried than distances between two residential buildings. In theory, many applications using distance computations only need distances from a fixed small set of vertices to other vertices (e.g. approximate APSP [20]–[24], approximate diameter [25]–[27] and shortcut sets and hopsets [28]).
Motivated by these applications, we study the multiple source version of distance and reachability problems. More formally, we study:
Definition 1 (Multiple Source Shortest Paths / Reachability). Given graph \(G = (V, E)\) and a set of sources \(S_{\mathrm{in}} \subseteq V\), compute \(\mathrm{dist}(s, v)\) for all \(s \in S_{\mathrm{in}}\) and \(v \in V\). In the reachability version of the problem, we only need to determine if the distance is \(\infty\) or not.
Our first result is for Multiple-Source Shortest Paths in undirected unweighted graphs. There are two straightforward algorithms to solve MSSP: we can either solve SSSP for every \(s \in S_{\mathrm{in}}\), or solve APSP. For undirected graphs, there were no other known algorithms besides these two approaches, to the best of our knowledge. This leads to the following question that motivated our work, instantiating a specific instance of 1.
Is there an MSSP algorithm faster than \(\widehat{O}(\min(|S_{\mathrm{in}}|m, n^{\omega}))\)?
We answer this question in the affirmative, giving the first algorithm that beats this running time. In fact, our algorithm is essentially optimal, by tying the running time of our algorithm to Boolean matrix multiplication.
theoremMSSP MSSP on undirected unweighted graphs is equivalent to \(\mathrm{BMM}(|S_{\mathrm{in}}|, n, n)\), up to \(n^{o(1)}\) factors, for randomized algorithms.4 In particular, there is a randomized algorithm computing MSSP on undirected, unweighted graphs in \(n^{o(1)}\mathsf{T}_{\mathrm{BMM}}\left(|S_{\mathrm{in}}|, n, n \right)\) time.
Here, \(\mathrm{BMM}(a, b, c)\) denotes Boolean matrix product instances between \(a \times b\) matrices and \(b \times c\) matrices, and \(\mathsf{T}_{\mathrm{BMM}}(a, b, c)\) denotes the running time of such instances. In particular, \(\mathsf{T}_{\mathrm{BMM}}(a, b, c)\) can be upper bounded by the running time for computing products of general \(a \times b\) and \(b \times c\) matrices, utilizing fast matrix multiplication algorithms (see 1 for an illustration of the quantitative improvements we achieve). The reduction from Boolean matrix multiplication to MSSP in the above theorem can be achieved with standard approaches.5 We also extend our algorithm to handle graphs with small integer weights.
theoremMSSPBounded MSSP on undirected graphs with integer edge weights in \([B]\) is equivalent to \(\mathrm{MPP}(|S_{\mathrm{in}}|, n, n \mid B)\), up to \(n^{o(1)} \log B\) factors, for randomized algorithms.6 In particular, if \(B \leqslant\mathrm{poly}(n)\), there is a randomized algorithm computing MSSP on undirected graphs with integer edge weights in \([B]\) in \(n^{o(1)} \mathsf{T}_{\mathrm{MPP}}\left(|S_{\mathrm{in}}|, n, n \mid B \right)\) time.
Here, \(\mathrm{MPP}(|S_{\mathrm{in}}|, n, n \mid B)\) denotes Min-Plus product between an \(|S_{\mathrm{in}}| \times n\) matrix and an \(n \times n\) matrix, whose entries are from \([B] \cup \{\infty\}\), and \(\mathsf{T}_{\mathrm{MPP}}(|S_{\mathrm{in}}|, n, n \mid B)\) denotes the running time of such instances. It is known that \(\mathsf{T}_{\mathrm{MPP}}(a, b, c \mid B) = \widetilde{O}\left(B \mathsf{T}_{\mathrm{MUL}}(a, b, c)\right)\) [16].
Our algorithms give a smooth interpolation between the SSSP algorithm and the APSP algorithms [13] and [15]. When \(s = n\), our algorithm serves as an alternative algorithm for APSP in undirected graphs with unit or small integer weights (See [29] for another alternative algorithm).
The key technical ingredient of our algorithms is a novel low diameter decomposition, which may be of independent interest. We define the notion of a low diameter small neighborhood decomposition. We say \(V_1 \sqcup \dots \sqcup V_{k}\) is a \((d, \phi)\)-low diameter small neighborhood decomposition if (1) \(\mathrm{diam}(G[V_i]) \leqslant d\) for all \(i\), and (2) \(\sum_{i} |N(V_i)| \leqslant\phi n\). While the first condition is reminiscent of standard low diameter decompositions, the second condition is different: instead of requiring that the number of edges between clusters is small (see e.g. [30]), our decomposition requires that the neighborhoods of the clusters are small. In particular, while there may be many edges incident to any given cluster, we ensure that they do not expand and hit too many distinct vertices. Note that our bound on the neighborhood size is global rather than local, there may be clusters where \(|N(V_i)| > \phi |V_i|\), but the sum of the neighborhoods is at most \(\phi n\). We show how to obtain an \((n^{o(1)}, n^{o(1)})\)-low diameter small neighborhood decomposition in \(n^{2 + o(1)}\) time.
theoremDecomposition There is a randomized \(n^{2 + o(1)}\) time algorithm that computes a \(\left(2^{O\left(\sqrt{\log n}\right)}, 2^{O\left(\sqrt{\log n}\right)}\right)\)-low diameter small neighborhood decomposition.
We also give some natural applications of our MSSP algorithm. We obtain improvements over the state-of-the-art algorithms with simple reductions, establishing the practical impact of the MSSP problem (see 5.3 for formal statements).
A (weighted) set of edges \(F\) is a \(\beta\)-hop-set for graph \(G = (V, E)\) if every pair of vertices \((u, v)\) in \(H = (V, E \cup F)\) has the same distance as in \(G\) and there exists a shortest path of at most \(\beta\) hops. Research in hop-sets (and the related concept of shortcut sets) aims to minimize both the size of the hop-set (ideally linear) and the hop diameter \(\beta\). A folklore sampling algorithm produces \(\beta\)-hop-sets of size \(n^2/\beta^{2}\): sample a set \(S\) of \(n/\beta\) vertices, and add all edges between \((u, v) \in S \times S\) with weight \(\mathrm{dist}(u, v)\). In particular, we may obtain an \(\widetilde{O}\left(n^{1/2}\right)\)-hop-set of size \(\widetilde{O}\left(n\right)\). Bodwin and Hoppenworth showed that the folklore sampling is optimal up to polylogarithmic factors: any exact hop-set of size \(\widetilde{O}\left(n\right)\) must have \(\beta = \widetilde{\Omega}\left(n^{1/2}\right)\) [31].
However, the sampling algorithm does not compute a hop-set efficiently, since previous algorithms for computing all distances between \(S \times S\) for \(S\) of size \(\sqrt{n}\) require time \(\widehat{O}(\min(n^{2.5}, n^{\omega})) = O(n^{2.372})\). Our improved MSSP algorithm allows us to compute all \(S \times S\) distances in time \(n^{\omega(0.5, 1, 1)} = O(n^{2.043})\) [14].7
Emulators are sparse graphs that faithfully preserve the distances of a graph. Formally, given a graph \(G=(V,E)\), a (possibly weighted) set of edges \(F\) is a \(+k\)-emulator if \(\mathrm{dist}_{G}(u, v) \leqslant\mathrm{dist}_{(V, F)}(u, v) \leqslant\mathrm{dist}_{G}(u, v) + k\) for all pairs of vertices \(u, v\). Emulators (and related constructions such as graph spanners) have been the subject of intense study since their introduction [32], and have been useful objects with many applications, including compact routing schemes [33]–[37], distance oracles [38], [39], and broadcasting [40].
Several constructions of additive emulators are known: \(+2\)-emulators of size \(\widetilde{O}\left(n^{3/2}\right)\) [41], \(+4\)-emulators of size \(\widetilde{O}\left(n^{4/3}\right)\) [42], and \(+6\)-emulators of size \(\widetilde{O}\left(n^{4/3}\right)\) [43]. We remark that both the \(+2\) and \(+6\) constructions are spanners (\(F\) is a subset of \(E\)). However, the sparsest \(+4\)-spanner known has size \(\widetilde{O}\left(n^{7/5}\right)\) [44]. Furthermore, it is known that no emulator (or any data structure) of size \(n^{4/3 - \Omega(1)}\) can achieve error \(k = n^{o(1)}\) [45]. Thus, significant effort has been devoted to characterizing the additive error of emulators of linear size [46]–[52].
Both the \(+2\) and \(+6\)-emulators can be constructed in near-linear time \(\widetilde{O}\left(n^2\right)\) [42], [53]. However, the best known algorithm for constructing the \(+4\)-emulator requires time \(\widetilde{O}\left(n^{7/3}\right)\) [42]. With our MSSP algorithm, we obtain a construction in time \(\widehat{O}(n^{\omega(2/3, 1, 1)}) = O(n^{2.1321})\) [14].
In the Multiple-Source Reachability problem, the goal is to determine whether \(s\) can reach \(v\) for every pair \((s, v) \in S_{\mathrm{in}} \times V\). As all-pairs reachability can be solved in \(\widehat{O}(n^\omega)\) time [18], [19], and single-source reachability can be solved in \(O(m)\) time, Multiple-Source Reachability can be solved in \(\widehat{O}(\min(|S_{\mathrm{in}}| m, n^\omega))\) time, similar to MSSP on undirected unweighted graphs. Standard reduction from \(\mathrm{BMM}(S_{\mathrm{in}}, n, n)\) also works for Multiple-Source Reachability, establishing an \(\Omega(\mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, n, n))\) lower bound.
Recently, Elkin and Trehan [54], [55] gave an alternative algorithm for Multiple-Source Reachability. Their algorithm runs in \(\widehat{O}\left(n \mathsf{T}_{\mathrm{MUL}}(S_{\mathrm{in}}, n, n)^{2/3}\right)\), which beats \(\widehat{O}(\min(S_{\mathrm{in}} m, n^\omega))\) for certain values of \(|S_{\mathrm{in}}|\), but unfortunately never meets the \(\Omega(\mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, n, n))\) lower bound (see 1).
In our second main result, we design an algorithm for Multiple-Source Reachability that matches the \(\Omega(\mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, n, n))\) lower bound.
theoremMultiSourceReach Multiple Source Reachability is equivalent to \(\mathrm{BMM}(|S_{\mathrm{in}}|, n, n)\), up to \(\mathrm{polylog}(n)\) factors. In particular, there is a deterministic algorithm computing Multiple-Source Reachability in \(\widetilde{O}\left(\mathsf{T}_{\mathrm{BMM}}\left(|S_{\mathrm{in}}|, n, n \right)\right)\) time.
The following figure illustrates a comparison of our algorithm with the baseline algorithm and the algorithm of Elkin and Trehan [54], [55].
Finally, we study MSSP on directed unweighted graphs, whose running time landscapes seem to be more complicated. Consider APSP as an example. APSP for undirected unweighted graphs runs in \(\widehat{O}(n^\omega)\) time [13], while APSP for directed unweighted graphs runs in \(\widehat{O}(n^{2+\mu})\) time [17], where \(\mu \le 0.528\) [14] is the solution to \(\omega(1, \mu, 1) = 2 + \mu\). As we can see, even representing the running time requires more effort in the directed case.
One can rephrase the running time of Zwick’s algorithm as \[\widetilde{O}\left(\max_{1 \le t \le n} \mathsf{T}_{\mathrm{MPP}}(n, t, n \mid n / t)\right),\] as observed in [29]. In fact, [29] showed that the running time for APSP in directed unweighted graphs is exactly \[\widetilde{\Theta}\left(\max_{1 \le t \le n} \mathsf{T}_{\mathrm{MPP}}(n, n/t, n \mid t)\right).\] Grandoni and Vassilevska Williams [56] gave an algorithm that can solve MSSP on directed unweighted graphs8, and the running time of their algorithm can be phrased as (let \(s = |S_{\mathrm{in}}|\)) \[\label{eq:GV-time} \widetilde{O}\left(\max_{1 \le t \le n} \mathsf{T}_{\mathrm{MPP}}(s + t, t, n \mid n / t)\right),\tag{1}\] Based on the approach in [29], we can show the following lower bound for MSSP on directed unweighted graphs: \[\label{eq:directed-lower-bound} \Omega\left(\max_{1 \le t \le n} \mathsf{T}_{\mathrm{MPP}}(s, t, n \mid n / \min(s, t), n / t)\right),\tag{2}\] where \(\mathsf{T}_{\mathrm{MPP}}(a, b, c \mid B_1, B_2)\) denotes the running time for Min-Plus product instances between an \(a \times b\) matrix with entries from \([B_1] \cup \{\infty\}\) and a \(b \times c\) matrix with entries from \([B_2] \cup \{\infty\}\).
Grandoni and Vassilevska Williams’s algorithm [56] is actually optimal for sufficiently large \(s\). To see this, let \(s\) be large enough so that the maximizer \(t^*\) for 1 is less than or equal to \(s\). In this case, their running time simplifies to \(\widetilde{O}\left(\mathsf{T}_{\mathrm{MPP}}\left(s, t^*, n \mid n / t^*\right)\right)\), which matches \(\mathsf{T}_{\mathrm{MPP}}(s, t, n \mid n / \min(s, t), n / t)\) by setting \(t = t^*\). On the other hand, their running time is not optimal for small values of \(s\). By setting \(t = n\) in 1 , their running time is not better than \(\widetilde{O}\left(\mathsf{T}_{\mathrm{MPP}}\left(n, n, n \mid 1\right)\right) = \widetilde{\Theta}\left(\mathsf{T}_{\mathrm{BMM}}\left(n, n, n\right)\right)\). Hence, using fast matrix multiplication for Boolean matrix product (this is the currently best known algorithm for Boolean matrix product), their running time always has an \(n^\omega\) term, even for small values of \(s\).
We improve [56]’s algorithm for small values of \(s\), in the important special case of directed acyclic graphs:
theoremDAGMSSP There is a deterministic algorithm computing MSSP on unweighted directed acyclic graphs in \(\widetilde{O}\left(\mathsf{T}_{\mathrm{MPP}}(|S_{\mathrm{in}}|, n, n \mid n, 1)\right)\) time.
Surprisingly, even though the running time expression for [thm:dag-mssp] is quite different from 2 , the numerical values of the exponents in \(n\) appear to match for small values of \(s\), utilizing the currently best known algorithm for Min-Plus product between two matrices that can have potentially different entry bounds. In fact, if we take the minimum of [56]’s algorithm and [thm:dag-mssp], the upper and lower bounds appear to be numerically matching for all values of \(s\)! Of course, this does not establish a formal lower bound, as there might be better algorithms for such Min-Plus product instances. See 7 for details.
A set of edges \(F\) is a \(D\)-shortcut-set for graph \(G = (V, E)\) if \(H = (V, E \cup F)\) has the same transitive closure as \(G\) and \(\mathrm{diam}(G \cup F) \leqslant D\). For a directed graph, \(\mathrm{diam}(G) = \max_{(u, v) \in \mathrm{TC}(G)} \mathrm{dist}(u, v)\) is the maximum distance between any two vertices for \((u, v) \in \mathrm{TC}(G)\), where \(\mathrm{TC}(G)\) is the transitive closure of \(G\). Shortcut sets have applications in reachability and shortest paths computation in many settings [57]–[64]. Similar to exact hop-sets, a folklore sampling algorithm yields a shortcut set of diameter \(O(\sqrt{n})\) and size \(\widetilde{O}\left(n\right)\). A breakthrough result of Kogan and Parter [65] showed that in fact there exist shortcut sets of size \(\widetilde{O}\left(n\right)\) and diameter \(O(n^{1/3})\), while no linear size shortcut set can achieve diameter \(o(n^{1/4})\) [31], [66]. As with hop-sets, known algorithms for computing shortcut sets are not optimal, with the current best algorithm computing diameter \(D\)-shortcut-sets of size \(\widetilde{O}\left(n^2/D^3 + n\right)\) in time \(\widetilde{O}\left(mn/D^2\right) = \widetilde{O}\left(n^3 / D^2\right)\) whenever \(D = O(\sqrt{n})\) [67] ([68]’s running time is the same for dense graphs). As an application of [thm:dag-mssp], we compute shortcut-sets in dense graphs of diameter \(D\) and size \(\widetilde{O}\left(n^2/D^3 + n\right)\) in time \(\widetilde{O}\left(\mathsf{T}_{\mathrm{MPP}}(n/D^2, n, n \mid D, 1)\right)\) (see 12). Our algorithm is faster than [67] for all values of \(D = O(\sqrt{n})\), as illustrated in 2. For the important case \(D = n^{1/3}\), our running time is \(O(n^{2.064})\).
1 is a long-term research paradigm that has been approached from many angles:
Single-Source Shortest Paths (SSSP): The most classical and successful example [69], [70], SSSP computes a set of \(n\) distances from \(s\).
Extremal distances: The diameter, radius, and eccentricities are well-studied problems in distance computation, resulting in both approximation algorithms [25]–[27], [71] and hardness results [25], [72], [73].
\(n\)-Pairs Shortest Paths (NPSP): Given \(n\) pre-specified pairs of vertices \((s_i, t_i)\), compute \(\mathrm{dist}(s_i, t_i)\) for all \(i\). In contrast to SSSP, the NPSP problem computes \(n\) arbitrary pre-specified distances. The study of NPSP was initiated by [41], with several recent works reigniting interest in the question [74], [75].
Distance Oracles: Preprocess \(G\) so that given any query \((u, v)\), return \(\mathrm{dist}(u, v)\) efficiently. Distance oracles capture the setting where we do not know what distances are interesting in advance. A long line of work has established a variety of approximation algorithms [38], [76]–[81] and hardness results [82]–[84].
We conclude the introduction with some open questions.
We establish an equivalence between BMM and MSSP on unweighted, undirected graphs. Can a similar equivalence (with some other matrix product) be established for MSSP on directed graphs? Concretely, can [thm:dag-mssp] be generalized to compute shortest paths on directed graphs (not necessarily DAGs)?
In our work, we have shown that a \((d, \phi)\)-low diameter small neighborhood decomposition can be computed efficiently, where \(d, \phi = n^{o(1)}\). In principle, it may be possible to obtain a decomposition where \(|N(V_i)| = O(|V_i|)\) and \(\mathrm{diam}(V_i) = O(\log n)\) for all \(V_i\). Can we obtain such a decomposition, and do so efficiently? Even the weaker setting where \(d, \phi = \mathrm{polylog}(n)\) would be interesting.
Our decomposition algorithm runs in \(n^{2 + o(1)}\) time, which is efficient for dense graphs, but is inefficient on sparse graphs. Can we compute a low diameter small neighborhood decomposition in \(m^{1 + o(1)}\) time? Are there other applications of low diameter small neighborhood decompositions?
Currently, our algorithm for computing MSSP is randomized, since our algorithm for computing our low diameter small neighborhood decomposition requires randomness. Can we derandomize our low diameter small neighborhood decomposition algorithm?
We use MSSP to develop faster algorithms for hop-set, shortcut-set, and distance emulator constructions. It would be interesting to find further applications of an efficient MSSP algorithm.
In 2, we give an overview of our main results and techniques. In 4, we present our algorithm for computing low diameter small neighborhood decompositions. In 5, we give our algorithms for computing MSSP on undirected graphs and their applications. In 6, we present our algorithms on directed graphs and their applications.
We give an overview of our techniques. Recall that our goal is to design an MSSP algorithm that performs better than the naive \(\widetilde{O}\left(\min(|S_{\mathrm{in}}|n^2, n^{\omega+o(1)})\right)\) time obtained by either running SSSP from every source or computing APSP. We begin with a simple algorithm that makes an improvement for some regimes of \(|S_{\mathrm{in}}|\).
Our simple algorithm relies on two key observations: (1) MSSP can be computed efficiently on graphs with small diameter, and (2) MSSP can be computed efficiently when each layer of the shortest path tree is small. On graphs with diameter at most \(D\), we can compute MSSP by taking the adjacency matrix and computing the matrix product \(A[S, V] A^{d}\) for every \(d \le D\) in \(O\left(D \mathsf{T}_{\mathrm{MUL}}(|S_{\mathrm{in}}|, n, n)\right)\) time by iteratively multiplying the adjacency matrix \(A\) on the right. In graphs where each layer of the shortest path tree (i.e. \(\left\{ v \textrm{ s.t. }\mathrm{dist}(s, v) = \ell \right\}\)) has at most \(T\) vertices, executing SSSP for a single vertex only requires \(O(nT)\) time (in contrast to \(O(n^2)\) in general). This leads us to the following algorithm. Let \(L(s, r) := \left\{ v \textrm{ s.t. }\mathrm{dist}(s, v) = r \right\}\) be the \(r\)-th layer of the shortest path tree from source \(s\).
Let \(T\) be a parameter to be set later. (We will set \(T \gets \sqrt{\mathsf{T}_{\mathrm{MUL}}(|S_{\mathrm{in}}|, n, n)/|S_{\mathrm{in}}|}\)).
Initialize \(L(s, 0) = \left\{ s \right\}\) for all \(s\). Set all \(s\) to active.
(Execute BFS from all \(s\) in parallel.)
While not all distances computed:
If some source \(s\) is active: (Small Layer Case)
Attempt to compute \(L(s, \mathrm{level}(s) + 1)\) by relaxing all edges from \(L(s, \mathrm{level}(s))\).
If \(|L(s, \mathrm{level}(s) + 1)| \leqslant T\), compute \(L(s, \mathrm{level}(s) + 1)\) and increment \(\mathrm{level}(s)\).
If \(|L(s, \mathrm{level}(s) + 1)| > T\), set \(s\) as inactive.
If all sources \(s\) are inactive: (Large Layer Case)
Compute \(L(s, \mathrm{level}(s) + 1)\) simultaneously for all \(s\) by computing \(AB\) where: \[A[s, u] = \mathbb{1}\left[ \mathrm{dist}(s, u) = \mathrm{level}(s) \right],\quad B[u, v] = \mathbb{1}\left[ (u, v) \in E \right]\]
Increment \(\mathrm{level}(s)\) for all \(s\) and set all sources \(s\) to active.
Our algorithm computes BFS in parallel from every source. For each source \(s\), we separately analyze the time required to compute large layers (\(>T\)) and small layers (\(\leqslant T\)) of the shortest path tree. For small layers (layers \(r\) where \(\max(|L(s, r - 1)|, |L(s, r)|, |L(s, r + 1)|) \leqslant T\)) to extend layer \(r\) to \(r + 1\) requires time \(O(|L(s, r)|T)\), which overall requires \(O(|S_{\mathrm{in}}|nT)\). For large layers, we note that each source \(s\) can only have \(O(n/T)\) large layers, and therefore become inactive at most \(O(n/T)\) times. Since we only compute the matrix product when all sources are inactive, all matrix products require \(O\left(\frac{n}{T} \mathsf{T}_{\mathrm{MUL}}(|S_{\mathrm{in}}|, n, n)\right)\) time. Balancing terms, we set \(T \gets \sqrt{\mathsf{T}_{\mathrm{MUL}}(|S_{\mathrm{in}}|, n, n)/|S_{\mathrm{in}}|}\) and obtain a running time of \(O\left(n \sqrt{|S_{\mathrm{in}}|\mathsf{T}_{\mathrm{MUL}}(|S_{\mathrm{in}}|, n, n)}\right)\). For example, for \(|S_{\mathrm{in}}| \leqslant n^{0.32}\), \(\mathsf{T}_{\mathrm{MUL}}(|S_{\mathrm{in}}|, n, n) = n^{2+o(1)}\) [14], which yields a \(\sqrt{|S_{\mathrm{in}}|}n^{2+o(1)}\) running time, improving upon \(O\left(|S_{\mathrm{in}}|n^2\right)\).
The above algorithm suggests a potential more generic approach: when we try to grow the BFS tree of some source by one layer, we could wait until many sources need to do so, and group the computation into a matrix multiplication. To further improve the running time, it is natural to use more thresholds, instead of a single threshold \(T\). Now when we group multiple sources together, we need a better bound on the size of the union of the corresponding layers. In order to really take advantage of batch processing, we need these layers to have large overlaps – if all the layers are disjoint, then batch processing does not help at all. In the above simple improvement, we only perform batch processing for very large layers, and we simply used \(n\) as the upper bound on the size of the union. For smaller layers, why wouldn’t layers of different sources be mostly disjoint (like random sets)? Hence, in order to proceed, we develop some structural insights of undirected unweighted graphs, in particular, a novel low diameter decomposition.
Typically, low diameter decompositions require the number of edges between clusters to be small (see e.g. [30]). For our application however, we will utilize something different: the sum of the size of the neighborhoods of each cluster is almost linear (i.e. \(n^{1 + o(1)}\)).9 Formally, we develop a decomposition \(V_1 \sqcup \dots \sqcup V_k\) of the vertices satisfying:
\(\mathrm{diam}(V_i) = n^{o(1)}\) for all \(i\).
\(\sum_{i} |N(V_i)| = n^{1 + o(1)}\).
Before describing how to obtain such a decomposition (see 1), let us see how it is useful. Recall that we use \(\mathrm{level}(s)\) to index the most recently computed layer of the shortest path tree rooted at \(s\). Now, instead of computing \(L(s, \mathrm{level}(s) + 1)\) from \(L(s, \mathrm{level}(s))\) by considering all pairs of vertices, we compute \(L(s, \mathrm{level}(s) + 1) \cap N(V_i)\) from \(L(s, \mathrm{level}(s)) \cap V_i\) for all \(i\) where \(V_i \cap L(s, \mathrm{level}(s)) \neq \emptyset\). Note that correctness follows from the fact that \(\{V_i\}_{i=1}^k\) cover \(L(s, \mathrm{level}(s))\) so that \(\{N(V_i)\}_{i=1}^k\) cover \(L(s, \mathrm{level}(s) + 1)\).
Since we do not consider \(L(s, \mathrm{level}(s))\) all at once, we need to keep track of which vertices in the layer whose neighborhoods we have already examined. Let \({\cal A}(s)\) denote the vertices in \(L(s, \mathrm{level}(s))\) which we still need to examine, called the active vertices. Note that \({\cal A}(s)\) is initialized to \(L(s, \mathrm{level}(s))\) and each iteration of the while loop removes some \(V_i\) from \({\cal A}(s)\).
We say \(V_i\) is relevant to \(s\) if \(V_i \cap {\cal A}(s) \neq \emptyset\). For each cluster \(V_i\), denote \(\mathrm{score}(i)\) the number of sources \(V_i\) is relevant to. We say a cluster \(V_i\) is ready when \(\mathrm{score}(i) \geqslant\frac{|S_{\mathrm{in}}||N(V_i)|}{n^{1 + o(1)}}\). Observe that there is always one ready cluster. If not, by the second property of our decomposition, we have \(\sum_{i} \mathrm{score}(i) < |S_{\mathrm{in}}|\). However, since there is at least one cluster relevant to each source, we obtain a contradiction via \(\sum \mathrm{score}(i) \geqslant|S_{\mathrm{in}}|\).
We now describe our improved algorithm (see [thm:mssp-reduction] for full algorithm).
Let \({\cal A}(s) \gets L(s, \mathrm{level}(s))\) for all \(s\). (Recall \(\mathrm{level}(s) \gets 0\) and \(L(s, 0) = \left\{ s \right\}\).)
While not all distances computed, select a ready cluster \(V_i\):
Compute \(L(s, \mathrm{level}(s) + 1) \cap N(V_i)\) from \(L(s, \mathrm{level}(s)) \cap V_i\) for all \(s\) that \(V_i\) is relevant to.
Remove \(V_i\) from \({\cal A}(s)\).
For any \({\cal A}(s) = \emptyset\), increment \(\mathrm{level}(s)\) and set \({\cal A}(s) \gets L(s, \mathrm{level}(s))\).
Correctness follows from our discussion above. We proceed to analyze the running time, where we will bound the time required by all iterations of the while loop where \(V_i\) is chosen as the ready cluster.
First, we claim that for any fixed source \(s\), \(V_i\) is relevant to \(s\) for \(n^{o(1)}\) iterations (see 4). This follows from the first property of our decomposition (\(\mathrm{diam}(V_i) \leqslant n^{o(1)}\)) so that \(V_i\) can intersect at most \(n^{o(1)}\) distinct layers of the shortest path tree of \(s\). The result follows from observing that \(V_i\) is relevant to \(s\) for one iteration per layer of the shortest path tree (i.e. one value of \(\mathrm{level}(s)\)).
Second, we claim that \(V_i\) is selected as a ready cluster in \(\frac{n^{1 + o(1)}}{|N(V_i)|}\) iterations (see 5). Let \(T(i)\) denote all iterations where \(V_i\) is selected. Let \(S'(t)\) denote the set of sources \(V_i\) is relevant to in iteration \(t \in T(i)\). Then, over all iterations where \(V_i\) is selected, we have \(\sum_{t} |S'(t)| = |S_{\mathrm{in}}|n^{o(1)}\). On the other hand, since \(V_i\) is ready, \(\mathrm{score}(i) = |S'(t)| \geqslant\frac{|S_{\mathrm{in}}||N(V_i)|}{n}\). Thus, we have \(|T(i)| \leqslant\frac{n^{1 + o(1)}}{|N(V_i)|}\).
We now bound the time required by all iterations where \(V_i\) is selected, breaking our analysis into two cases: small clusters and large clusters. For small clusters with \(|N(V_{i})| \leqslant\frac{n}{|S_{\mathrm{in}}|}\), the \(t\)-th iteration requires time \(O(S'(t)|V_i||N(V_i)|)\). Since \(\sum_{t} S'(t) = |S_{\mathrm{in}}|n^{o(1)}\), we bound the total time as \(\sum_{t} O(S'(t)|V_i||N(V_i)|) = n^{1 + o(1)} |V_i|\). Summing over all small clusters, the total time bound is \(n^{2 + o(1)}\).
For large clusters, the \(t\)-th iteration involves a matrix product of dimension \(S'(t) \times V_i \times N(V_i)\). Summing over all iterations, we obtain (see [lem:mat-mul-convex] for the deduction) \[\sum_{t \in T(i)} \mathsf{T}_{\mathrm{MUL}}(S'(t), V_i, N(V_i)) \le O\left(\frac{n^{1 + o(1)}}{|N(V_i)|} \mathsf{T}_{\mathrm{MUL}}\left( \frac{|S_{\mathrm{in}}||N(V_i)|}{n}, V_i, N(V_i) \right)\right).\] Let \(Q := n / |N(V_i)|\) so that the time is \(n^{o(1)} \cdot Q \mathsf{T}_{\mathrm{MUL}}(|S_{\mathrm{in}}| / Q, n / Q, n / Q)\). Since there are at most \(n^{1 + o(1)}/|N(V_i)|\) clusters of size \(O(|N(V_i)|)\), we may bound the total time over all large clusters as \(n^{o(1)} \cdot Q^2 \mathsf{T}_{\mathrm{MUL}}(|S_{\mathrm{in}}| / Q, n / Q, n / Q)\), which can be upper bounded by \(n^{o(1)} \cdot \mathsf{T}_{\mathrm{MUL}}(|S_{\mathrm{in}}|, n, n)\) as desired (see the running time analysis of [thm:mssp-reduction] for the deduction).
We now describe how to efficiently obtain a low diameter small neighborhood decomposition (1). We say \(V_1 \sqcup \dots \sqcup V_k\) is a \((d, \phi)\)-low diameter small neighborhood decomposition (LDSND) if \(\max_{i} \mathrm{diam}(V_i) \leqslant d\) and \(\sum_{i} |N(V_i)| \leqslant\phi n\) (see 2).
Consider the following algorithm for obtaining a single low diameter cluster. Pick an arbitrary vertex \(v\) and let \(N(v, r) := \left\{ u \in V: \mathrm{dist}(v, u) \leqslant r \right\}\) denote the \(r\)-neighborhood of \(v\). We claim \(|N(v, 3^{k})| \leqslant\phi^{k}\) for some \(k \leqslant\lceil\log_{\phi} n\rceil\). Otherwise \(|N(v, 3^{\lceil\log_{\phi} n\rceil})| > n\) becomes a contradiction (see 3). Setting \(\phi = 2^{O(\sqrt{\log n})}\), we get that \(k \leqslant O(\sqrt{\log n})\) and \(3^{k} \leqslant 2^{O(\sqrt{\log n})}\) so that \(N(v, 3^{k})\) has small diameter.
Motivated by this observation, our decomposition \({\cal C}\) will consist of balls \(N(v, 3^{k})\) for some \(v\) and \(k\). For each \(0 \leqslant k \leqslant\log_{\phi} n\), we sample \(S_{k} \subseteq V\) by including each vertex with probability \(p_{k} \sim \phi^{-k}\). Then, for each \(u \in S_{k}\), we add \(N(u, 3^{k})\) to \({\cal C}\) if \(|N(u, 3^{k} + 1)| \leqslant\phi^{k + 1}\). Since \(|S_{k}| = O(n\phi^{-k})\) with high probability, the total time required is at most \(O(\sum_{k} |S_{k}| \phi^{2k + 2}) = O(\sum_{k} n \phi^{k+2}) = n^{2 + o(1)}\).
Above, we have argued that each set has small diameter. Furthermore, since \(|S_{k}| = O(n\phi^{-k})\) with high probability, we have that \(\sum_{u \in S_{k}} |N(u, 3^{k} + 1)| = O(n \phi) = n^{1 + o(1)}\), as desired.
It remains to argue that every vertex \(v \in N(u, 3^{k})\) for some \(N(u, 3^{k}) \in {\cal C}\). Let \(k \geqslant 1\) be the smallest positive integer satisfying \(|N(v, 3^{k})| \leqslant\phi^{k}\) so that \(|N(v, 3^{k - 1})| > \phi^{k - 1}\). Note that such a \(k\) always exists since \(|N(v, 1)| > 1\) unless \(v\) is an isolated vertex. Then, with high probability, some \(u \in S_{k - 1}\) hits \(N(v, 3^{k - 1})\). Then, since \(\mathrm{dist}(u, v) \leqslant 3^{k - 1}\) and \(2 \cdot 3^{k - 1} + 1 \leqslant 3^{k}\), we have \(|N(u, 3^{k - 1} + 1)| \leqslant|N(v, 2 \cdot 3^{k - 1} + 1)| \leqslant|N(v, 3^{k})| \leqslant\phi^{k}\) , resulting in \(N(u, 3^{k - 1})\) being added to \({\cal C}\), as desired.
Note that the above process gives a covering of the vertices. We can obtain a decomposition by removing duplicated vertices from the clusters.
Finally, we describe how to extend the algorithm to handle weighted graphs with small integer weights bounded by \(B\). Note that an algorithm that computes MSSP on graphs with integer weights bounded by \(\Theta(B)\) also computes the rectangular \((\min, +)\)-product of two integer matrices with entries bounded by \(B\). Given \(S_{\mathrm{in}} \times n\) matrix \(X\) and \(n \times n\) matrix \(Y\), construct a three-layer graph with \(V_1 = S_{\mathrm{in}}, V_2 = [n], V_3 = [n]\) and edges \((s, u)\) for \(s \in V_1, u \in V_2\) with weight \(10B + X[s, u]\) and edges \((u, v)\) for \(u \in V_2, v \in V_3\) with weight \(10B + Y[u, v]\). Then, \(\mathrm{dist}(s, v) = 20B + (X \star Y)[s, v]\) whenever \((X \star Y)[s,v] < \infty\) and is at least \(40B\) otherwise.
Thus, our goal is to develop an algorithm that runs in \(\mathsf{T}_{\mathrm{MPP}}(|S_{\mathrm{in}}|, n, n \mid B) = \widetilde{O}\left(B\mathsf{T}_{\mathrm{MUL}}(|S_{\mathrm{in}}|, n, n)\right)\) time, where \(\mathsf{T}_{\mathrm{MPP}}(n^{a}, n^{b}, n^{c} \mid B)\) denotes the time required to compute the \((\min, +)\)-product between integer matrices of dimension \(n^{a} \times n^{b} \times n^{c}\) with integer entries bounded by \(B\).
We first describe an \(\hat{O}(B^2 \mathsf{T}_{\mathrm{MUL}}(|S_{\mathrm{in}}|, n, n))\) time algorithm. Treat \(G\) as an unweighted graph, and compute an \((n^{o(1)}, n^{o(1)})\)-low diameter small neighborhood decomposition.
Now, fix a source \(s\). To ensure correctness, in order to compute \(L(s, \mathrm{level}(s) + 1)\) we need two modifications to account for the fact that edge weights can be up to \(B\). We need to (1) consider any cluster \(V_i\) that intersects \(L(s, r)\) for any \(\mathrm{level}(s) - B \leqslant r \leqslant\mathrm{level}(s)\), and (2) compute \(N(V_i) \cap L(s, \mathrm{level}(s) + 1)\) via a \(B\)-bounded \((\min, +)\)-product. Revisiting the analysis of our unweighted algorithm, we obtain a running time of \(\hat{O}(B^2 \mathsf{T}_{\mathrm{MUL}}(|S_{\mathrm{in}}|, n, n))\) since (1) implies that \(V_i\) is relevant to \(s\) for \(Bn^{o(1)}\) iterations (in contrast to \(n^{o(1)}\)), while (2) implies that we must use \(B\)-bounded \((\min, +)\)-products in place of a Boolean product.
To ensure that each cluster is relevant to any source \(s\) only for \(n^{o(1)}\) iterations of the while loop, we instead take the following approach. Consider graphs \(G_{b}\) for \(b \leqslant\log B\) consisting of all edges with weight between \(2^{b}\) and \(2^{b + 1}\). We obtain low diameter small neighborhood decompositions for all \(G_{b}\) as unweighted graphs, denoted \({\cal C}_{b} = \left\{ V_{i}^{(b)} \right\}\). Now, while each cluster \(V_{i}^{(b)}\) has diameter \(2^{b}n^{o(1)}\), we only need to consider cluster edges in \(G_{b}\) incident to \(V_{i}^{(b)}\) for every \(2^{b}\) layers of the shortest path tree from \(s\), since each of these edges has weight at least \(2^{b}\). Our final algorithm for bounded weights selects a cluster that is relevant to many sources, and relaxes all edges of the appropriate weight range incident to this cluster. To ensure correctness and efficiency, we carefully manage which vertices are active for each source and edge weight class, ensuring that the shortest path tree of each source is built accurately (see [thm:bounded-weight-mssp] for details).
Our algorithm for Multiple Source Reachability (and MSSP on DAGs) employs a simple recursive scheme. Assume that \(G\) is sorted in topological order. Let \(\mathrm{pred}(\pi, v)\) denote the predecessor of \(v\) in path \(\pi\). For any interval \([L, R]\) of \(\ell\) vertices, we employ a recursive scheme \(\textsf{complete}(G, S_{\mathrm{in}}, L, R)\) with the following input/output conditions:
Input: \(\mathrm{reach}(s, v)\) is computed if there is a path \(\pi\) from \(s \in S_{\mathrm{in}}\) to \(v \leqslant R\) where \(\mathrm{pred}(\pi, v) \leqslant L\).
Output: \(\mathrm{reach}(s, v)\) is computed for all \(s \in S_{\mathrm{in}}\) and \(v \leqslant R\).
Our Multiple Source Reachability algorithm computes \(\textsf{complete}(G, S_{\mathrm{in}}, 0, |V|)\). In this overview, we describe how to compute \(\textsf{complete}(G, S_{\mathrm{in}}, L, R)\). Let \(M = (L+R)/2\) be the midpoint of the interval. Note that we can compute \(\textsf{complete}(G, S_{\mathrm{in}}, L, M)\) since the input condition is satisfied. Our goal is to satisfy the input condition of \(\textsf{complete}(G, S_{\mathrm{in}}, M, R)\) which would satisfy the output condition of \(\textsf{complete}(G, S_{\mathrm{in}}, L, R)\). To do so, we need to ensure \(\mathrm{reach}(s, v)\) is computed for any path \(\pi\) from \(s\) to \(v\) with \(L \leqslant\mathrm{pred}(\pi, v) \leqslant M\). We can do this with a single computation of BMM by constructing matrix \(X\) as a \(S_{\mathrm{in}} \times [L, M]\) containing \(\mathrm{reach}(s, u)\) for \(u \in [L, M]\) and a matrix \(Y\) as a \([L, M] \times [M, R]\) submatrix of the adjacency matrix, ensuring that all paths passing through \([L, M]\) are accounted for. The running time of the recursion is thus \[T(\ell) = 2 T(\ell/2) + \mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, \ell, \ell)\] which yields \(\mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, n, n)\) by appealing to the root-heavy case of the Master Theorem. Our algorithm for MSSP on DAGs employs a similar recursive structure, replacing each BMM instance with an appropriate Min-Plus Product.
Let \([n] = \left\{ 1, \dots, n \right\}\). Let \(\log\) denote the base-2 logarithm, unless stated otherwise. For any set \(S\), let \(|S|\) denote the size of the set. For an empty set, we use the conventions \(\min(\emptyset) = \infty\) and \(\max(\emptyset) = - \infty\). In our algorithms, we use \(x \overset{+}{\gets}y\) to denote \(x \gets x + y\) and \(x \overset{\min}{\gets}y\) to denote \(x \gets \min(x, y)\). For sets, we use \(A \overset{\cup}{\gets}B\) to denote \(A \gets A \cup B\).
For a graph \(G = (V, E)\), we typically use \(n = |V|\) and \(m = |E|\) to denote the number of vertices and edges respectively. We use \(G = (V, E, \mathrm{wt})\) to denote a weighted graph with weight function \(\mathrm{wt}: E \mapsto {\mathbb{Z}}\). For any \(S \subseteq V\), \(E(S)\) denotes all edges incident to some vertex in \(S\). Unless otherwise stated, all graphs are undirected. Furthermore, we assume (without loss of generality) that all graphs are connected.
For any two vertices \(s, t \in V\), let \(\mathrm{dist}_{G}(s, t)\) denote the length of the shortest path from \(s\) to \(t\). When the context is clear, we omit \(G\) and write \(\mathrm{dist}(s, t)\). For any path \(\pi \subseteq G\) (not necessarily shortest), let \(|\pi|\) denote the length, or number of edges, of \(\pi\). For a subset of vertices \(S \subseteq V\) and a vertex \(v \in V\), let \(\mathrm{dist}(S, v) := \min_{s \in S} \mathrm{dist}_{G}(s, v)\). For any vertex \(s \in V\), let \(N(s, r) := \left\{ v \textrm{ s.t. }\mathrm{dist}(s, v) \leqslant r \right\}\) and for a subset of vertices \(S \subset V\), let \(N(S, r) := \left\{ v \textrm{ s.t. }\mathrm{dist}(S, v) \leqslant r \right\}\). Let \(N(v) := N(v, 1)\) and \(N(S) := N(S, 1)\). Let \(\mathrm{diam}_{G}(S) := \max_{s, t \in S} \mathrm{dist}_{G}(s, t)\) denote the diameter of a subset \(S\). For a given vertex \(s \in V\) and distance \(r\), let \(L(s, r) := \left\{ v \textrm{ s.t. }\mathrm{dist}(s, v) = r \right\}\).
Given a matrix \(A\), we let \(A[i, j]\) denote the entry of \(A\) in the \(i\)-th row and \(j\)-th column. Let \(0_{a \times b}\) denote an \(a \times b\) matrix of \(0\)s. Let \(\mathsf{T}_{\mathrm{MUL}}(n_1, n_2, n_3)\) denote the time required to compute a \(n_1 \times n_2 \times n_3\) dimensional matrix product i.e. the product of an \(n_1 \times n_2\) matrix and an \(n_2 \times n_3\) matrix. Given matrices \(A, B\), we let \(AB\) denote the standard matrix product (either Boolean or integer), and \(A \star B\) the \((\min, +)\) (or Min-Plus) matrix product, where \((A \star B)[i,j] = \min_{k} \{A[i,k] + B[k,j]\}\). Let \(\mathsf{T}_{\mathrm{BMM}}(n_1, n_2, n_3)\) denote the time required to compute a \(n_1 \times n_2 \times n_3\) dimensional boolean matrix product, and \(\mathsf{T}_{\mathrm{MPP}}(n_1, n_2, n_3 \mid B_1, B_2)\) the time required to compute the \((\min, +)\) product of a \(n_1 \times n_2\) matrix with entries in \([B_1] \cup \left\{ \infty \right\}\) and a \(n_2 \times n_3\) matrix with entries in \([B_2] \cup \left\{ \infty \right\}\). Let \(\mathsf{T}_{\mathrm{MPP}}(n_1, n_2, n_3 \mid B) := \mathsf{T}_{\mathrm{MPP}}(n_1, n_2, n_3 \mid B, B)\). In some cases, we write \(\mathsf{T}_{\mathrm{BMM}}(A, B, C) := \mathsf{T}_{\mathrm{BMM}}(|A|, |B|, |C|)\) where \(A, B, C\) are sets. We also allow combinations of sets and integers, e.g. for set \(A\) and integers \(n_2, n_3\), \(\mathsf{T}_{\mathrm{BMM}}(A, n_2, n_3) := \mathsf{T}_{\mathrm{BMM}}(|A|, n_2, n_3)\).
In this section, we present an efficient algorithm for computing a low diameter small neighborhood decomposition. We begin by defining the desired properties.
Definition 2. A partition of \(V\) into subsets \(V_{1}, \dots, V_{k}\) is a \((d, \phi)\)-low diameter small neighborhood decomposition (LDSND) of \(G = (V, E)\) if:
(Low Diameter) \(\mathrm{diam}_{G}(V_{i}) \leqslant d\) for all \(i \in [k]\).
(Total Neighborhood Size) \(\sum_{i = 1}^{k} |N(V_{i})| \leqslant\phi n\).
We now give an efficient algorithm for computing a low diameter small neighborhood decomposition.
Theorem 1. For any \(\psi > 1\), there is a randomized \(O\left(n^2 \psi^{4} \log n \log_{\psi} n\right)\) time algorithm that given an \(n\)-vertex \(m\)-edge undirected, unweighted graph \(G\) computes a \((d, \phi)\)-LDSND where \(d = 6 \cdot 3^{\log_{\psi} n}\) and \(\phi= O\left(\psi \log n \log_{\psi} n\right)\) Furthermore, this algorithm computes \(N(V_i)\) for all subsets \(V_i\) in the decomposition.
Proof. We give an algorithm that computes a collection of subsets \(V_1, \dots, V_{k}\) such that (1) \(V = V_1 \cup \dots \cup V_{k}\), (2) \(\mathrm{diam}_{G}(V_i) \leqslant d\) for all \(i\), and (3) \(\sum_{i} |N(V_i)| \leqslant\phi n\). From here, it is easy to observe that by removing duplicate vertices, we obtain a partition that is a \((d, \phi)\)-LDSND, as removing vertices can only reduce the diameter and the total neighborhood size.
First, we show that any vertex \(v\) has a small-diameter neighborhood that does not expand.
Claim 2. For every \(v \in V\), there exists \(0 \leqslant k < \lceil \log_{\psi} n \rceil\) such that \(|N(v, 3^{k + 1})| \leqslant\psi^{k + 1}\) and \(|N(v, 3^{k})| > \psi^{k}\).
Proof. Observe that \(|N(v, 3^{0})| = |N(v, 1)| \ge 2 > \psi^0\) (recall we assume the graph is connected). Also, \(|N(v, 3^{\lceil \log_{\psi} n \rceil})| = n \le \psi^{\lceil \log_{\psi} n \rceil}\). The claim thus follows. ◻
We now argue that an appropriate collection of \(N(v, 3^{k})\) suffice to provide a low diameter small neighborhood decomposition of \(G\). Consider the following procedure.
Let \({\cal C}\gets \emptyset, {\cal N}\gets \emptyset\).
For \(0 \leqslant k < \lceil \log_{\psi} n \rceil\):
Sample a random subset \(S_{k} \subseteq V\) by including each \(u \in V\) with probability \(p_{k} = \min\left(1, \frac{3 \log n}{\psi^{k}}\right)\).
For each \(u \in S_{k}\):
Compute \(N(u, 3^{k} + 1)\) using BFS.
If \(|N(u, 3^{k} + 1)| \leqslant\psi^{k + 1}\): update \({\cal C}\overset{\cup}{\gets}\left\{ N(u, 3^{k}) \right\}\) and \({\cal N}\overset{\cup}{\gets}\left\{ N(u, 3^{k} + 1) \right\}\).
(Whenever \(|N(u, 3^{k} + 1)| > \psi^{k + 1}\), we terminate the invocation of BFS early.)
Return \({\cal C}, {\cal N}\).
We claim that our algorithm returns a low diameter small neighborhood decomposition. We begin with the first property. Let \(v \in V\). Let \(k\) be an arbitrary integer guaranteed by 2. We claim that \(S_{k}\) contains a vertex in \(N(v, 3^{k})\) with high probability. The claim holds trivially whenever \(p_{k} = 1\) (i.e. \(S_{k} = V\)). For \(p_{k} < 1\), since \(|N(v, 3^{k})| > \psi^{k}\), \[\Pr(N(v, 3^{k}) \cap S_{k} = \emptyset) \leqslant\left( 1 - p_{k} \right)^{\psi^{k}} < e^{-p_{k} \psi^{k}} < \frac{1}{n^{3}}.\]
Let \(u \in S_{k} \cap N(v, 3^{k})\). Then, since \(u \in N(v, 3^{k})\), we have \(v \in N(u, 3^{k})\). We now argue that \(N(u, 3^{k}) \in {\cal C}\). To see this, since \(k \geqslant 0\), we have \(N(u, 3^{k} + 1) \subseteq N(v, 2 \cdot 3^{k} + 1) \subseteq N(v, 3^{k + 1})\) so that \(|N(u, 3^{k} + 1)| \leqslant|N(v, 3^{k + 1})| \leqslant\psi^{k + 1}\), as desired. Hence, by union bound, the collection of sets in \({\cal C}\) covers all vertices in \(V\) with probability at least \(1 - 1/n^2\).
Towards the second property, we bound the diameter of each set \(N(u, 3^{k})\) with \(k \leqslant\lceil \log_{\psi} n \rceil\) by \[2 \left( 3^{k} \right) \leqslant 2 \cdot 3^{\lceil \log_{\psi} n \rceil} \leqslant 6 \cdot 3^{\log_{\psi} n} \text{.}\]
Towards the third property, we can bound the size of all \(N(V_{i}) = N(u, 3^{k} + 1)\) by \(\sum_{k} |S_{k}| \psi^{k + 1}\). Using a standard Chernoff bound, we can conclude with high probability that all \(|S_{k}| = O\left(\frac{n \log n}{\psi^{k}}\right)\). In particular, \(\sum_{k} |S_{k}| \psi^{k + 1} = O\left(\psi n \log n \log_{\psi} n\right)\). Thus, we have achieved a \(\left( 6 \cdot 3^{\log_{\psi} n} , O\left(\psi \log n \log_{\psi} n\right) \right)\)-LDSND.
It remains to prove the running time. For a fixed \(u \in S_{k}\), since we terminate whenever \(N(u, 3^{k} + 1) > \psi^{k + 1}\), we can bound the running time of each BFS by \(O\left(\psi^{2k + 2}\right)\) since the number of edges incident to \(N(u, 3^{k})\) can be bounded by \(O(|N(u, 3^{k} + 1)|^2)\). Summing over all \(S_{k}\), the total running time is \[\sum_{k} |S_{k}| \psi^{2k + 2} = O\left(n \psi^{\log_{\psi} n + 4} \log n \log_{\psi} n\right) = O\left(n^{2} \psi^{4} \log n \log_{\psi} n\right) \text{.}\] Above, we have used that \(|S_{k}| = O\left(\frac{n \log n}{\psi^{k}}\right)\) and \(\psi^{k} \leqslant\psi^{\lceil \log_{\psi} n \rceil}\). ◻
From our above theorem, we obtain a specific decomposition.
Proof. Set \(\psi = 2^{\sqrt{\log n}}\) and apply 1. We obtain an \(n^{2} \cdot 2^{O\left(\sqrt{\log n}\right)}\) time algorithm that computes a \(\left(2^{O\left(\sqrt{\log n}\right)}, 2^{O\left(\sqrt{\log n}\right)}\right)\)-LDSND. ◻
We remark that by appropriately setting parameters, we can obtain a low diameter small neighborhood decomposition where exactly one of the diameter and expansion factor is polylogarithmic and both are sub-polynomial. However, for our applications, it suffices to obtain a decomposition where both are sub-polynomial.
In this section, we present our algorithms for MSSP in undirected graphs.
We begin with our algorithm for undirected, unweighted graphs.
theoremMSSPReduction Given a \((d, \phi)\)-low diameter small neighborhood decomposition, there is a deterministic algorithm computing Multiple Source Shortest Paths (MSSP) on undirected, unweighted graphs in time \[O\left(n^{2} \phi d \log n + \mathsf{T}_{\mathrm{BMM}}\left( \frac{|S_{\mathrm{in}}|}{\phi \log n}, n, n \right) \phi^2 d (\log n)^2\right).\]
Combined with [cor:boundary-decomposition], we prove our main result.
Proof of [cor:mssp]. We obtain an \((n^{o(1)}, n^{o(1)})\)-low diameter small neighborhood decomposition in \(n^{2 + o(1)}\) time via [cor:boundary-decomposition]. Applying [thm:mssp-reduction], we compute MSSP in \(n^{o(1)} \cdot \mathsf{T}_{\mathrm{BMM}}\left(|S_{\mathrm{in}}|, n, n\right)\) time. ◻
We prove [thm:mssp-reduction] in the remainder of 5.1. Consider the following procedure.
Input: Graph \(G = (V, E)\), sources \(S_{\mathrm{in}} \subseteq V\), and \((d, \phi)\)-LDSND \({\cal C}= \left\{ V_1, \dots, V_{k} \right\}\).
Let \(S \gets S_{\mathrm{in}}\).
Let \(\hat{L}(s, 0) \gets \left\{ s \right\}, {\cal A}(s) \gets \left\{ s \right\}\), \(\hat{L}(s, 1) \gets \emptyset\), \(\widehat{\mathrm{d}}(s, s) \gets 0, \mathrm{level}(s) \gets 0\), and \(\widehat{\mathrm{d}}(s, v) \gets \infty\) for all \(s \in S, v \in V \setminus \{s\}\).
Let \(\mathrm{score}(i) \gets |\left\{ s \in S \textrm{ s.t. }{\cal A}(s) \cap V_{i} \neq \emptyset \right\}|\) for all \(V_{i}\).
While there exists \(V_{i}\) with \(\mathrm{score}(i) > \frac{|S||N(V_i)|}{2 \phi n}\):
Let \(S' \gets \left\{ s \in S \textrm{ s.t. }{\cal A}(s) \cap V_{i} \ne \emptyset \right\}\).
If \(|N(V_i)| \leqslant\frac{\phi n \log n}{|S_{\mathrm{in}}|}\):
Else (\(|N(V_i)| > \frac{\phi n \log n}{|S_{\mathrm{in}}|}\)):
Construct an \(S' \times V_{i}\) matrix \(X\) and a \(V_i \times N(V_{i})\) matrix \(Y\) with entries \[X[s, u] = \mathbb{1}\left[ u \in {\cal A}(s) \right],\quad Y[u, v] = \mathbb{1}\left[ (u, v) \in E \right] \text{.}\]
Compute \(XY\) and for all \((XY)[s, v] = 1\), update \(\widehat{\mathrm{d}}(s, v) \overset{\min}{\gets}\mathrm{level}(s) + 1\).
For all \(s \in S'\):
Update \(\hat{L}(s, \mathrm{level}(s) + 1) \overset{\cup}{\gets}\left\{ v \textrm{ s.t. }\widehat{\mathrm{d}}(s, v) = \mathrm{level}(s) + 1 \right\}\).
Remove \(V_{i}\) from \({\cal A}(s)\) and decrement \(\mathrm{score}(i) \overset{-}{\gets}1\).
If \({\cal A}(s) = \emptyset\):
Update \(\mathrm{level}(s) \overset{+}{\gets}1\), \(\hat{L}(s, \mathrm{level}(s) + 1) \gets \emptyset\).
If \(\bigcup_{r = 0}^{\mathrm{level}(s)} \hat{L}(s, r) = V\): then remove \(s\) from \(S\). Else, set \({\cal A}(s) \gets \hat{L}(s, \mathrm{level}(s))\).
For all \(V_i \cap {\cal A}(s) \neq \emptyset\), increment \(\mathrm{score}(i)\).
Output: \(\widehat{\mathrm{d}}(s, v)\) for all \(s \in S_{\mathrm{in}}\) and \(v \in V\).
Proof of [thm:mssp-reduction]. We prove the correctness and running time of our algorithm.
Beginning with correctness, we argue that our algorithm terminates and upon termination of our algorithm, all distances are correct i.e. \(\widehat{\mathrm{d}}(s, v) = \mathrm{dist}(s, v)\) for all \(s \in S_{\mathrm{in}}, v \in V\).
First, we claim that in every iteration of the while loop \(\widehat{\mathrm{d}}(s, v) \geqslant\mathrm{dist}(s, v)\) for all \(s \in S_{\mathrm{in}}, v \in V\).
Lemma 1. In every iteration of the while loop \(\widehat{\mathrm{d}}(s, v) \geqslant\mathrm{dist}(s, v)\) for all \(s \in S_{\mathrm{in}}, v \in V\).
Proof of 1. Suppose for contradiction that there is some \(s \in S_{\mathrm{in}}\) where \(\widehat{\mathrm{d}}(s, v) < \mathrm{dist}(s, v)\) in some iteration of the while loop. Consider the first iteration of the while loop where a violation \(\widehat{\mathrm{d}}(s, v) < \mathrm{dist}(s, v)\) occurs and let \(v\) be the violating vertex. In particular, at the start of this iteration, we have \(\widehat{\mathrm{d}}(s, v) \geqslant\mathrm{dist}(s, v)\). During this iteration, we update \(\widehat{\mathrm{d}}(s, v) \gets \mathrm{level}(s) + 1 < \mathrm{dist}(s, v)\). By our two update rules, there exists \(u \in {\cal A}(s) \cap V_{i}\) with \((u, v) \in E\). Observe that \({\cal A}(s) \subseteq \hat{L}(s, \mathrm{level}(s))\) so \(u \in \hat{L}(s, \mathrm{level}(s))\). Since \(u \in \hat{L}(s, \mathrm{level}(s))\), we have at the start of this iteration that \(\mathrm{dist}(s, u) \leqslant\widehat{\mathrm{d}}(s, u) \leqslant\mathrm{level}(s)\). By the triangle inequality, for \((u, v) \in E\) we have \(\mathrm{dist}(s, v) \leqslant\mathrm{dist}(s, u) + 1 \leqslant\mathrm{level}(s) + 1\), a contradiction. ◻
Now, we argue that \(L(s, r) = \hat{L}(s, r)\) for all \(s \in S_{\mathrm{in}}\) and \(r \leqslant\mathrm{level}(s)\) at the end of each iteration of the while loop.
Lemma 2. At the end of each iteration of the while loop, \(\widehat{\mathrm{d}}(s, v) = \mathrm{dist}(s, v)\) for all \(v\) with \(\mathrm{dist}(s, v) \leqslant\mathrm{level}(s)\). In particular, for all \(r \leqslant\mathrm{level}(s)\), \(L(s, r) = \hat{L}(s, r)\).
Proof of 2. We proceed by induction on \(\mathrm{level}(s)\). In the base case, \(L(s, 0) = \left\{ s \right\}\) and we initialize \(\widehat{\mathrm{d}}(s, s) = 0\) and \(\hat{L}(s, 0) = \left\{ s \right\}\). In any future iteration of the while loop, we do not modify \(\hat{L}(s, 0)\) or \(\widehat{\mathrm{d}}(s, 0)\) since \(\mathrm{level}(s) + 1 > 0\).
Now, consider \(\ell := \mathrm{level}(s) > 0\). Consider the iteration of the while loop where \(\mathrm{level}(s)\) is incremented to \(\ell\) for the first time. At the end of the previous iteration, we have \(\mathrm{level}(s) = \ell - 1\). Induction then implies that \(\widehat{\mathrm{d}}(s, u) = \mathrm{dist}(s, u)\) for all \(\mathrm{dist}(s, u) < \ell\) and \(L(s, r) = \hat{L}(s, r)\) for all \(r < \ell\).
Fix \(v\) with \(\mathrm{dist}(s, v) = \ell\) and let \(s = w_0, \dots, w_{\ell - 1}, w_{\ell} = v\) denote a shortest path. By induction, \(w_{\ell - 1} \in L(s, \ell - 1) = \hat{L}(s, \ell - 1)\) holds at the iteration where \(\mathrm{level}(s)\) is incremented to \(\ell - 1\) for the first time. At this iteration, the algorithm sets \({\cal A}(s) \gets \hat{L}(s, \ell - 1) = L(s, \ell - 1)\) so that \(w_{\ell - 1} \in {\cal A}(s)\).
Since we only increment \(\mathrm{level}(s)\) when \({\cal A}(s)\) is empty, there was an iteration of the while loop (possibly the current one) \(w_{\ell - 1}\) must have been removed from \({\cal A}(s)\). In particular, there was an iteration where \(w_{\ell - 1} \in V_{i} \cap {\cal A}(s)\) and therefore \(s \in S'\). For this iteration, we consider two cases.
Case 1: \(|N(V_i)| \leqslant\frac{\phi n \log n}{|S_{\mathrm{in}}|}\). Since \(w_{\ell - 1} \in V_i \cap {\cal A}(s)\) and \((w_{\ell - 1}, v) \in E\), so we set \(\widehat{\mathrm{d}}(s, v) \leqslant\ell\) since at this time \(\mathrm{level}(s) = \ell - 1\) (i.e. we have inserted \(w_{\ell - 1}\) into \({\cal A}(s)\) so \(\mathrm{level}(s) \geqslant\ell - 1\) but we have yet to increment \(\mathrm{level}(s)\) to \(\ell\)).
Case 2: \(|N(V_i)| > \frac{\phi n \log n}{|S_{\mathrm{in}}|}\). Since \(w_{\ell - 1} \in V_i \cap {\cal A}(s)\) and \((w_{\ell - 1}, v) \in E\), we have \(X[s, w_{\ell - 1}] = Y[w_{\ell - 1}, v] = 1\) so that \((XY)[s, v] = 1\) and we set \(\widehat{\mathrm{d}}(s, v) \leqslant\ell\) (where \(\mathrm{level}(s) = \ell - 1\) as observed in Case 1).
By 1, we have in both cases that \(\widehat{\mathrm{d}}(s, v) \geqslant\mathrm{dist}(s, v) = \ell\) so \(\widehat{\mathrm{d}}(s, v) = \ell\). In any future iterations, the estimated distance does not change, as \(\mathrm{level}(s) + 1 \geqslant\ell + 1\) is increasing.
We now argue \(L(s, \ell) = \hat{L}(s, \ell)\). In our above argument, in the iteration where we set \(\widehat{\mathrm{d}}(s, v)\) we also add \(v\) to \(\hat{L}(s, \ell)\), so \(L(s, \ell) \subseteq \hat{L}(s, \ell)\). Again, this follows as \(\mathrm{level}(s) = \ell - 1\) and we add \(v\) to \(\hat{L}(s, \mathrm{level}(s) + 1)\).
To argue the reverse inclusion, let \(v\) be some vertex where \(\widehat{\mathrm{d}}(s, v) = \ell\) in some iteration of the while loop where \(s \in S'\) and \(\mathrm{level}(s) = \ell - 1\). By 1, we have \(\mathrm{dist}(s, v) \leqslant\ell\). If \(v \not\in L(s, \ell)\), we have \(\mathrm{dist}(s, v) < \ell\). Then, since \(\mathrm{level}(s) = \ell - 1\), the inductive hypothesis states that \(\widehat{\mathrm{d}}(s, v) = \mathrm{dist}(s, v) \leqslant\ell - 1\), a contradiction.
Finally, we again observe that in any future iterations where \(\mathrm{level}(s) \geqslant\ell\), only \(\hat{L}(s, \mathrm{level}(s) + 1)\) is modified so \(L(s, \ell) = \hat{L}(s, \ell)\) for all future iterations of the while loop, as desired. ◻
Next, we argue that the while loop does not terminate until all distances are computed.
Lemma 3. If there exists \(\widehat{\mathrm{d}}(s, v) > \mathrm{dist}(s, v)\) at the end of an iteration, then the while loop will not terminate.
Proof of 3. We claim \({\cal A}(s) \neq \emptyset\) for all \(s \in S\). If \({\cal A}(s) = \emptyset\) at the end of the iteration, then it is empty at the if statement right before the end of the iteration. If \({\cal A}(s)\) is still empty after the if statement, \(\hat{L}(s, \mathrm{level}(s)) = \emptyset\). By 2 and \(G\) being connected, we have \(\mathrm{ecc}(s) < \mathrm{level}(s)\). Consider the first iteration where \(\mathrm{level}(s) = \mathrm{ecc}(s)\) (which must be a previous iteration of the while loop). By 2, during that iteration \(s\) is already removed from \(S\) as \[\bigcup_{r = 0}^{\mathrm{level}(s)} \hat{L}(s, r) = \bigcup_{r = 0}^{\mathrm{level}(s)} L(s, r) = \bigcup_{r = 0}^{\mathrm{ecc}(s)} L(s, r) = V \text{.}\] Thus, \(s \not\in S\), a contradiction.
Applying our claim above, we argue that \(\sum_{i} \mathrm{score}(i) \geqslant|S|\) since \[\sum_{i \in [k]} \mathrm{score}(i) = \sum_{i \in [k]} |\left\{ s \in S \textrm{ s.t. }{\cal A}(s) \cap V_{i} \neq \emptyset \right\}| = \sum_{s \in S} |\left\{ i \in [k] \textrm{ s.t. }{\cal A}(s) \cap V_{i} \neq \emptyset \right\}| \geqslant|S| \text{.}\] If all \(\mathrm{score}(i) \leqslant\frac{|S||N(V_i)|}{2 \phi n}\), then since \({\cal C}\) is a \((d, \phi)\)-LDSND, \[\sum_{i} \mathrm{score}(i) \leqslant|S| \sum_{i} \frac{|N(V_i)|}{2 \phi n} \leqslant\frac{|S|}{2} \text{.}\] Thus, there is some \(i\) with \(\mathrm{score}(i) > \frac{|S||N(V_i)|}{2 \phi n}\) and the while loop does not terminate. ◻
Thus, if the while loop terminates, then we return \(\widehat{\mathrm{d}}(s, v) = \mathrm{dist}(s, v)\) for all \(s \in S_{\mathrm{in}}, v \in V\).
We now bound the running time of our algorithm. This will also complete the correctness argument as we will show that the while loop terminates. Initializing \(S\), \(\hat{L}(s, 0)\), \({\cal A}(s)\), \(\widehat{\mathrm{d}}(s, s)\), \(\mathrm{level}(s)\), and \(\widehat{\mathrm{d}}(s, v)\) for all \(v\) requires \(O(|S_{\mathrm{in}}|n)\) time. Initializing \(\mathrm{score}(i)\) requires \(O(n)\) time by enumerating all \(V_i\). Overall, we have used time linear in the output so far.
It now remains to analyze the running time of the while loop. Fix a cluster \(V_{i}\). We bound the running time of all iterations of the while loop where \(i\) is chosen as the cluster with \(\mathrm{score}(i) > \frac{|S||N(V_i)|}{2 \phi n}\). Let \(T(i)\) denote the iterations where \(V_i\) is the chosen cluster. We now argue that (1) for all \(s \in S_{\mathrm{in}}\), there are few (roughly \(d\)) iterations \(t \in T(i)\) where \(V_i \cap {\cal A}(s) \neq \emptyset\), and (2) \(|T(i)|\) is not too large (roughly \(\frac{n}{|V_i|}\)). We begin with the first claim.
Lemma 4. For any \(s \in S_{\mathrm{in}}\) and \(V_{i}\), \(V_i \cap {\cal A}(s) \neq \emptyset\) (equivalently \(s \in S'\)) for at most \(d + 1\) distinct \(t \in T(i)\).
Proof of 4. Let \(V_i \cap {\cal A}(s) \neq \emptyset\) (equivalently \(s \in S'\)) for \(k := k(s, i)\) distinct iterations of the while loop where \(V_i\) is the chosen cluster (i.e. distinct \(t \in T(i)\)).
First, observe that for all \(s \in S_{\mathrm{in}}\), \({\cal A}(s) \subseteq \hat{L}(s, \mathrm{level}(s))\) at every iteration, since every time \(\mathrm{level}(s)\) increases, we set \({\cal A}(s) \gets \hat{L}(s, \mathrm{level}(s))\). In later iterations, we only remove vertices from \({\cal A}(s)\) and leave \(\hat{L}(s, \mathrm{level}(s))\) untouched until \({\cal A}(s)\) is empty, at which point we increment \(\mathrm{level}(s)\) to a larger value and reset \({\cal A}(s)\). Furthermore, for each value of \(\mathrm{level}(s)\), \(s \in S'\) for at most one iteration where \(V_i\) is chosen, since whenever \(s \in S'\), we remove \(V_i\) from \({\cal A}(s)\). Since \({\cal A}(s)\) does not add elements until \(\mathrm{level}(s)\) is incremented again, \(s \not\in S'\) for further iterations where \(V_i\) is chosen. Thus, it suffices to bound the number of distinct \(\mathrm{level}(s)\) for which \(V_i \cap \hat{L}(s ,\mathrm{level}(s)) \neq \emptyset\). By 2, we can bound the number of distinct \(\mathrm{level}(s)\) for which \(V_i \cap L(s ,\mathrm{level}(s)) \neq \emptyset\).
We conclude by arguing that \(V_{i}\) can only intersect few \(L(s, r)\). Since \(\mathrm{diam}(V_i) \leqslant d\), the triangle inequality implies that for any \(u, v \in V_i\), \[|\mathrm{dist}(s, u) - \mathrm{dist}(s, v)| \leqslant\mathrm{dist}(u, v) \leqslant d \text{.}\] In particular, for all \(s \in S\), \(V_i \subseteq \bigcup_{r = t}^{t + d} L(s, r)\) for some \(t \geqslant 0\). Thus, we have \(k \leqslant d + 1\) as desired. ◻
Next, we bound the size of \(T(i)\).
Lemma 5. For all \(V_{i}\), \(|T(i)| = O\left(\frac{d \phi n \log n}{|N(V_i)|}\right)\).
Proof of 5. Observe that \(|S|\) is monotonically decreasing from \(|S_{\mathrm{in}}|\). Let \(T_{k}(i) \subseteq T(i)\) denote the iterations of the while loop where \(\frac{|S_{\mathrm{in}}|}{2^{k - 1}} \geqslant|S| \geqslant\frac{|S_{\mathrm{in}}|}{2^{k}}\). Thus, \(T(i) = \bigcup_{k = 1}^{\log |S_{\mathrm{in}}|} T_{k}(i)\) as the while loop terminates once \(|S|\) is empty.
We bound \(|T_{k}(i)|\) for \(k \geqslant 1\). Fix an iteration of the while loop \(t \in T_{k}(i)\) where \(V_i\) is the chosen cluster. Since \(|S| \geqslant\frac{|S_{\mathrm{in}}|}{2^{k}}\), we have \(\mathrm{score}(i) > \frac{|S||N(V_i)|}{2 \phi n} \geqslant\frac{|S_{\mathrm{in}}||N(V_i)|}{2^{k + 1} \phi n}\). In particular, there are \(\frac{|S_{\mathrm{in}}||N(V_i)|}{2^{k + 1} \phi n}\) distinct sources in \(S\) where \({\cal A}(s) \cap V_{i} \neq \emptyset\): i.e. \(S'(t)\) contains at least \(\frac{|S_{\mathrm{in}}||N(V_i)|}{2^{k + 1} \phi n}\) vertices, where \(S'(t)\) denotes the set \(S'\) chosen in the \(t\)-th iteration of the while loop. From 4, we know that each source \(s \in S_{\mathrm{in}}\) is in \(S'\) for at most \(d + 1\) distinct iterations in \(T_{k}(i)\). Combining the above observations, \[|S|(d + 1) \geqslant\sum_{s \in S} \left| \left\{ t \in T_{k}(i) \textrm{ s.t. }s \in S'(t) \right\} \right| = \sum_{t \in T_{k}(i)} \left| \left\{ s \in S'(t) \right\} \right| \geqslant|T_{k}(i)| \frac{|S_{\mathrm{in}}||N(V_i)|}{2^{k + 1} \phi n} \text{.}\] Rearranging and applying the upper bound \(|S| \leqslant\frac{|S_{\mathrm{in}}|}{2^{k - 1}}\), \[|T_{k}(i)| \leqslant\frac{2^{k + 1} \phi n}{|N(V_i)||S_{\mathrm{in}}|} \frac{|S_{\mathrm{in}}|(d + 1)}{2^{k - 1}} \leqslant\frac{8 d \phi n}{|N(V_i)|} \text{.}\] Summing over \(k\) and using \(|S_{\mathrm{in}}| \leqslant n\) we get \(|T(i)| = O\left(\frac{d \phi n \log n}{|N(V_i)|}\right)\). ◻
Finally, we are ready to bound the total running time of all iterations where \(V_i\) is the chosen cluster. We break into two cases. Recall that \(S'(t)\) denotes the set \(S'\) chosen in the \(t\)-th iteration of the while loop.
An iteration of the while loop requires time \(O\left(|S'(t)||V_i||N(V_i)|\right)\) (since the running time is dominated by the time taken to relax all edges from \({\cal A}(s) \cap V_{i} \subseteq V_i\) to \(N({\cal A}(s) \cap V_i) \subseteq N(V_i)\)). Over all iterations in \(T(i)\), the total time is \[\sum_{t \in T(i)} O\left(|S'(t)||V_i||N(V_i)|\right) = O\left(|V_i||N(V_i)||S_{\mathrm{in}}|d\right) = O\left(|S_{\mathrm{in}}||V_i| \frac{\phi n d \log n}{|S_{\mathrm{in}}|}\right) = O\left(|V_i| \phi n d \log n\right) \text{.}\] In the first equality, we use \(\sum_{t} |S'(t)| = O\left(|S_{\mathrm{in}}|d\right)\) by 4. In the second equality, we apply our upper bound on \(|N(V_i)|\).
Similarly, the running time of each while loop is dominated by the boolean matrix product between \(S' \times V_i\) matrix \(X\) and \(V_i \times N(V_i)\) matrix \(Y\). Summing over all iterations, we bound the total time as \[O\left(\sum_{t \in T(i)} \mathsf{T}_{\mathrm{BMM}}(S'(t), V_i, N(V_i))\right) = O\left(\frac{d \phi n \log n}{|N(V_i)|} \mathsf{T}_{\mathrm{BMM}}\left(\frac{|S_{\mathrm{in}}||N(V_i)|}{\phi n \log n}, N(V_i), N(V_i)\right)\right)\] using 4, 5, the fact that \(V_i \subseteq N(V_i)\), and the following lemma.
lemmaMatMulConvex Let \(a_1, \ldots, a_p\) be positive integers with \(a_1 + a_2 + \dots + a_{p} = a\), and \(q\) be a positive integer. Then, \[\sum_{j = 1}^{p} \mathsf{T}_{\mathrm{BMM}}(a_j, q, q) = O\left(p \mathsf{T}_{\mathrm{BMM}}(a/p, q, q)\right) \text{.}\] The result holds also for Min-Plus matrix multiplication (i.e. \(\mathsf{T}_{\mathrm{MPP}}\)).
Proof of [lem:mat-mul-convex]. For all \(a_{j}\), we need to compute the product between an \(a_{j} \times q\) matrix \(X\) and a \(q \times q\) matrix \(Y\). To do so, we construct \(\lceil \frac{a_{j}}{a/p} \rceil\) instances of matrix multiplication between \(\lceil \frac{a}{p} \rceil \times q\) and \(q \times q\) matrices, where each product computes \(\lceil a/p \rceil\) rows of the \(a_{j} \times q \times q\) matrix product. Formally, we split \(X\) by its rows into \(\lceil \frac{a_{j}}{a/p} \rceil\) blocks of size \(\lceil \frac{a}{p} \rceil \times q\) and multiply each block by \(Y\). Overall, we need \[O\left(\sum_{j} \left\lceil \frac{a_{j}}{a/p} \right\rceil \right) = O\left(p\right)\] such matrix products. ◻
Finally, we are ready to bound the running time over all clusters. First, for clusters with \(|N(V_i)| \leqslant\frac{\phi n \log n}{|S_{\mathrm{in}}|}\), the total time spent over all iterations of the while loop is then \(O\left(\sum_{i} |V_{i}| \phi n d \log n\right) = O\left(n^2 \phi d \log n\right)\). For clusters with \(|N(V_i)| > \frac{\phi n \log n}{|S_{\mathrm{in}}|}\), we observe that for any \(k > 0\), there are at most \(2^{k}\) clusters with \(|N(V_i)| \geqslant\frac{\phi n}{2^{k}}\). Summing over \(O(\log n)\) values of \(k\), we obtain total running time: \[O\left(d \phi^2 n^2 (\log n)^2 \max_{T> \frac{\phi n \log n}{|S_{\mathrm{in}}|}} \frac{\mathsf{T}_{\mathrm{BMM}}\left( \frac{|S_{\mathrm{in}}|T }{\phi n \log n}, T, T\right)}{T^2}\right) = O\left(d \phi^2 n^2 (\log n)^2 \max_{T> \frac{n}{|S_{\mathrm{in}}|}} \frac{\mathsf{T}_{\mathrm{BMM}}\left( \frac{|S_{\mathrm{in}}|T }{n}, T, T\right)}{T^2}\right) \text{.}\]
We use the following claim to upper bound the final term.
Claim 3. Let \(0 < z < Z\) be constants independent of \(T\). Then, \[\max_{z < T \leqslant Z, T = 2^{k}} \frac{\mathsf{T}_{\mathrm{BMM}}\left( T/z , T, T\right)}{T^2} = Z^{\omega(p(Z), 1, 1) - 2 + o(1)}\] where \(p := p(Z)\) is defined so that \(T^{p} = T/z\).
Furthermore, if \(\mathsf{T}_{\mathrm{BMM}}\) satisfies \[\mathsf{T}_{\mathrm{BMM}}(2m, 2n, 2n) \geqslant 4 \mathsf{T}_{\mathrm{BMM}}(m, n, n)\] for all \(m, n \geqslant 1\), then \[\max_{z < T \leqslant Z} \frac{\mathsf{T}_{\mathrm{BMM}}\left( T/z , T, T\right)}{T^2} = O\left(\frac{\mathsf{T}_{\mathrm{BMM}}\left( Z/z , Z, Z\right)}{Z^2}\right)\] The claim holds also if we replace \(\mathsf{T}_{\mathrm{BMM}}\) with \(\mathsf{T}_{\mathrm{MPP}}\).
Proof. For any \(T \geqslant z\), fix \(p := p(T) > 0\) so that \(T/z = T^{p}\). Then, we have \[p(T) = \frac{\log(T/z)}{\log(T)} = \frac{\log T - \log z}{\log T}\] is increasing for \(T \geqslant 1\). In particular, we can upper bound \[\frac{\mathsf{T}_{\mathrm{BMM}}\left( T/z , T, T\right)}{T^2} \leqslant\frac{T^{\omega(p(T), 1, 1) + o(1)}}{T^2} = T^{\omega(p(T), 1, 1) - 2 + o(1)} \text{.}\] Since \(\omega(p(T), 1, 1)\) is increasing in \(T\), we have \[\max_{z < T \leqslant Z} \frac{\mathsf{T}_{\mathrm{BMM}}\left( T/z , T, T\right)}{T^2} = \max_{z < T \leqslant Z} T^{\omega(p(T), 1, 1) - 2 + o(1)} = Z^{\omega(p(Z), 1, 1) - 2 + o(1)}\] is maximized at \(T = Z\).
We now prove the second statement, which is necessary for establishing equivalence to BMM. It suffices to consider \(z \leqslant T \leqslant n\) where \(T\) is a power of \(2\), as changing \(T\) by a constant factor changes \(\mathsf{T}_{\mathrm{BMM}}(T/z, T, T)/T^2\) by a constant factor. It follows from our assumption that \[\frac{\mathsf{T}_{\mathrm{BMM}}\left( 2T/z , 2T, 2T\right)}{(2T)^2} \geqslant\frac{\mathsf{T}_{\mathrm{BMM}}(T/z, T, T)}{T^2}\] for all \(T \geqslant z\) so that the expression is maximized at \(T = Z\). ◻
To conclude the running time analysis, we apply 3 with \(z = n/|S_{\mathrm{in}}|\) and \(Z = n\) to obtain \(p := p(Z) = p(n)\) satisfying \(n^{p} = |S_{\mathrm{in}}|\). In particular, we can bound the final running time as \[O\left(d \phi^2 (\log n)^2 n^{\omega(p, 1, 1) + o(1)}\right) \text{.}\]
To establish equivalence with BMM, we apply the second statement of 3, and bound the final running time as \[O\left(d \phi^2 (\log n)^2 \mathsf{T}_{\mathrm{BMM}}\left( |S_{\mathrm{in}}|, n, n \right)\right) \text{.}\] ◻
We now extend our algorithm to handle undirected graphs with small integer weights.
Note that it is without loss of generality that we assume all weights are positive: a negative edge in undirected graphs creates a negative cycle, and all pairwise distances become \(-\infty\) (recall we assume the graph is connected). Also, any vertices joined by a weight \(0\) edge can be merged and treated as one vertex. Assume without loss of generality that \(B\) is a power of \(2\). We will require a simple generalization of bounded Min-Plus products.
Lemma 6. Let \(X\) be an \(n_1 \times n_2\) integer matrix with all finite entries bounded between \([B_0, B_0 + B]\) and \(Y\) be an \(n_2 \times n_3\) integer matrix with entries bounded between \([0, B]\). Then, \(X \star Y\) can be computed in \(O\left(\mathsf{T}_{\mathrm{MPP}}(n_1, n_2, n_3 \mid B)\right) = O\left(B \cdot \mathsf{T}_{\mathrm{MUL}}(n_1, n_2, n_3)\right)\) time.
Proof of 6. Consider the matrix \(X' := X - \min_{i, j} X[i, j]\) with integer entries between \([0, B]\), which can be computed in \(O(n_1 n_2)\) time. Then, \(X' \star Y\) can be computed in \(O\left(B \cdot \mathsf{T}_{\mathrm{MUL}}(n_1, n_2, n_3)\right)\) time [16]. To recover \(X \star Y\), observe that \(X \star Y = (X' \star Y) + \min_{i, j} X[i, j]\), which can be computed in \(O(n_1 n_3)\) time. ◻
We are now ready to prove [thm:bounded-weight-mssp]. Consider the following procedure which for presentation we break into an initialization phase and a computation phase. In the initialization phase, we decompose the graph and initialize various useful data structures.
Input: Graph \(G = (V, E, \mathrm{wt})\), weight bound \(B\), and sources \(S_{\mathrm{in}} \subseteq V\).
For \(t = 0 \ldots \log B\) and \(b = 2^{t}\):
Let \(G_{b} = (V, E_{b})\) be the graph with \(E_{b} = \left\{ e \in E \textrm{ s.t. }b \leqslant\mathrm{wt}(e) < 2b \right\}\).
Let \(d, \phi \gets 2^{O(\sqrt{\log n})}\).
Let \({\cal C}_{b}\) be a \((d, \phi)\)-LDSND of \(G_{b}\) as an unweighted graph. Denote \({\cal C}_{b} = \left\{ V_{1}^{(b)}, \dots, V_{k_{b}}^{(b)} \right\}\).
Let \(S \gets S_{\mathrm{in}}\).
For all \(s \in S\):
Let \(\hat{L}(s, 0) \gets \left\{ s \right\}\), \(\hat{L}(s, r) \gets \emptyset\) for \(1 \leqslant r \leqslant B n\), and \(\widehat{\mathrm{d}}(s, s) \gets 0\), \(\widehat{\mathrm{d}}(s, v) \gets \infty\) for all \(v \neq s\).
Let \({\cal A}(s, b) \gets \left\{ s \right\}\) and \(\mathrm{level}(s, b) \gets 0\) for all \(s \in S\) and \(b = 2^{t}\). Let \(\mathrm{level}(s) \gets 0\).
Let \(\mathrm{score}(i, b) \gets \left|\left\{ s \in S \textrm{ s.t. }\mathrm{level}(s) = \mathrm{level}(s, b) \textrm{ and }{\cal A}(s, b) \cap V_{i}^{(b)} \neq \emptyset \right\}\right|\) for all \(V_{i}^{(b)}\).
Output: \({\cal C}_{b}\), \({\cal A}(s, b)\), \(\mathrm{level}(s, b)\), \(\mathrm{level}(s)\), \(\hat{L}(s, r)\), \(\widehat{\mathrm{d}}(s, v)\), and \(\mathrm{score}(i, b)\) for all \(s, b, r, i\).
In the computation phase, we use the computed decompositions and data structures to compute shortest paths.
Input: Graph \(G\), weight bound \(B\), sources \(S_{\mathrm{in}}\). Outputs of initialization phase.
While \(S \neq \emptyset\):
If exists \(s \in S\) with \({\cal A}(s, b) = \emptyset\) for all \(b = 2^{t}\):
Otherwise, there exists \(V_{i}^{(b)}\) with \(\mathrm{score}(i, b) > \frac{|S|\left|N\left(V_{i}^{(b)}\right)\right|}{2 \phi n \log B}\):
Output: \(\widehat{\mathrm{d}}(s, v)\) for all \(s \in S_{\mathrm{in}}\) and \(v \in V\).
\(\textsf{extendPaths}\left(G, S, V_{i}^{(b)}, \left\{ {\cal A}(s, b) \right\}, \left\{ \mathrm{level}(s, b) \right\}, \left\{ \mathrm{level}(s) \right\}, \left\{ \hat{L}(s, r) \right\}\right)\):
Let \(S' \gets \left\{ s \in S \textrm{ s.t. }{\cal A}(s, b) \cap V_{i}^{(b)} \ne \emptyset \right\}\).
If \(|N(V_i^{(b)})| \leqslant\frac{n}{|S_{\mathrm{in}}|}\):
If \(|N(V_i^{(b)})| > \frac{n}{|S_{\mathrm{in}}|}\):
Construct \(S' \times V_{i}^{(b)}\) matrix \(X\) and \(V_i^{(b)} \times N_{G_{b}}(V_{i}^{(b)})\) matrix \(Y\) with entries \[X[s, u] = \begin{cases} \widehat{\mathrm{d}}(s, u) & u \in {\cal A}(s, b) \\ \infty & \textrm{ o/w } \end{cases} ,\quad Y[u, v] = \begin{cases} \mathrm{wt}(u, v) & (u, v) \in E_{b} \\ \infty & \textrm{ o/w } \end{cases} \text{.}\]
Compute \(X \star Y\) using 6.
For all \(s \in S'\) and \(v \in N_{G_{b}} (V_i^{(b)})\), update \(\widehat{\mathrm{d}}(s, v) \overset{\min}{\gets}(X\star Y)[s, v]\).
For all \(s \in S'\):
Update \(\hat{L}(s, \mathrm{level}(s) + 1) \overset{\cup}{\gets}\left\{ v \textrm{ s.t. }\widehat{\mathrm{d}}(s, v) = \mathrm{level}(s) + 1 \right\}\).
Remove \(V_{i}^{(b)}\) from \({\cal A}(s, b)\) and decrement \(\mathrm{score}(i, b) \overset{-}{\gets}1\).
If \({\cal A}(s, b) = \emptyset\): run \(\textsf{updateScores}(s, b)\).
\(\textsf{updateScores}(s, b)\):
Update \(\mathrm{level}(s, b) \overset{+}{\gets}b\) and \(\mathrm{level}(s) \gets \min_{b} \mathrm{level}(s, b)\).
If \(\bigcup_{r = 0}^{\mathrm{level}(s)} \hat{L}(s, r) = V\): then remove \(s\) from \(S\) and return.
If \(\mathrm{level}(s)\) increased, then for all \(b\) with \(\mathrm{level}(s, b) = \mathrm{level}(s)\):
Update \({\cal A}(s, b) \gets \bigcup_{r = \mathrm{level}(s) - b + 1}^{\mathrm{level}(s)} \hat{L}(s, r)\).
For all \(V_i^{(b)} \cap {\cal A}(s, b) \neq \emptyset\), increment \(\mathrm{score}(i, b)\).
\(\textsf{increaseLevel}\left(s, \left\{ \mathrm{level}(s, b) \right\}, \mathrm{level}(s), \left\{ \hat{L}(s, r) \right\}, \left\{ {\cal C}_{b} \right\}\right)\):
Update \(\hat{L}(s, \mathrm{level}(s) + 1) \overset{\cup}{\gets}\left\{ v \textrm{ s.t. }\widehat{\mathrm{d}}(s, v) = \mathrm{level}(s) + 1 \right\}\).
Increment \(\mathrm{level}(s, b) \overset{+}{\gets}b\) for all \(b\) with \(\mathrm{level}(s, b) = \mathrm{level}(s)\) and update \(\mathrm{level}(s) \gets \min_{b} \mathrm{level}(s, b)\).
For all \(b\) with \(\mathrm{level}(s, b) = \mathrm{level}(s)\):
Update \({\cal A}(s, b) \gets \bigcup_{r = \mathrm{level}(s) - b + 1}^{\mathrm{level}(s)} \hat{L}(s, r)\).
For all \(V_i^{(b)} \cap {\cal A}(s, b) \neq \emptyset\), increment \(\mathrm{score}(i, b)\).
Proof of [thm:bounded-weight-mssp]. We prove the correctness and running time of our algorithm.
We argue that our algorithm terminates and outputs correct distances. As before, we can show that the estimated distances are always valid.
Lemma 7. In every iteration of the while loop \(\widehat{\mathrm{d}}(s, v) \geqslant\mathrm{dist}(s, v)\) for all \(s \in S_{\mathrm{in}}, v \in V\).
Proof of 7. We argue that at the end of each iteration of the while loop \(\widehat{\mathrm{d}}(s, v)\) can be realized by a path in \(G\) from \(s\) to \(v\) for all \(s \in S_{\mathrm{in}}\), \(v \in V\). Consider the first iteration where this is not the case. Then, during this iteration, \(\widehat{\mathrm{d}}(s, v)\) was updated, i.e. we update \(\widehat{\mathrm{d}}(s, v) \gets \widehat{\mathrm{d}}(s, u) + \mathrm{wt}(u, v) < \mathrm{dist}(s, v)\) for some \(u \in {\cal A}(s, b) \cap V_{i}^{(b)}\) with \(\widehat{\mathrm{d}}(s, v) = \widehat{\mathrm{d}}(s, u) + \mathrm{wt}(u, v)\). Note that \(\widehat{\mathrm{d}}(s, u)\) was computed in some previous iteration. Thus, there is a path from \(s\) to \(u\) with length \(\widehat{\mathrm{d}}(s, u)\), which we may extend to \(v\) via the edge \((u, v)\) with weight \(\mathrm{wt}(u, v)\). This is a contradiction. ◻
The remainder of the proof is dedicated to showing that our algorithm produces exact shortest distances. We begin with some useful claims about \(\mathrm{level}(s, b)\), \(\mathrm{level}(s)\), whose proofs are deferred.
claimLevelIncBound In any iteration of the while loop, \(\mathrm{level}(s)\) increases by at most one for all \(s \in S_{\mathrm{in}}\).
claimMultipleBExist Let \(s \in S_{\mathrm{in}}\) and \(\ell \leqslant\mathrm{ecc}(s)\). Then, for every \(b\) such that \(\ell\) is a multiple of \(b\), there exists an iteration where \(\mathrm{level}(s) = \mathrm{level}(s, b) = \ell\) at the beginning of the iteration.
Next, we prove that our algorithm iteratively computes correct distances, analogously to 2.
Lemma 8. At the end of each iteration of the while loop, \(\widehat{\mathrm{d}}(s, v) = \mathrm{dist}(s, v)\) for all \(\mathrm{dist}(s, v) \leqslant\mathrm{level}(s)\). In particular, for all \(r \leqslant\mathrm{level}(s)\), \(L(s, r) = \hat{L}(s, r)\).
Proof. We proceed by induction, where the base case follows identically as 2. Now, let \(\ell > 0\). Consider the first iteration of the while loop where \(\mathrm{level}(s) = \ell\). In this iteration, we incremented \(\mathrm{level}(s)\). By [clm:level-inc-bound], \(\mathrm{level}(s)\) increments by at most \(1\), so that at the end of the previous iteration, we have \(\mathrm{level}(s) = \ell - 1\).
By induction, we have \(\widehat{\mathrm{d}}(s, u) = \mathrm{dist}(s, u)\) for all \(\mathrm{dist}(s, u) < \ell\). Consider a vertex with \(\mathrm{dist}(s, v) = \ell\) and a shortest path \(s = w_{0}, \dots, w_{p - 1}, w_{p} = v\) where \(\mathrm{dist}(s, w_{p - 1}) < \ell\). Suppose \((w_{p - 1}, v) \in E_{b}\) and \(w_{p - 1} \in V_{i}^{(b)}\). By induction, \(\widehat{\mathrm{d}}(s, w_{p - 1}) = \mathrm{dist}(s, w_{p - 1})\) and \(w_{p - 1} \in \hat{L}(s, r)\) for \(r = \mathrm{dist}(s, w_{p - 1}) \geqslant\ell - 2b + 1\) since edge weights in \(E_{b}\) are less than \(2b\). Let \(\ell_0\) be the multiple of \(b\) such that \(\ell_0 - b < \mathrm{dist}(s, w_{p - 1}) \leqslant\ell_0\). Note that we have \(\ell_0 < \ell \leqslant\mathrm{ecc}(s)\) since \(\mathrm{wt}(u, v) \geqslant b\).
Consider the first iteration where \(\mathrm{level}(s, b) = \mathrm{level}(s) = \ell_0\), which exists by [clm:multiple-b-exists]. In this iteration, we set \({\cal A}(s, b) \gets \bigcup_{r = \ell_0 - b + 1}^{\ell_0} \hat{L}(s, r) = \bigcup_{r = \ell_0 - b + 1}^{\ell_0} L(s, r)\) so that \(w_{p - 1} \in {\cal A}(s, b)\). Now, in the current iteration, we have \(\mathrm{level}(s, b) \geqslant\mathrm{level}(s) = \ell\), which implies that \(\textsf{updateScores}\) or \(\textsf{increaseLevel}\) was triggered i.e. \({\cal A}(s, b) = \emptyset\). Thus, there was an intermediate iteration where \(w_{p - 1}\) was removed from \({\cal A}(s, b)\) i.e. \(V_{i}^{(b)}\) was chosen. We argue that at the start of this intermediate iteration, \(\widehat{\mathrm{d}}(s, w_{p - 1}) = \mathrm{dist}(s, w_{p - 1})\). This follows via induction, as above we showed \(\mathrm{level}(s) \geqslant\ell_0 \geqslant\mathrm{dist}(s, w_{p - 1})\) (in fact this was already true in the iteration where \({\cal A}(s, b)\) was set).
We now consider two cases.
Case 1: \(|N(V_i^{(b)})| \leqslant\frac{n}{|S_{\mathrm{in}}|}\). Since \(w_{p - 1} \in V_i^{(b)} \cap {\cal A}(s, b)\) and \((w_{p - 1}, v) \in E_{b}\), so we set \(\widehat{\mathrm{d}}(s, v) \leqslant\widehat{\mathrm{d}}(s, w_{p - 1}) + \mathrm{wt}(w_{p - 1}, v) \leqslant\mathrm{dist}(s, w_{p - 1}) + \mathrm{wt}(w_{p - 1}, v) = \mathrm{dist}(s, v)\).
Case 2: \(|N(V_i^{(b)})| > \frac{n}{|S_{\mathrm{in}}|}\). Since \(w_{p - 1} \in V_i^{(b)} \cap {\cal A}(s, b)\) and \((w_{p - 1}, v) \in E_{b}\), we have \(X[s, w_{p - 1}] = \mathrm{dist}(s, u)\), \(Y[w_{p - 1}, v] = \mathrm{wt}(u, v)\) so that \((X \star Y)[s, v] \leqslant\mathrm{dist}(s, u) + \mathrm{wt}(u, v)\) and we set \(\widehat{\mathrm{d}}(s, v) \leqslant\mathrm{dist}(s, u) + \mathrm{wt}(u, v) = \mathrm{dist}(s, v)\).
Thus, we have \(\widehat{\mathrm{d}}(s, v) = \mathrm{dist}(s, v)\) in this intermediate iteration. Note that we already have \(\widehat{\mathrm{d}}(s, v) = \mathrm{dist}(s, v)\) in an iteration where \(\mathrm{level}(s) = \mathrm{level}(s, b) = \ell_0\). The distance equality holds also in any subsequent iteration since \(\widehat{\mathrm{d}}\) does not increase, and does not decrease below \(\mathrm{dist}(s, v)\) 7.
Finally, we argue that \(\hat{L}(s, \ell) = L(s, \ell)\). Suppose \(v \in \hat{L}(s, \ell)\), so that \(\widehat{\mathrm{d}}(s, v) \leqslant\ell\). We can in fact conclude \(\widehat{\mathrm{d}}(s, v) = \ell\) since if \(\widehat{\mathrm{d}}(s, v) = \mathrm{dist}(s, v) < \ell\) then \(v \notin \hat{L}(s, \ell)\) by induction.
Conversely, if \(v \in L(s, \ell)\), consider the iteration where \(\mathrm{level}(s) = \ell\) for the first time. We increment \(\mathrm{level}(s)\) either in \(\textsf{updateScores}\) or \(\textsf{increaseLevel}\). Recall from our previous discussion that we have \(\widehat{\mathrm{d}}(s, v) = \mathrm{dist}(s, v)\) in some iteration where \(\mathrm{level}(s) = \ell_0 < \ell\), where \(\ell_0\) is the multiple of \(b\) satisfying \(\ell_0 - b < \mathrm{dist}(s, w_{p - 1}) \leqslant\ell_0\) above. We consider two cases.
If \(\mathrm{level}(s) \gets \ell\) is triggered through \(\textsf{updateScores}\), then before the last if statement in \(\textsf{extendPaths}\), we have \(\mathrm{level}(s) = \ell - 1 \geqslant\ell_{0}\) and \(v\) is added to \(\hat{L}(s, \ell)\). On the other hand, if \(\mathrm{level}(s) \gets \ell\) is triggered through \(\textsf{increaseLevel}\), at the first step of \(\textsf{increaseLevel}\), we have \(\mathrm{level}(s) = \ell - 1 \geqslant\ell_{0}\) so \(v\) is added to \(\hat{L}(s, \ell)\).
In any future iterations, the equality holds as we only update \(\hat{L}(s, \mathrm{level}(s) + 1)\) when \(\mathrm{level}(s)\) increases. ◻
Thus, we have established that \(\widehat{\mathrm{d}}(s, v) = \mathrm{dist}(s, v)\) for all \(\mathrm{dist}(s, v) \leqslant\mathrm{level}(s)\) at the end of each iteration of the while loop. Again, we must argue that the while loop does not terminate until all distances are computed.
Lemma 9. If there exists \(\widehat{\mathrm{d}}(s, v) > \mathrm{dist}(s, v)\) at the end of an iteration, then the while loop will not terminate.
Proof. Suppose the while loop terminates while there is some wrong distance: i.e. \(v\) with \(\widehat{\mathrm{d}}(s, v) > \mathrm{dist}(s, v)\) at the end of the iteration. We claim \(s \in S\), ensuring the while loop does not terminate. It suffices to argue \(v \not\in \bigcup_{r = 0}^{\mathrm{level}(s)} \hat{L}(s, r)\). By 8, we have \(\widehat{\mathrm{d}}(s, v) > \mathrm{dist}(s, v) > \mathrm{level}(s)\), implying that \(v \not\in \bigcup_{r \leqslant\mathrm{level}(s)} \hat{L}(s, r)\) since \(\hat{L}(s, r)\) only contains vertices \(w\) with \(\widehat{\mathrm{d}}(s, w) \leqslant r\), as desired. ◻
Finally, we argue that either the condition to run \(\textsf{increaseLevel}\) or the condition to run \(\textsf{extendPaths}\) is satisfied in each iteration.
Lemma 10. If all \(s\) have \({\cal A}(s, b) \neq \emptyset\) for some \(b\), there exists \(V_{i}^{(b)}\) with \(\mathrm{score}(i, b) > \frac{|S|\left|N\left(V_{i}^{(b)}\right)\right|}{2 \phi n \log B}\).
Proof. Following a similar argument to 3, we bound the sum of scores from below. \[\sum_{i, b} \mathrm{score}(i, b) = \sum_{i, b} \left| \left\{ s \in S \textrm{ s.t. }{\cal A}(s, b) \cap V_{i}^{(b)} \neq \emptyset \right\} \right| = \sum_{s} \left| \left\{ V_{i}^{(b)} \textrm{ s.t. }{\cal A}(s, b) \cap V_{i}^{(b)} \neq \emptyset \right\} \right| \geqslant|S|\] If all \(\mathrm{score}(i, b) \leqslant\frac{|S|\left|N\left(V_{i}^{(b)}\right)\right|}{2 \phi n \log B}\), then we obtain a contradiction via \[\sum_{i, b} \mathrm{score}(i, b) \leqslant\sum_{b} \sum_{i} \frac{|S|\left|N\left(V_{i}^{(b)}\right)\right|}{2 \phi n \log B} \leqslant(1 + \log B) \frac{|S|}{2 \log B} < |S| \text{.}\] ◻
We have thus established that our algorithm (if it terminates) outputs exact distances between \(S_{\mathrm{in}}\) and \(V\). As before, it remains to show that the algorithm terminates, which we prove below.
We now bound the running time, thus proving that our algorithm terminates and produces the correct output. First, the initialization phase takes \(O\left(n^{2 + o(1)} \log B + |S_{\mathrm{in}}|Bn\right) = B n^{2 + o(1)}\) time.
We separately bound the time required by the while loop of the computation phase. First, we bound the total time required by all iterations where \(\textsf{increaseLevel}\) is invoked. We defer the proof to the end of this section.
lemmaIncreaseLevelTimeBound The total time used by all calls to \(\textsf{increaseLevel}\) is \(\tilde{O}\left(|S_{\mathrm{in}}|nB\right) = \tilde{O}\left(Bn^{2}\right)\).
Next, we bound the total time required by all iterations where \(\textsf{extendPaths}\) is invoked. As in [thm:mssp-reduction], we bound the time required by all iterations where a fixed cluster \(V_{i}^{(b)}\) is chosen. Let \(T(i, b)\) denote the iterations where \(V_{i}^{(b)}\) is the chosen cluster. We again bound the number of iterations where \(s \in S'\) in \(T(i, b)\) and the size of \(T(i, b)\), analogously to 4 and 5.
Lemma 11. For any \(s \in S_{\mathrm{in}}\) and \(V_{i}^{(b)}\), \(s \in S'\) for at most \(3d\) distinct \(t \in T(i, b)\).
Proof of 11. Observe \(s \in S'\) is only possible for an iteration \(t \in T(i, b)\) when \(\mathrm{level}(s) = \mathrm{level}(s, b)\). Fix some \(\ell = \mathrm{level}(s) = \mathrm{level}(s, b)\). Observe that \(s \in S'\) holds in an iteration where \(t \in T(i, b)\) and \(\mathrm{level}(s) = \mathrm{level}(s, b) = \ell\) if and only if \[\label{eq:layers-intersect-cluster} \emptyset \neq {\cal A}(s, b) \cap V_{i}^{(b)} \subseteq \bigcup_{r = \ell - b + 1}^{\ell} L(s, r) \cap V_{i}^{(b)} \neq \emptyset \text{.}\tag{3}\] Furthermore, this holds in at most one iteration \(t \in T(i, b)\) where \(\ell = \mathrm{level}(s) = \mathrm{level}(s, b)\). This follows as we remove \(V_{i}^{(b)}\) from \({\cal A}(s, b)\) after the first iteration that this occurs, thus guaranteeing that \({\cal A}(s, b)\) is disjoint from \(V_{i}^{(b)}\) until \(\mathrm{level}(s, b)\) is increased.
Thus, as in 4, it suffices to bound the number of \(\ell\) where 3 holds. Since \(V_{i}^{(b)}\) has hop diameter \(d\), \(V_{i}^{(b)}\) has diameter \(2bd\). Then, \[V_{i}^{(b)} \subseteq \bigcup_{r = \ell_0}^{\ell_0 + 2bd} L(s, r)\] for some \(\ell_0\). We conclude by bounding the number of distinct values of \(\ell\) by \(\lceil \frac{2bd + 1}{b} \rceil \leqslant 3d\). ◻
Next, we may bound the size of \(T(i, b)\) following identical arguments as 5.
Lemma 12. For all \(V_{i}^{(b)}\), \(T(i, b) = \tilde{O}\left(\frac{d \phi n \log B \log n}{\left|N\left(V_i^{(b)}\right)\right|}\right)\).
Proof of 12. We repeat the argument for completeness. As before, let \(T_{k}(i, b) \subseteq T(i, b)\) denote the iterations of the while loop where \(\frac{|S_{\mathrm{in}}|}{2^{k - 1}} \geqslant|S| \geqslant\frac{|S_{\mathrm{in}}|}{2^{k}}\). Thus, \(T(i, b) = \bigcup_{k = 1}^{\log |S_{\mathrm{in}}|} T_{k}(i, b)\) as the while loop terminates once \(|S|\) is empty.
We bound \(|T_{k}(i, b)|\) for \(k \geqslant 1\). Fix an iteration of the while loop \(t \in T_{k}(i, b)\) where \(V_i^{(b)}\) is the chosen cluster. Since \(|S| \geqslant\frac{|S_{\mathrm{in}}|}{2^{k}}\), we have \(\mathrm{score}(i, b) > \frac{|S|\left|N\left(V_i^{(b)}\right)\right|}{2 \phi n \log B} \geqslant\frac{|S_{\mathrm{in}}|\left|N\left(V_i^{(b)}\right)\right|}{2^{k + 1} \phi n \log B}\). In particular, there are \(\frac{|S_{\mathrm{in}}|\left|N\left(V_i^{(b)}\right)\right|}{2^{k + 1} \phi n \log B}\) distinct sources in \(S\) where \({\cal A}(s) \cap V_{i}^{(b)} \neq \emptyset\): i.e. \(S'(t)\) contains at least \(\frac{|S_{\mathrm{in}}|\left|N\left(V_i^{(b)}\right)\right|}{2^{k + 1} \phi n \log B}\) vertices, where \(S'(t)\) denotes the set \(S'\) chosen in the \(t\)-th iteration of the while loop. From 11, we know that each source \(s \in S_{\mathrm{in}}\) is in \(S'\) for at most \(3d\) distinct iterations in \(T_{k}(i, b)\). Combining the above observations, \[3|S|d \geqslant\sum_{s \in S} \left| \left\{ t \in T_{k}(i, b) \textrm{ s.t. }s \in S'(t) \right\} \right| = \sum_{t \in T_{k}(i, b)} \left| \left\{ s \in S'(t) \right\} \right| \geqslant|T_{k}(i, b)| \frac{|S_{\mathrm{in}}|\left|N\left(V_i^{(b)}\right)\right|}{2^{k + 1} \phi n \log B} \text{.}\] Rearranging and applying the upper bound \(|S| \leqslant\frac{|S_{\mathrm{in}}|}{2^{k - 1}}\), \[|T_{k}(i, b)| \leqslant\frac{2^{k + 1} \phi n \log B}{\left|N\left(V_i^{(b)}\right)\right||S_{\mathrm{in}}|} \frac{3 |S_{\mathrm{in}}| d}{2^{k - 1}} \leqslant\frac{12 d \phi n \log B}{\left|N\left(V_i^{(b)}\right)\right|} \text{.}\] Summing over \(k\) and using \(|S_{\mathrm{in}}| \leqslant n\) we get \(|T(i, b)| = O\left(\frac{d \phi n \log B \log n}{\left|N\left(V_i^{(b)}\right)\right|}\right)\). ◻
Finally, we bound the total running time of all iterations where \(V_{i}^{(b)}\) is chosen using similar arguments as [thm:mssp-reduction]. We break into two cases.
Case 1: \(\left|N\left(V_i^{(b)}\right)\right| \leqslant\frac{n}{|S_{\mathrm{in}}|}\). An iteration of the while loop requires time \(O\left(|S'(t)|\left|V_i^{(b)}\right|\left|N\left(V_i^{(b)}\right)\right|\right)\) (since the running time is dominated by the time taken to relax all edges from \({\cal A}(s) \cap V_{i}^{(b)} \subseteq V_i^{(b)}\) to \(N\left({\cal A}(s) \cap V_i^{(b)} \right) \subseteq N\left(V_i^{(b)}\right)\)). Over all iterations in \(T(i, b)\), the total time is \[\begin{align} \sum_{t \in T(i, b)} O\left(|S'(t)|\left|V_i^{(b)}\right|\left|N\left(V_i^{(b)}\right)\right|\right) &= O\left(\left|V_i^{(b)}\right|\left|N\left(V_i^{(b)}\right)\right||S_{\mathrm{in}}|d\right) \\ &= O\left(|S_{\mathrm{in}}|\left|V_i^{(b)}\right|\frac{d n}{|S_{\mathrm{in}}|}\right) \\ &= O\left(\left|V_i^{(b)} \right| d n\right) \text{.} \end{align}\] In the first equality, we use \(\sum_{t} |S'(t)| = O\left(|S_{\mathrm{in}}|d\right)\) by 11. In the second equality, we apply our upper bound on \(|N(V_i)|\).
Case 2: \(\left|N\left(V_i^{(b)}\right)\right| > \frac{n}{|S_{\mathrm{in}}|}\). Following [thm:mssp-reduction], we obtain the time bound \[\begin{align} &\quad~O\left(\sum_{t \in T(i, b)} \mathsf{T}_{\mathrm{MPP}}\left(S'(t), N(V_i^{(b)}), N(V_{i}^{(b)}) \mid B \right)\right) \\ &= \tilde{O}\left( \frac{d \phi n \log B}{\left|N\left(V_{i}^{(b)}\right) \right|} \mathsf{T}_{\mathrm{MPP}}\left(\frac{|S_{\mathrm{in}}| \left|N\left(V_{i}^{(b)}\right) \right|}{2 \phi n \log B}, N(V_i^{(b)}), N(V_{i}^{(b)}) \mid B \right)\right) \\ &= \frac{n^{1 + o(1)} \log B}{\left|N\left(V_{i}^{(b)}\right) \right|} \mathsf{T}_{\mathrm{MPP}}\left(\frac{|S_{\mathrm{in}}| \left|N\left(V_{i}^{(b)}\right) \right|}{n}, N(V_i^{(b)}), N(V_{i}^{(b)}) \mid B \right) \end{align}\] over all iterations. Here, we use 6 instead of BMM to compute the matrix product \(X * Y\). In the first equality, we apply [lem:mat-mul-convex] and 12. In the second, we plug in our values \(d, \phi \gets n^{o(1)}\).
Finally, to bound the time of the fourth step, we fix a source \(s \in S_{\mathrm{in}}\). Since \(\hat{L}(s, r)\) are disjoint so are \({\cal A}(s, b)\) over different iterations with distinct \(\mathrm{level}(s, b)\), the total time required by all updates to \(\hat{L}\), \({\cal A}\), and \(\mathrm{score}\) variables is \(\widetilde{O}\left(n\right)\). Updating \(\mathrm{level}(s, b)\) requires \(\widetilde{O}\left(Bn\right)\) time. Overall, the fourth step over all sources requires \(\tilde{O}\left(|S_{\mathrm{in}}|Bn\right) = \tilde{O}\left(Bn^2\right)\) time.
Summing over all \(V_{i}^{(b)}\) (again bucketing \(N\left(V_{i}^{(b)}\right)\) by size in increasing powers of \(2\)), we obtain the total time bound \[\max_{\frac{n}{|S_{\mathrm{in}}|} \leqslant T \leqslant n} \frac{n^{2 + o(1)} \log B}{T^2} \mathsf{T}_{\mathrm{MPP}}\left( \frac{|S_{\mathrm{in}}|T}{n}, T, T \mid B \right) = n^{o(1)} \log B \mathsf{T}_{\mathrm{MPP}}\left( |S_{\mathrm{in}}|, n, n \mid B \right)\] where we apply 3 to argue that the time is maximized when \(T = n\). This concludes the proof of [thm:bounded-weight-mssp]. ◻
We prove the remaining lemmas. We begin with a few useful claims.
Claim 4. \(\mathrm{level}(s, b)\) increases only in iterations where \(\mathrm{level}(s, b) = \mathrm{level}(s)\) at the start of the iteration.
Proof of 4. We prove this claim inductively. The base case follows as initially all \(\mathrm{level}(s)\) and \(\mathrm{level}(s, b) = 0\). Consider the first iteration where \(\mathrm{level}(s) = \ell\), \(\mathrm{level}(s, b) > \ell\), and \(\mathrm{level}(s, b)\) is incremented. Thus, we can assume \(\mathrm{level}(s, b) = \ell' > \ell\) is the smallest multiple of \(b\) greater than \(\ell\). Note that \(\mathrm{level}(s, b)\) can only increase via \(\textsf{increaseLevel}\) or \(\textsf{updateScores}\). In \(\textsf{increaseLevel}\), we only increase \(\mathrm{level}(s, b)\) if \(\mathrm{level}(s, b) = \mathrm{level}(s)\). Otherwise, we run \(\textsf{extendPaths}\) and call \(\textsf{updateScores}\) if \({\cal A}(s, b) = \emptyset\). In particular, in this iteration, since \(s \in S'\), a cluster \(V_{i}^{(b)}\) is selected such that \({\cal A}(s, b) \cap V_{i}^{(b)} \neq \emptyset\).
By induction, in the iteration where \(\mathrm{level}(s, b)\) is set to \(\ell'\), that iteration began with \(\mathrm{level}(s) = \mathrm{level}(s, b) = \ell' - b\) and \({\cal A}(s, b) = \emptyset\) at some point in that iteration (since this is a requirement to trigger \(\textsf{increaseLevel}\) or \(\textsf{updateScores}\)). Regardless of which one was triggered, \({\cal A}(s, b)\) is only set to be non-empty if \(\mathrm{level}(s) = \mathrm{level}(s, b) = \ell'\), a contradiction as \(\mathrm{level}(s)\) cannot decrease. ◻
Claim 5. At the start of any iteration of the while loop, \[\mathrm{level}(s) \leqslant\mathrm{level}(s, b) \leqslant\mathrm{level}(s) + b\] for all \(s \in S_{\mathrm{in}}\) and \(b\).
Proof of 5. Observe that \(\mathrm{level}(s) \leqslant\mathrm{level}(s, b)\) by definition. Since at most one of \(\textsf{updateScores}\) or \(\textsf{increaseLevel}\) is called during any single iteration, \(\mathrm{level}(s, b)\) increases by at most \(b\). Furthermore, by 4 \(\mathrm{level}(s, b)\) does not increase whenever \(\mathrm{level}(s, b) > \mathrm{level}(s)\). Thus, \(\mathrm{level}(s, b)\) can never exceed \(\mathrm{level}(s)\) by more than \(b\). ◻
We are ready to prove the required lemmas.
Proof of [clm:level-inc-bound]. At the start of any iteration, we have \(\ell = \mathrm{level}(s) \leqslant\mathrm{level}(s, 1) \leqslant\mathrm{level}(s) + 1\) by 5. If \(\mathrm{level}(s, 1) = \ell + 1\), then by 4, \(\mathrm{level}(s, 1)\) is not incremented during this iteration, so that \(\mathrm{level}(s) \leqslant\mathrm{level}(s, 1) \leqslant\ell + 1\) at the end of this iteration. On the other hand, if \(\mathrm{level}(s, 1) = \ell\), then since at most one of \(\textsf{increaseLevel}\) or \(\textsf{updateScores}\) is invoked during any single iteration, we have \(\mathrm{level}(s) \leqslant\mathrm{level}(s, 1) \leqslant\ell + 1\) at the end of the iteration, as desired. ◻
Proof of [clm:multiple-b-exists]. From [clm:level-inc-bound], we have that \(\mathrm{level}(s)\) increments by at most one in every iteration. Thus, since \(\mathrm{level}(s) \leqslant\mathrm{level}(s, b)\), consider the first iteration where \(\ell = \mathrm{level}(s) \leqslant\mathrm{level}(s, b)\). We claim that in fact \(\mathrm{level}(s, b) = \mathrm{level}(s)\). Suppose not for contradiction. Then, we have that at the start of this iteration, \(\mathrm{level}(s, b) \geqslant\ell + b\) since \(\mathrm{level}(s, b)\) increases in increments of size \(b\), and the same bound holds at the end of the previous iteration.
Now, consider the previous iteration which began with \(\mathrm{level}(s) = \ell - 1\). From 5, at the start of this iteration \(\mathrm{level}(s, b) \leqslant\ell - 1 + b < \ell + b\) so that \(\mathrm{level}(s, b)\) must have been incremented in the previous iteration. Furthermore, at the start of the previous iteration, \(\mathrm{level}(s, b) \geqslant\mathrm{level}(s) = \ell - 1\). We consider two cases.
If \(b > 1\), then \(\mathrm{level}(s, b) = \ell\) since \(\ell - 1 \mod b \not\equiv 0\). Then, regardless of whether \(\mathrm{level}(s)\) is incremented via \(\textsf{updateScores}\) or \(\textsf{increaseLevel}\), \(\mathrm{level}(s, b)\) is only incremented if \(\mathrm{level}(s, b) = \ell - 1\) by 4, which is impossible unless \(b = 1\) (again since \(\mathrm{level}(s, b)\) increases in increments of size \(b\)).
Thus, assume \(b = 1\). In this case, \(\mathrm{level}(s, b) = \ell - 1\) at the start of the previous iteration (otherwise \(\mathrm{level}(s, b) \neq \mathrm{level}(s)\) is not increased) so that \(\mathrm{level}(s, b) = \ell\) at the start of this iteration, as desired. ◻
Proof of [lem:increase-level-time-bound]. First, we claim that \(\mathrm{level}(s, b) \leqslant Bn\) for all \(b\).
Claim 6. \(\mathrm{level}(s, b) \leqslant Bn\) for all \(b = 2^{t}\) and \(s \in S\).
Proof of 6. Since \(G\) is connected, we have \(\mathrm{ecc}(s) \leqslant Bn\) so that by 8, we have that \(\bigcup_{r = 0}^{Bn} \hat{L}(s, r) = V\), so we remove \(s\) from \(S\) after level \(Bn\). ◻
Now, fix a single source \(s\). By 8 and the fact that we never remove vertices from \(\hat{L}(s, r)\) for any \(r\), we have that \(\hat{L}(s, r)\) are always disjoint. Thus, the overall time required by step 1 of \(\textsf{increaseLevel}\) is \(O(Bn)\), since \(\textsf{increaseLevel}\) is called at most \(\mathrm{ecc}(s) \leqslant Bn\) times and in each iteration, step 1 requires \(O\left(1 + \left|\hat{L}(s, \mathrm{level}(s) + 1))\right|\right)\) time.
Note step 2 over all iterations requires \(O(n B \log B)\) time.
Finally, in step 3, we observe that any vertex is added to and removed from \({\cal A}(s, b)\) exactly once. When we add or remove a vertex from \({\cal A}(s, b)\), we can also update the score as appropriate by maintaining a membership data structure for each \(V_{i}^{(b)}\). Thus, the total time required by step 3 is \(O(n B \log B)\), since for every \(b\) and \(s\), the time at one iteration is \(\tilde{O}\left(\left|\bigcup_{\mathrm{level}(s) - b < r \leqslant\mathrm{level}(s)} L(s, r) \right| + 1\right)\). Initializing the membership data structures also requires \(\widetilde{O}\left(n \log B\right)\) time.
Thus, the total cost of all \(\textsf{increaseLevel}\) calls over all sources is at most \(\tilde{O}\left(|S_{\mathrm{in}}| n B\right)\) time. ◻
We give some applications of our MSSP algorithm.
Our first application is the first non-trivial algorithm for explicitly constructing hop-sets.
Definition 3. A set of weighted edges \(F\) is a \(\beta\)-hop-set for \(G = (V, E, \mathrm{wt})\) if \(\mathrm{dist}_{G}(u, v) = \mathrm{dist}_{G \cup F}(u, v)\) for all \(u, v \in V\) and for every \(u, v\), there is a path \(\pi\) of at most \(\beta\) hops from \(u\) to \(v\) such that \(\pi\) is a shortest path between \(u, v\).
We give an efficient algorithm for computing exact \(\beta\)-hop-sets on dense graphs, improving upon the known \(\min\left( n^3/\beta, n^{\omega} \right)\) time algorithm.
Theorem 7. For all \(\beta \geqslant 1\), there is a randomized \(Bn^{o(1)}\mathsf{T}_{\mathrm{MUL}}(n/\beta, n, n)\) time algorithm that computes a \(\beta\)-hop-set with \(\widetilde{O}\left(n^2/\beta^2\right)\) edges on undirected graphs with integer weights in \([B]\).
Proof. When \(\beta \leqslant 30 \log n\), we observe that the theorem is true by computing APSP in \(B n^{o(1)} \mathsf{T}_{\mathrm{MUL}}(n, n, n)\) time and adding edges of weight \(\mathrm{dist}(u, v)\) between every pair of vertices. Thus, we assume \(\beta > 30 \log n\). Consider the following algorithm.
Input: Undirected graph \(G\) with integer weights in \([B]\).
Sample \(S \subseteq V\) by including each vertex independently with probability \(\frac{30 \log n}{\beta}\)
Compute \(\widehat{\mathrm{d}}(S, V) \gets {\rm MSSP}(G, S)\).
Compute \(F \gets \left\{ (a, b) \textrm{ s.t. }a, b \in S \right\}\) where edge \((a, b)\) has weight \(\widehat{\mathrm{d}}(a, b)\).
Output: Weighted edge set \(F\).
First, we argue that \(F\) is a \(\beta\)-hop-set. Consider a shortest path of at least \(\beta/3\) nodes. Then, the probability that none of these nodes is included in \(S\) is at most \[\left( 1 - \frac{30 \log n}{\beta} \right)^{\beta/3} \leqslant n^{-10}\] so that union bounding over \(O(n^2)\) shortest paths, we can ensure with high probability that all shortest paths of at least \(\beta/3\) nodes include one node in \(S\). Then, for any shortest path of length \(\ell \geqslant\beta\), \(\pi = v_0, \dots, v_{\beta/3}, \dots, v_{\ell - \beta/3}, \dots, v_{\ell}\), we have \(v_i, v_j \in S\) for \(i \leqslant\beta/3\) and \(j \geqslant\ell - \beta/3\). Then, adding \(F\), we have the path \(\pi' = v_0, \dots, v_i, v_j, \dots, v_{\ell}\) of hop length at most \(2\beta/3 + 1\). Furthermore, \(\mathrm{wt}(v_i, v_j) = \widehat{\mathrm{d}}(v_i, v_j) = \mathrm{dist}(v_i, v_j)\) by correctness of the MSSP algorithm.
To analyze the time, sampling requires \(O(n)\) time, MSSP requires \(Bn^{o(1)}\mathsf{T}_{\mathrm{MUL}}(n/\beta, n, n)\) time by [thm:bounded-weight-mssp], and constructing \(F\) requires \(O(|S|^2)\) time. We thus conclude by bounding \(|S|\). By a Chernoff bound, we have with high probability \(|S| = O\left(\frac{n \log n}{\beta}\right)\) so that \(|S|^2 = \widetilde{O}\left(n^2/\beta^2\right)\), as desired. ◻
We give a simple, efficient algorithm for constructing a \(+4\)-emulator on undirected graphs.
Theorem 8. There is a randomized \(O(Bn^{\omega(1, 2/3, 1) + o(1)}) = O\left(Bn^{2.1321}\right)\) time algorithm to construct \(+4B\)-emulators of size \(O(n^{4/3} \log n)\) on undirected graphs with integer weights at most \(B\).
Proof. Elkin, Gitlitz, and Neiman [49] present the following algorithm for obtaining a \(+4\)-emulator.
Input: Graph \(G\).
Initialize \(H \gets \emptyset\) and \(S \subseteq V\) a random set chosen by sampling each vertex independently with probability \(n^{-1/3}\).
Add the \(O(n^{1/3} \log n)\) lightest edges incident to every vertex to \(H\).
Compute MSSP from \(S\) and add \(S \times S\) to \(H\) with weights \(\mathrm{wt}(s_1, s_2) = \mathrm{dist}(s_1, s_2)\).
Since we follow the algorithm exactly, we omit the proof of correctness. To analyze the running time, note that the first two steps require \(O(n^2 \log n)\) time. By [thm:bounded-weight-mssp], MSSP requires \(Bn^{\omega(1, 2/3, 1) + o(1)}\), which bounds the running time of our algorithm. ◻
We give a simple recursive scheme that obtains optimal running time for directed reachability.
Definition 4 (Multiple Source Reachability). Given directed graph \(G = (V, E)\) and a set of sources \(S_{\mathrm{in}} \subseteq V\), compute \(\mathrm{reach}(s, v)\) for all \(s \in S_{\mathrm{in}}\) and \(v \in V\).
Proof. Without loss of generality, we may assume that the graph \(G\) is a directed acyclic graph (DAG) and \(G\) is topologically sorted. In particular, we first decompose the graph into strongly connected components (SCC) and apply a topological sort to the remaining DAG. After this transformation, let \(S_{\mathrm{in}}\) denote all the strongly connected components of the input graph that intersect the input \(S_{\mathrm{in}}\). Note that both the SCC decomposition (which preserves reachability) and topological sort can be computed in linear time.
Given the assumption, we let \(a \leqslant b\) denote comparison in the topological order. Let \([a, b] \subseteq V\) denote all vertices between \(a\) and \(b\) (inclusive) in the topological order. Furthermore, given \(s, v \in V\), let \(\mathrm{pred}(s, v)\) denote the minimum vertex \(a\) (in topological order) such that \(\mathrm{reach}(s, a) = 1\) and \((a, v) \in E\). That is, there is a path from \(s\) to \(v\) such that \(a\) is the vertex immediately preceding \(v\).
With our assumptions, consider the following recursive procedure.
\(\textsf{complete}(G, S_{\mathrm{in}}, L, R)\):
Input: Topologically sorted DAG \(G\), sources \(S_{\mathrm{in}}\), and interval endpoints \(L \leqslant R\).
(Assume \(\mathrm{reach}(s, v)\) is computed for \(s \in S_{\mathrm{in}}\) and \(v\) where either \(v \leqslant L\) or \(\mathrm{pred}(s, v) \leqslant L\).)
If \(R - L \leqslant 2\), compute \(\mathrm{reach}(s, v)\) for all \(s \in S_{\mathrm{in}}\) and \(L < v \leqslant R\).
Set \(M \gets \lfloor (L + R) / 2 \rfloor\) and run \(\textsf{complete}(G, S_{\mathrm{in}}, L, M)\).
Construct \(S_{\mathrm{in}} \times [L, M]\) matrix \(X\) and \([L, M] \times [M, R]\) matrix \(Y\) with entries \[X[s, u] = \mathrm{reach}(s, u),\quad Y[u, v] = \mathbb{1}\left[ (u, v) \in E \right] \text{.}\] Compute \(XY\) and update \(\mathrm{reach}(s, v) \overset{\vee}{\gets}(XY)[s, v]\) for all \(s \in S_{\mathrm{in}}, v \in V\).
Run \(\textsf{complete}(G, S_{\mathrm{in}}, M, R)\).
Our algorithm for Multiple-Source Reachability computes \(\textsf{complete}(G, S_{\mathrm{in}}, 0, |V|)\). We prove the correctness of our algorithm via the following inductive claim.
Claim 9. Suppose \(\mathrm{reach}(s, v)\) is computed for all \((s, v)\) such that \(s \in S_{\mathrm{in}}\) and \(v \leqslant L\) or \(\mathrm{pred}(s, v) \leqslant L\) before the execution of \(\textsf{complete}(G, S_{\mathrm{in}}, L, R)\). Then, after the execution of \(\textsf{complete}(G, S_{\mathrm{in}}, L, R)\), \(\mathrm{reach}(s, v)\) is computed for all \((s, v)\) with \(s \in S_{\mathrm{in}}\) and \(v \leqslant R\).
First, we argue that the claim suffices to compute \(\mathrm{reach}(s, v)\) for all \(s \in S_{\mathrm{in}}\) and \(v \in V\). When \(L = 0\), there is exactly one vertex \(\leqslant L\), say \(s^*\) in \(L\). If \(s^* \not\in S_{\mathrm{in}}\), then we set \(\mathrm{reach}(s, v) = 0\) for all \(s, v\). If \(s^* \in S_{\mathrm{in}}\), we note \(\mathrm{pred}(s, v) \leqslant 0\) if and only if \(v \in N^{+}(s^*)\) is an out-neighbor of \(s^*\). In this case, we update \(\mathrm{reach}(s^*, v) = 1\) for all \(v \in N^{+}(s^*)\) in \(O(n)\) time. In either case, the assumption of 9 is satisfied. Thus, the claim ensures that \(\mathrm{reach}(s, v)\) is computed for all \(s \in S_{\mathrm{in}}\) and \(v \in V\). It remains to prove 9.
Proof of 9. We begin by describing how to compute \(\textsf{complete}\) in the base case (i.e. \(R - L \leqslant 2\)). Note that in \(O(1)\) time, we can compute \(\mathrm{reach}(a, b)\) for all \(a, b \in [L, R]\). Then, for all \(s \in S_{\mathrm{in}}\) and \(v \in [L, R]\), we set \[\label{eq:base-r-update} \mathrm{reach}(s, v) \overset{\vee}{\gets}\bigvee_{L \leqslant u < v} (\mathrm{reach}(s, u) \wedge \mathrm{reach}(u, v)) \text{.}\tag{4}\] This completes the description of our algorithm.
To prove correctness, we first observe that whenever \(\mathrm{reach}(s, v) = 1\), there exists a path from \(s\) to \(v\). Thus, it suffices to show that we set \(\mathrm{reach}(s, v) = 1\) if there exists a path from \(s\) to \(v\). Fix \(s \in S_{\mathrm{in}}\) and \(v \leqslant R\) such that there is a path from \(s\) to \(v\). We may assume \(v > L\) and \(\mathrm{pred}(s, v) > L\). Otherwise, we already have \(\mathrm{reach}(s, v) = 1\) by the input assumption, and observe that our algorithm never decreases (i.e.flip from 1 to 0) \(\mathrm{reach}(s, v)\).
We then proceed by induction, beginning with the base case. In the base case, we need to compute \(\mathrm{reach}(s, v)\) for \(s \in S_{\mathrm{in}}\) and \(L < v \leqslant R \leqslant L + 2\). Since we compute the transitive closure of \([L, R]\), we compute reachability following the update rule of 4 if \(s \leqslant L\) and from the transitive closure of \([L, R]\) if \(L \leqslant s \leqslant R\).
We now conclude the proof of correctness with the inductive case. We may assume \(v > M\), as otherwise the first recursive call \(\textsf{complete}(G, S_{\mathrm{in}}, L, M)\) computes \(\mathrm{reach}(s, v)\). We consider two cases.
We have \(L < \mathrm{pred}(s, v) \leqslant M\), or there exists \(L < u \leqslant M\) such that \(\mathrm{reach}(s, u) = 1\) and \((u, v) \in E\). In this case, since \(u \leqslant M\), we have \(X[s, u] = \mathrm{reach}(s, u) = 1\) and \(Y[u, v] = 1\). In particular, \((XY)[s, v] = 1\) so we set \(\mathrm{reach}(s, v) \gets 1\) as desired.
From the previous case, when we call \(\textsf{complete}(G, S_{\mathrm{in}}, M, R)\), we have computed \(\mathrm{reach}(s, v)\) for all \(s \in S_{\mathrm{in}}\) and \(v \leqslant M\) (handled by first recursive call) or \(\mathrm{pred}(s, v) \leqslant M\) (handled by Case 1). Thus, we satisfy the input assumption of 9, and obtain \(\mathrm{reach}(s, v)\) for all \(v \leqslant R\) by induction. ◻
Finally, we bound the running time. Note that an invocation of the base case requires \(O(|S_{\mathrm{in}}|)\) time. In the base case, we compute the transitive closure of \([L, R]\) in \(O(1)\) time as the graph is sorted in topological order, so it suffices to compute the transitive closure of \(G[L, R]\), a graph of \(O(1)\) vertices. Next, compute 4 in \(O(|S_{\mathrm{in}}|)\) time, which bounds the running time of the base case.
Consider an invocation of the algorithm when \(R - L = \ell\). In this case, we make two recursive calls to intervals of size \(\ell/2\) and compute a \(S_{\mathrm{in}} \times \ell \times \ell\) matrix product in \(\mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, \ell, \ell)\) time. In other words, we obtain the recursion \[T(\ell) = 2 T(\ell/2) + \mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, \ell, \ell)\] which we claim resolves to \(T(\ell) = \widetilde{O}\left(\mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, \ell, \ell)\right)\). Formally, we first show the following claim.
Claim 10. For any \(\ell \geqslant 0\), \[\mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, \ell, \ell) \geqslant 2 \mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, \ell/2, \ell/2) \text{.}\] The claim holds also if we replace \(\mathsf{T}_{\mathrm{BMM}}\) with \(\mathsf{T}_{\mathrm{MPP}}(S_{\mathrm{in}}, \ell, \ell \mid B_1, B_2)\).
Proof. Let \(A, B\) be arbitrary \(S_{\mathrm{in}} \times \ell/2\) boolean matrices (resp. integer matrices with finite entries in \([B_1]\)) and \(C, D\) be arbitrary \(\ell/2 \times \ell/2\) boolean matrices (resp. integer matrices with finite entries in \([B_2]\)). Then, define \[X = \begin{pmatrix} A & B \end{pmatrix},\quad Y = \begin{pmatrix} C & 0_{\ell/2 \times \ell/2} \\ 0_{\ell/2 \times \ell/2} & D \end{pmatrix}\] so that \(XY = \begin{pmatrix} AC & BD \end{pmatrix}\). In particular, we compute two arbitrary \(S_{\mathrm{in}} \times \ell/2 \times \ell/2\) matrix products with one \(S_{\mathrm{in}} \times \ell \times \ell\) matrix product. ◻
Then, we can bound the running time of one recursive call as \[\begin{align} T(\ell) &= 2 T(\ell/2) + \mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, \ell, \ell) \\ &= O\left(\sum_{0 \leqslant i \leqslant\log \ell} \frac{\ell}{2^{i}} \mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, 2^{i}, 2^{i})\right) \\ &= O\left(\mathsf{T}_{\mathrm{BMM}}(S_{\mathrm{in}}, \ell, \ell) \log \ell\right) \end{align}\] where in the final inequality we apply 10. ◻
In fact, our algorithm, with minor modifications, can be used to compute MSSP on unweighted directed acyclic graphs.
We in fact prove a slightly stronger result.
Proposition 11. Let \(B, D \geqslant 1\). Then, there is a deterministic algorithm computing MSSP on directed acyclic graph with edge weights in \(\left\{ 0, \dots, B \right\}\) and \(\mathrm{diam}(G) \leqslant D\) in \(\widetilde{O}\left(\mathsf{T}_{\mathrm{MPP}}(S_{\mathrm{in}}, n, n \mid D, B)\right)\) time.
[thm:dag-mssp] follows by applying \(B = 1\) and \(D = n\).
Proof. As before, we assume the graph is sorted in topological order, and keep the same notation as [thm:msreach]. We let \(\widehat{\mathrm{d}}(s, v)\) denote the estimated distance between \(s \in S_{\mathrm{in}}\) and \(v \in V\), with all values initialized to \(\infty\). We then run the following algorithm, replacing \(\mathrm{reach}\) with \(\widehat{\mathrm{d}}\) and \(\mathrm{BMM}\) with \(\mathrm{MPP}\).
\(\textsf{complete}(G, S_{\mathrm{in}}, L, R)\):
Input: Topologically sorted DAG \(G\), sources \(S_{\mathrm{in}}\), and interval endpoints \(L \leqslant R\).
(Assume \(\widehat{\mathrm{d}}(s, v) = \mathrm{dist}(s, v)\) is computed for \(s \in S_{\mathrm{in}}\) and \(v\) where either \(v \leqslant L\) or \(\mathrm{pred}(s, v) \leqslant L\).)
If \(R - L \leqslant 2\), compute \(\widehat{\mathrm{d}}(s, v)\) for all \(s \in S_{\mathrm{in}}\) and \(L < v \leqslant R\).
Set \(M \gets \lfloor (L + R) / 2 \rfloor\) and run \(\textsf{complete}(G, S_{\mathrm{in}}, L, M)\).
Construct \(S_{\mathrm{in}} \times [L, M]\) matrix \(X\) and \([L, M] \times [M, R]\) matrix \(Y\) with entries \[X[s, u] = \widehat{\mathrm{d}}(s, u),\quad Y[u, v] = \begin{cases} \mathrm{wt}(u, v) & (u, v) \in E \\ \infty & \textrm{ o/w } \end{cases} \text{.}\] Compute \(X * Y\) and update \(\widehat{\mathrm{d}}(s, v) \overset{\min}{\gets}(X * Y)[s, v]\) for all \(s \in S_{\mathrm{in}}, v \in [M, R]\).
Run \(\textsf{complete}(G, S_{\mathrm{in}}, M, R)\).
In the base case when \(R - L \leqslant 2\), we compute APSP on the induced subgraph \(G[L, R]\) which has \(O(1)\) vertices and contains the shortest path between any pair of vertices \(u, v \in [L, R]\). This requires \(O(1)\) time and we can update distances analogously to 4 as follows for all \(s \in S_{\mathrm{in}}, v \in [L, R]\): \[\label{eq:base-dag-update} \widehat{\mathrm{d}}(s, v) \overset{\min}{\gets}\min_{L \leqslant u \leqslant R} \widehat{\mathrm{d}}(s, u) + \widehat{\mathrm{d}}(u, v) \text{.}\tag{5}\] Our algorithm for MSSP sets \(\widehat{\mathrm{d}}(s, v) = 0\) for all \(s \in S_{\mathrm{in}}, v \in N(s)\) and computes \(\textsf{complete}(G, S_{\mathrm{in}}, 0, |V|)\).
The correctness proof follows similarly to [thm:msreach], we highlight the necessary modifications here. As before, without loss of generality let the first vertex in topological order denoted \(s^*\) be in \(S_{\mathrm{in}}\). At the root level, when we invoke \(\textsf{complete}(G, S_{\mathrm{in}}, 0, |V|)\), we have \(\widehat{\mathrm{d}}(s, v) = \mathrm{dist}(s, v)\) for all \(s \in S_{\mathrm{in}}\) and \(\mathrm{pred}(s, v) \leqslant 0\) i.e. \(\mathrm{pred}(s, v) = s^*\), satisfying the input assumption.
In the base case (i.e.\(R - L \leqslant 2\)) we compute \(\widehat{\mathrm{d}}(u, v) = \mathrm{dist}(u, v)\) for all \(u, v \in [L, R]\) as \(G[L, R]\) contains all shortest paths between \(u, v \in [L, R]\) since \(G\) is a DAG. Thus, we obtain correct distances following 5 if \(s \leqslant L\) and from APSP on \(G[L, R]\) if \(L \leqslant s \leqslant R\). The proof of the inductive case follows identically to [thm:msreach].
To bound the running time, we have the recursion \[T(\ell) = 2 T(\ell/2) + \mathsf{T}_{\mathrm{MPP}}(S_{\mathrm{in}}, \ell, \ell \mid D, B)\] since \(X\) has finite entries bounded by \(D\) and \(Y\) has finite entries bounded by \(B\). Following the same analysis as 10, we obtain the time bound \(T(\ell) = \widetilde{O}\left(\mathsf{T}_{\mathrm{MPP}}(S_{\mathrm{in}}, \ell, \ell \mid D, B)\right)\). ◻
We give our improved algorithm for computing shortcut sets of linear size. Recall that for a directed graph \(G\), \(\mathrm{TC}(G)\) denotes the transitive closure of \(G\) and \(\mathrm{diam}(G)\) is the maximum of \(\mathrm{dist}(u, v)\) over \((u, v) \in \mathrm{TC}(G)\).
Definition 5. A set of edges \(F\) is a \(D\)-shortcut-set for directed graph \(G = (V, E)\) if \(\mathrm{TC}(G) = \mathrm{TC}(G \cup F)\) and \(\mathrm{diam}(G \cup F) \leqslant D\).
We give a faster algorithm for computing shortcut sets.
Theorem 12. For \(D = O(\sqrt{n})\), there is an algorithm that computes a \(D\)-shortcut-set of size \(\widetilde{O}\left(n^2/D^3 + n\right)\) in time \(\tilde{O}\left(n^{2} + \mathsf{T}_{\mathrm{MPP}}(n/D^2, n, n \mid D, 1)\right)\).
We remark that using our algorithm for Multiple Source Reachability, one can achieve a running time of \(\mathsf{T}_{\mathrm{BMM}}(n/D, n, n)\). However, 12 is at least as fast for all \(D = O(\sqrt{n})\).
Proof of 12. We recap the algorithm of [68], beginning with the necessary definitions. Without loss of generality, we may assume that the input graph \(G\) is directed and acyclic (DAG). Given a graph \(G\), \(\mathrm{LP}(G)\) denotes the length of the longest simple path in \(G\). For a subset of vertices \(U \subseteq V\), \(G[U]\) is the induced subgraph of \(G\) on \(U\). We define \(\ell\)-covers and chains.
Definition 6. Given a directed graph \(G\), an \(\ell\)-cover is a collection of \(\ell\) (not necessarily disjoint) paths in \(G\), \({\cal P}= \left\{ P_{1}, \dots, P_{\ell} \right\}\) satisfying:
(Size Bound) \(\sum_{P \in {\cal P}} |P| \leqslant\min(\ell, \mathrm{diam}(G)) \cdot n\).
(Longest Path Bound) \(\mathrm{LP}(G') \leqslant 2n/\ell\) where \(G' = \mathrm{TC}(G)[U]\) and \(U = V \setminus V({\cal P})\).
Definition 7. Given a directed graph \(G\), a chain is a path in \(\mathrm{TC}(G)\).
Given a vertex \(v\) and a chain \(C\), let \(w := w(v, C)\) denote the first vertex in \(C\) such that \((v, w) \in \mathrm{TC}(G)\), if such a vertex exists. We are now ready to state the algorithm of [68].
Compute \(H_0\), a shortcut set of diameter \(D_0 = O(\sqrt{n})\) of size \(\widetilde{O}\left(n\right)\).
Compute an \(\ell\)-cover \({\cal P}\) of \(G \cup H_{0}\) where \(\ell = 16 n/D\).
Compute \({\cal C}\), a collection of vertex disjoint chains in \(G\) satisfying (i) \(|{\cal C}| \leqslant|{\cal P}|\) and (ii) \(V({\cal C}) = V(P)\).
For every \(C \in {\cal C}\), compute \(H(C)\): a \(2\)-shortcut-set for \(C\).
Let \(V' \subset V, {\cal C}' \subset {\cal C}\) be random subsets where each vertex (resp. chain) is sampled with probability \(p = \Theta(\log n/D)\).
Compute \(\hat{H} = \left\{ (v, w(v, C)) \textrm{ s.t. }v \in V', C \in {\cal C}' \text{ if } w(v, C) \text{ exists} \right\}\).
Return \(H_{0} \cup \left(\bigcup_{C \in {\cal C}} H(C)\right) \cup \hat{H}\).
The above algorithm returns a \(D\)-shortcut-set of size \(\widetilde{O}\left(n^2/D^3 + n\right)\) (see Theorem 1.4 of [68]). It suffices for us to analyze the running time. Step 1 requires time \(\widetilde{O}\left(m + n^{3/2}\right)\) by Theorem 1.3 of [68]. Step 2 requires time \(\widetilde{O}\left(m + n^{3/2} + n \cdot \min(\mathrm{diam}(G), \ell)\right)\) by Theorem 2.3 of [68]. Step 3 requires time \(\widetilde{O}\left(\sum_{P \in {\cal P}} |P|\right)\) by Lemma 1.15 of [68]. Step 4 requires time \(\widetilde{O}\left(\sum_{C \in {\cal C}} |C|\right)\) by Lemma 1.10 of [68]. Step 5 requires time \(O(n + |{\cal C}|)\). Step 7 requires time \(\widetilde{O}\left(n\right)\) by the size of the shortcut set. In total, all steps (excluding step 6) require time \(\widetilde{O}\left(n^2\right)\).
It thus suffices to analyze the running time of step 6, for which we propose a new algorithm. First, we need a simple bound on \(|V'|, |{\cal C}'|\).
Claim 13. With high probability, \(|V'| = O\left(n \log n /D\right)\) and \(|{\cal C}'| = O\left(n \log n/D^2\right)\).
Proof. Note that \(|V'|\) is a sum of independent Bernoulli variables with mean \(O(n \log n/D)\). A Chernoff bound shows that \(\Pr(|V'| > 10 \mu) < \exp(- \mu) \ll n^{-10}\). A similar bound holds for \(|{\cal C}'|\), a sum of independent Bernoulli variables with mean \(\widetilde{O}\left(n \log n /D^2\right)\). ◻
Next, we argue that we can assume that the length of each chain is at most twice the average.
Claim 14. Given a collection of vertex disjoint chains \({\cal C}_{0}\) of size \(\ell\), there is a collection of vertex disjoint chains \({\cal C}\) of size \(\ell\) satisfying (1) \(V({\cal C}) = V({\cal C}_{0})\) and (2) each \(C \in {\cal C}\) satisfies \(|C| \leqslant 2 n/\ell\). Furthermore, \({\cal C}\) can be computed in \(O(n)\) time.
Proof. For every chain \(C \in {\cal C}_{0}\) of length \(|C| > n/\ell\), we split \(C\) into \(|C| \ell / n\) chains of length at most \(2 n/\ell\). Let \({\cal C}\) be the union of all the split chains. Note that \({\cal C}\) is vertex disjoint and \(V({\cal C}) = V({\cal C}_{0})\). Furthermore, every \(C \in {\cal C}\) satisfies \(|C| \leqslant 2 n/\ell\). We bound the size of \({\cal C}\) as \[\sum_{C \in {\cal C}_{0}} |C| \ell / n \leqslant\frac{\ell}{n} \sum_{C \in {\cal C}_{0}} |C| \leqslant\ell\] where we use the fact that \({\cal C}_{0}\) are vertex disjoint so \(\sum_{C \in {\cal C}_{0}} |C| \leqslant n\). It is clear that \({\cal C}\) can be computed in \(O(n)\) time. ◻
By running 14 immediately after step 3, we have the additional property that each chain has length \(\leqslant 2n/\ell = D/8\). Note that we maintain the required properties of \({\cal C}\), so that correctness is maintained. As a corollary of 13 and 14, we have that with high probability \[\label{eq:total-chain-bound} V({\cal C}') = O(n \log n / D) \text{.}\tag{6}\] We now present our algorithm for computing \(\hat{H}\). Consider the graph \(\overline{G}\) constructed as follows:
Add a vertex for every \(v \in V(G)\) and edge \(e \in E(G)\) with weight \(\mathrm{wt}(e) = 0\).
For every \(C \in {\cal C}'\), add a vertex \(t_{C}\).
For every \(C \in {\cal C}'\), denote \(C = \left\{ c_{1}, \dots, c_{p} \right\}\). Add a path \(\pi_{C, i}\) of \(i\) edges with weight \(1\) from \(c_{i}\) to \(t_{C}\) for all \(1 \leqslant i \leqslant p\). Note that distinct \(\pi_{C, i}\) are vertex disjoint except for \(t_{C}\).
We claim that distances from \(v \in V'\) to \(t_{C}\) for \(C \in {\cal C}'\) allow us to compute \(w(v, C)\).
Claim 15. Let \(v \in V'\) and \(C \in {\cal C}'\). Let \(C = \left\{ c_{1}, \dots, c_{p} \right\}\). Then, \(w(v, C) = c_{i}\) if and only if \(\mathrm{dist}_{\overline{G}}(v, t_{C}) = i\).
Proof. Fix \(v \in V', C \in {\cal C}'\) and let \(w := w(v, C)\). If \(w = c_{i}\), there is a path from \(v\) to \(w\) using only edges in \(E(G)\), and thus a path \(P_{0}\) of weight \(0\) from \(v\) to \(w\) in \(\overline{G}\). Then, \(P_{0} \circ \pi_{C, i}\) is a path of length \(i\) from \(v\) to \(t_{C}\), establishing \(\mathrm{dist}_{\overline{G}}(v, t_{C}) \leqslant i\).
Suppose \(\mathrm{dist}_{\overline{G}}(v, t_{C}) < i\). We claim there is a vertex \(c_{j}\) with \(j < i\) such that \((v, c_{j}) \in \mathrm{TC}(G)\), contradicting the minimality of \(c_{i}\). Let \(c_{j}\) be the final vertex in \(C\) on the shortest path from \(v\) to \(t_{C}\). Note that \(j < i\) since the \(\pi_{C, j}\) has length \(j\). However, this implies that \((v, c_{j}) \in \mathrm{TC}(G)\) since there is no path from vertices in \(\pi_{C', i'} \setminus c'_{i'}\) for any \(C', i'\) to vertices in \(G\), so any path from \(v\) to \(c_{j}\) must be contained in \(E(G)\). In particular, \((v, c_{j}) \in \mathrm{TC}(G)\), contradicting the minimality of \(i\). ◻
Thus, it suffices to compute \(\mathrm{dist}_{\overline{G}}(v, t_{C})\) for all \(v \in V'\) and \(C \in {\cal C}'\). Equivalently, we can compute \(\mathrm{dist}_{\overline{G}_{\mathrm{rev}}}(t_{C}, v)\), which requires one invocation of MSSP on \(\overline{G}_{\mathrm{rev}}\). To bound the running time, it remains to show that \(\overline{G}\) is a DAG with \(\widetilde{O}\left(n\right)\) vertices and diameter \(O(D)\). The number of vertices in \(\overline{G}\) is \[O\left(n + |{\cal C}'| D^2\right) = O\left(n \log n\right) \text{.}\] Next, we claim \(\overline{G}\) is a DAG. First, observe that there is no path from any vertex not in \(V(G)\) to a vertex in \(V(G)\), so no SCC can contain both a vertex in \(V(G)\) and one not in \(V(G)\). In particular, the additional vertices and edges introduce no paths between vertices in \(V(G)\), so no SCC can contain multiple vertices in \(V(G)\). To conclude, observe that no SCC can contain multiple vertices not in \(V(G)\). Finally, we claim \(\overline{G}\) has diameter \(O(D)\). This follows as any \((u, v) \in \mathrm{TC}(G)\) has a path of length \(0\) in \(\overline{G}\) (by following edges in \(G\)) and any of the additional paths \(\pi_{C, i}\) has length \(O(D)\) by 14.
Thus, we invoke 11 on \(\overline{G}_{\mathrm{rev}}\) with sources \(\left\{ t_{C} \right\}\) to compute the required distances and \(\hat{H}\) in \(\widetilde{O}\left(\mathsf{T}_{\mathrm{MPP}}(n/D^{2}, n, n \mid D, 1)\right)\) time, completing the proof of 12. ◻
In this appendix, we discuss lower bounds for directed MSSP from Min-Plus Matrix Multiplication. We begin with the lower bound given in 2 .
Proposition 16. Any algorithm that computes MSSP on unweighted directed acyclic graphs with \(5n\) vertices and \(s\) sources requires time \[\Omega\left(\max_{1 \leqslant t \leqslant n} \mathsf{T}_{\mathrm{MPP}}\left(s, t, n \mid \frac{n}{\min(s, t)}, \frac{n}{t} \right)\right) \text{.}\]
Proof. For any \(1 \leqslant t \leqslant n\), consider an \(s \times t\) matrix \(X\) with entries in \([n/\min(s, t)] \cup \left\{ \infty \right\}\) and a \(t \times n\) matrix \(Y\) with entries in \([n/t] \cup \left\{ \infty \right\}\). When \(t \leqslant s\), we immediately inherit the lower bound of \[\Omega\left(\max_{1 \leqslant t \leqslant n} \mathsf{T}_{\mathrm{MPP}}\left(s, t, n \mid \frac{n}{t} \right)\right)\] given by [29]. Thus, for the remainder of the proof, we assume \(s \leqslant t\). Construct a graph \(G\) with vertex sets \[A = \left\{ a_{i} \right\}_{i \in [s]},\quad B = \left\{ b_{i} \right\}_{i \in [n]},\quad C = \left\{ c_{i} \right\}_{i \in [n]}, \quad P = \left\{ p_{ij} \right\}_{i \in [s], j \in [n/s]}, \quad Q = \left\{ q_{ij} \right\}_{i \in [t], j \in [n/t]} \text{.}\] Note that the number of vertices is \(s + 4n \leqslant 5n\). We describe the edge sets. For each \(i \in [s]\), there is a directed path \((a_{i}, p_{i1}, \dots, p_{i, n/s})\). For each \(i \in [t]\), there is a directed path \((b_{i}, q_{i1}, \dots, q_{i, n/t})\). For each \((i, k) \in [s] \times [t]\), there is an edge \((p_{iv}, b_{k})\) where \(X[i, k] = v\). For each \((k, j) \in [t] \times [n]\), there is an edge \((q_{kv}, c_{j})\) where \(Y[k, j] = v\). This completes the description of our graph. Let \(S_{\mathrm{in}} = A\). To complete the proof, we claim that for all \((i, j) \in [s] \times [n]\), \[\mathrm{dist}(a_{i}, c_{j}) = (X * Y)[i, j] + 2 \text{.}\]
Suppose \((X * Y)[i, j] = X[i, k] + Y[k, j]\) for some \(k \in [t]\). Then, the path \((a_{i}, p_{i1}, \dots, p_{iv}, b_{k}, q_{k1}, \dots, q_{kw}, c_{j})\) where \(X[i, k] = v\) and \(Y[k, j] = w\) is a path of length \(v + w + 2\) from \(a_{i}\) to \(c_{j}\) so \(\mathrm{dist}(a_{i}, c_{j}) \leqslant(X * Y)[i, j] + 2\).
Suppose for contradiction \(\mathrm{dist}(a_{i}, c_{j}) = \ell < (X * Y)[i, j] + 2\). Then, there is a path \((a_{i}, v_{1}, \dots, v_{\ell - 1}, c_{j})\). By construction, there exists \(k', v', w'\) such that the path takes the form \((a_{i}, p_{i1}, \dots, p_{iv'}, b_{k'}, q_{k'1}, \dots, q_{k'w'}, c_{j})\). However, this implies that there exists \(k'\) with \(X[i, k'] = v', Y[k', j] = w'\) such that \(v' + w' + 2 = \ell < (X * Y)[i, j] + 2\), contradicting the minimality of \(k\). ◻
There are several known algorithms for computing \(\mathrm{MPP}(n_1, n_2, n_3 \mid B_1, B_2)\):
We can compute \(\mathrm{MPP}(n_1, n_2, n_3 \mid \max(B_1, B_2))\) in time \(\widetilde{O}\left(\max(B_1, B_2) \mathsf{T}_{\mathrm{MUL}}(n_1, n_2, n_3)\right)\) [15].
[29] showed that (see Lemma B.2 of [29]) if \(B_1 \leqslant B_2\), then \[\mathsf{T}_{\mathrm{MPP}}(n_1, n_2, n_3 \mid B_1, B_2) = \tilde{O}\left(\min_{1 \leqslant t \leqslant n_2 n_3} \mathsf{T}_{\mathrm{MPP}}\left(n_1, n_2, \frac{n_2n_3}{t} \mid B_1 \right) + t n_1 n_3\right) \text{.}\] Similarly, if \(B_2 \leqslant B_1\), then \[\mathsf{T}_{\mathrm{MPP}}(n_1, n_2, n_3 \mid B_1, B_2) = \tilde{O}\left(\min_{1 \leqslant t \leqslant n_1 n_2} \mathsf{T}_{\mathrm{MPP}}\left(\frac{n_1 n_2}{t} , n_2, n_3 \mid B_2 \right) + t n_1 n_3\right) \text{.}\]
We give a simple algorithm that beats the above two algorithms in certain regimes of parameters.
Proposition 17. Suppose \(\mathsf{T}_{\mathrm{BMM}}(a, b, c) = \Omega(ab + ac + bc)\). For any integers \(n_1, n_2, n_3, B_1, B_2, B \geqslant 0\), \[\mathsf{T}_{\mathrm{MPP}}(n_1, n_2, n_3 \mid B_1, B_2) = O\left(\mathsf{T}_{\mathrm{BMM}}(n_1 B_1, n_2, n_3 B_2)\right)\] and if \(B = B_1 + B_2\), \[\mathsf{T}_{\mathrm{MPP}}(n_1, n_2, n_3 \mid B_1, B_2) =O\left(\min \left( \mathsf{T}_{\mathrm{BMM}}(n_1 B, n_2 B_2 , n_3), \mathsf{T}_{\mathrm{BMM}}(n_1, n_2 B_1, n_3 B)\right)\right) \text{.}\]
Proof. We begin with the first bound. Let \(A, B\) be the input matrices. Construct a \(n_1 B_1 \times n_2\) matrix \(X\) and \(n_2 \times n_3 B_2\) matrix \(Y\) as follows \[X[(i, b), k] = \mathbb{1}\left[ A[i, k] = b \right], \quad Y[k, (j, c)] = \mathbb{1}\left[ B[k, j] = c \right] \text{.}\] Note that construction takes \(O(n_1 n_2 B_1 + n_2 n_3 B_2)\) time. Compute \(XY\) and note that \((A * B)[i, j] = \min \left\{ b + c \textrm{ s.t. }XY[(i, b), (j, c)] = 1 \right\}\) can be recovered from \(XY\) in \(O(n_1 n_3 B_1 B_2)\) time, or linear time in the size of \(XY\).
We now prove the second bound. Construct \(n_1 B \times n_2 B_2\) matrix \(X\) and \(n_2 B_2 \times n_3\) matrix \(Y\) as follows \[X[(i, b), (k, c)] = \mathbb{1}\left[ A[i, k] = b - c \right], \quad Y[(k, c), j] = \mathbb{1}\left[ B[k, j] = c \right] \text{.}\] Note that \(X, Y\) can be constructed in \(O(n_1 B n_2 B_2 + n_2 B_2 n_3)\) time. Compute \(XY\) and note that \((A * B)[i, j] = \min\left\{ b \textrm{ s.t. }(XY)[(i, b), j] = 1 \right\}\) can be recovered from \(XY\) in \(O(n_1 n_3 B)\) time, or linear time in the size of \(XY\). The second term in the minimum follows by a symmetric argument. ◻
4 compares the running time of our directed MSSP algorithm ([thm:dag-mssp]), the directed MSSP algorithm of [56], and the best known algorithms for computing 2 .
Supported by NSF HDR TRIPODS Phase II grant 2217058 (EnCORE Institute).↩︎
Throughout this paper, we consider dense graphs with \(m = O(n^2)\).↩︎
\(\omega \le 2.372\) [14] is the fast matrix multiplication exponent, or the smallest constant \(c\) such that an \(n \times n \times n\) matrix product can be computed in \(n^{c+o(1)}\) time. \(\widehat{O}\) hides sub-polynomial factors.↩︎
Our equivalence holds under the mild assumption that \(\mathsf{T}_{\mathrm{BMM}}(2m, 2n, 2n) \geqslant 4 \mathsf{T}_{\mathrm{BMM}}(m, n, n)\) for all \(m, n \geqslant 1\). Note that this assumption essentially requires that \(\mathrm{BMM}\) scales at least linearly with input size. We remark that our improved running time holds regardless of the assumption. See proof of 3 for details.↩︎
Let \(A\) be an \(s \times n\) matrix and \(B\) an \(n \times n\) matrix. We build a three layered graph with vertex layers \(V_1, V_2, V_3\), where \(|V_1| = s\), \(|V_2| = |V_3| = n\), encode \(A\) into \(V_1 \times V_2\) (i.e., there is an edge if the corresponding entry of \(A\) is \(1\), and no edge otherwise) and \(B\) into \(V_2 \times V_3\), and note that for \(i \in V_1, j \in V_3\), \(\mathrm{dist}(i, j) = 2\) if and only if \((AB)[i, j] = 1\).↩︎
Like [cor:mssp], the equivalence holds under the mild assumption that \(\mathsf{T}_{\mathrm{MPP}}(2m, 2n, 2n \mid B) \geqslant 4 \mathsf{T}_{\mathrm{MPP}}(m, n, n \mid B)\) for all \(m, n \geqslant 1\). As before, our improved running time holds regardless of the assumption.↩︎
\(\omega(a, b, c)\) is the rectangular matrix multiplication exponent, or the smallest constant \(d\) such that an \(n^{a} \times n^{b} \times n^{c}\) matrix product can be computed in \(n^{d+o(1)}\) time.↩︎
Their algorithm is actually more general and can be used to solve multiple-source multiple-target shortest paths.↩︎
To avoid confusion, we call our decomposition a low diameter small neighborhood decomposition.↩︎