Manuscript Offprint
arXiv:2611.03594Square-Root Pass Semi-Streaming Algorithms for Digraph Problems
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
We study directed graph problems in the semi-streaming model where we are restricted to space for processing the edge stream of an -node graph and can make one or a few passes to solve the given problem. A longstanding open problem in multipass streaming is determining the number of semi-streaming passes needed to solve directed -reachability: there is an exponential gap— vs —between the best-known lower and upper bounds. Several related fundamental digraph problems, e.g., topological sorting, acyclicity testing, and decomposition into strongly connected components (SCCs), are known to have the same semi-streaming pass lower bound. However, no -pass upper bound was known for any of them. Our main result achieves an -pass semi-streaming algorithm for each of these problems. As a corollary, we get algorithms with the same pass and space usage for a broad class of DAG problems that admit a certain form of dynamic program over a topological ordering. This class includes weighted single-source shortest paths, longest paths, max-outdegree+1 coloring, and constructing a lexicographically-first DFS (depth-first search) forest. Our algorithm for the last problem can be seen as a generalization of our results on topological sorting and acyclicity testing: recall that standard textbook algorithms for these problems use DFS as a subroutine.
It is easy to show that all our algorithms are optimal up to an factor in passes under the reasonable conjecture that -reachability requires semi-streaming passes (weaker than the conjecture that the current-best bound is tight). However, using the fact that our algorithms can be parameterized by the number of passes taken by topological sorting or single-source reachability algorithms, we prove stronger lower bounds for some of the problems even under weaker conjectures. Along this line, we define complexity classes of digraph problems according to their semi-streaming pass complexity and explore the relationships among these classes. Overall, this presents a clearer picture of the hardness of various graph problems in the semi-streaming model.
- (pghosh@tntech.edu) Department of Computer Science, Tennessee Tech University, USA. Funded in part by startup support provided by the Department of Computer Science and the College of Engineering at Tennessee Tech. † (amirhossein26@ru.is) Department of Computer Science, Reykjavík University, Iceland.
1 Introduction
The semi-streaming model has emerged as a natural setting for processing massive graphs arriving as a stream of edges. Semi-streaming algorithms are restricted to space for an -node graph, which is sublinear in the (worst-case) number of edges, while permitting small amount of information per vertex. This makes many graph problems tractable [FKM+05]. When a single pass is insufficient for a solution, a natural workaround is to make more passes over the stream and optimize this number.
Motivation and Background. The directed -reachability problem asks whether there is a directed path from a node to another node in the graph. It is one of the most basic problems in the study of graph algorithms, but surprisingly, its complexity is far from resolved in the streaming model. The seminal work of Guruswami and Onak [GO13] proved that any -pass streaming algorithm for the problem requires space. This means any semi-streaming algorithm must make at least passes. The lower bound holds even when the input graph is promised to be a DAG (directed acyclic graph). This lower bound extends to related directed graph problems. Chakrabarti, Ghosh, McGregor, and Vorotnikova [CGMV20] showed simple reductions from reachability on DAGs to acyclicity and topological sorting. Baweja, Jia, and Woodruff [BJW22] subsequently showed similar reductions to strong connectivity and decomposition into strongly connected components (SCCs). A couple of works made progress in improving the reachability lower bound, but only for sublogarithmic passes: Assadi and Raz [AR20] proved that almost-linear space is required for two passes, while [CKP+21] extended it to hold for passes. However, their general space/pass tradeoff lower bound did not improve the state of the art for semi-streaming space: the longstanding pass barrier remains.
The best-known upper bounds are nowhere close. Observe that passes are trivially sufficient: one can simulate DFS (depth-first search) in these many passes (by adding a new node to the DFS forest per pass), which is the textbook approach for all the aforementioned problems in the classical model. To the best of our knowledge, among these problems, only reachability has a published strongly-sublinear-in- pass upper bound for semi-streaming space: [AJJ+22] gave an -pass semi-streaming algorithm, building on the parallel reachability algorithm of Jambulapati, Liu, and Sidford [JLS19]. Their implementation extends to single-source reachability: one can determine all vertices reachable from a source , and moreover recover an explicit directed path for every reachable vertex .
There has been recent work on topological ordering in the streaming model: Chen, Lin, and Tsai [CLT25] developed parameterized streaming algorithms for the problem. They show that a DAG with independence number can be topologically sorted in passes using space, and an approximate topological ordering with maximum displacement can be leveraged to obtain an -pass algorithm using space. Indeed, these algorithms do not admit sublinear space for all DAGs (since and can be in the worst case). For arbitrary DAGs, they give a tradeoff of -passes and space (previously such an algorithm was given by Janthong [Jan14]). Their framework also yields parameterized algorithms for SCC decomposition, strong connectivity, and related problems. More recently, Chen, Cheung, Lin, and Tsai [CCLT26] studied directed strong-connectivity certificates parameterized by the independence number. In the insertion-only model, for instance, they obtain -pass algorithms using roughly space for a 1-strong-connectivity certificate, from which several directed connectivity tasks can be solved. Unfortunately, none of these results give -pass semi-streaming algorithms in the worst case.
Our Contributions with Comparison to Prior Work. Our first contribution is to match the reachability upper bound for topological sorting and SCC-decomposition. We give -pass semi-streaming algorithms for the problems on arbitrary digraphs. As immediate corollaries of our topological-sorting and SCC-decomposition algorithms, we obtain the same bound for cycle detection and cycle finding respectively. As mentioned above, each of these problems is known to be at least as hard as -reachability on DAGs. Thus, an improvement over our algorithms would, in particular, break the square-root barrier for reachability, at least for DAGs, and maybe shed light on the analogous square-root-depth barrier in parallel reachability, a more longstanding open problem.
We then establish topological sorting as a powerful tool for designing -pass semi-streaming algorithms for problems on DAGs. Many classical algorithms on DAGs can be solved by the following approach: first obtain a topological ordering, then evaluate a dynamic program (DP) along this ordering. In the static setting, the implementation is straightforward once the DP is figured out. In a graph stream, however, even knowing the ordering does not immediately make the dynamic program implementable: a vertex may have too many incident edges to store, while its predecessors and successors are scattered arbitrarily throughout the stream. We show that a broad class of such dynamic programs can nevertheless be simulated in semi-streaming passes, once a topological ordering is available. Combining this framework with our topological-sorting algorithm gives -pass semi-streaming algorithms for several classical DAG problems, almost all of which generalize -reachability. These include single-source shortest paths and the global longest-path problem.
Shortest paths are among the most ubiquitous primitives in graph algorithms, while longest paths in DAGs have classical applications to precedence-constrained scheduling and critical-path analysis [KW59]. Exact-distance computation is considerably more challenging in streaming than offline computation. Hence, existing work on these problems in the streaming setting have focused on approximation [KSS16, KT25, AHS26]. There are, however, known -pass algorithms for exact shortest path on undirected graphs [CFHT20]. On directed graphs, Elkin [Elk11] gave -pass -space algorithms for exact shortest paths, which necessitates passes for semi-streaming space. To our knowledge, no -pass algorithm was previously known for directed graphs, even for unweighted DAGs. Our algorithms work for weighted DAGs, even on ones with negative edge weights: the absence of negative cycles (in fact, any cycle) removes the usual difficulty.
Recall that DFS generalizes the fundamental problems of aylicity, topological sorting, and SCC decomposition: classical textbook algorithms use DFS to solve these problems [CLRS22]. It is therefore natural to ask whether our results can be generalized to perform DFS, i.e., to construct a DFS forest of the input graph, in the streaming model. Khan and Mehta [KM19] gave an -pass semi-streaming algorithm for constructing DFS trees of undirected graphs that can be improved to -pass when the DFS tree has height . [CFHT20] improved upon their results by designing -pass semi-streaming algorithms, again for undirected graphs. No bound better than the trivial was known for digraphs, even for DAGs. Moreover, an arbitrary DFS forest is not sufficient for all of the applications mentioned above: in particular, the standard DFS algorithm for topological sorting relies on the “finish times” in addition. Consider the most standard simulation of DFS: break ties in a given lexicographic order. We call the DFS forest thus obtained as the lexicographically first DFS forest (LF-DFS). It lets us recover the entire traversal, including its finishing times. We show that the LF-DFS of a DAG can be constructed in semi-streaming passes. The key structural ingredient is a non-trivial DP on the topological order that needs care to establish and then implement in semi-streaming space. Interestingly, while DFS has been a primitive for topological sort in the classical setting, we show that in the streaming model, the reverse is a natural solution.
Our final algorithmic problem is of a slightly different flavor. It is the -coloring problem: every DAG can be properly colored with colors, where is the maximum outdegree. One can show that the problem is at least as hard as -coloring ( is the max-degree of an undirected graph) but at least as easy as -coloring ( is the degeneracy of the graph). -coloring is known to be admit a single-pass semi-streaming algorithm [ACK19] while -coloring requires space in a single pass [BCG20]. Although we are not aware of any concrete multipass lower bounds for the -coloring problem when edges cannot repeat, it is known that its natural primitives like finding degeneracy value or a degeneracy ordering requires passes [AGL24]. However, no -pass upper bound is known for any of these degeneracy-based problems. We design an -pass -coloring algorithm. Although the problem does not admit a “stream-friendly” DP as the other ones, we combine the idea from our DP framework with other tools like -sampling and succeed in designing the algorithm. Complementing our algorithmic results, we show that unlike -coloring and -coloring [AKM22], -coloring does not admit a single-pass semi-streaming solution and actually requires linear (i.e., ) space. On the other hand, we also prove that similar to -coloring, -coloring requires passes when edges can repeat in the stream.
Finally, we explore hardness relative to the fundamental problems of reachability (single-pair and single-source)
There is an -pass lower bound for when edges can repeat in the stream [BCG20].
on DAGs and topological sorting. Under the natural conjecture that , -reachability needs passes, it is immediate that our algorithms are optimal up to passes. But since our algorithms can be parameterized by the number of passes required for topological sorting and that for single-source reachability, we show stronger lower bounds (tight up to constant or logarithmic factors) for certain problems even under weaker conjectures that topological sorting or single-source reachability require passes. Overall, our collection of results makes a significant advancement in the digraph streaming literature which has seen much slower progress than its undirected counterpart. We also present a clearer picture about the relative hardness of fundamental digraph problems whose complexity remains unresolved.
Theorem 1.1. Given a -pass semi-streaming algorithm for single-source reachability, there is an -pass semi-streaming algorithm for topologically sorting a DAG. In particular, there is an -pass semi-streaming algorithm for the problem.
An algorithm for acyclicity follows as an immediate corollary.
Corollary 1.2. Given a -pass semi-streaming algorithm for single-source reachability, there is an -pass semi-streaming algorithm for testing whether a graph has a directed cycle. In particular, there is an -pass semi-streaming algorithm for the problem.
Our next main theorem is an algorithm for SCC decomposition on general digraphs.
Theorem 1.3. Given a -pass semi-streaming algorithm for single-source reachability, there is an -pass semi-streaming algorithm on general digraphs for SCC decomposition, and in fact, for returning the SCCs in topological order. In particular, there is an -pass semi-streaming algorithm for SCC decomposition.
The above algorithm immediately implies an algorithm for finding a directed cycle (if one exists).
Corollary 1.4. Given a -pass semi-streaming algorithm for single-source reachability, there is an -pass semi-streaming algorithm for finding a directed cycle in a digraph, if one exists, or correctly report that none exists. In particular, there is an -pass semi-streaming algorithm for the problem.
Note that each of the above problems is fundamental to graph algorithms and can be useful primitives in future research on graph streaming. But prior to our work, no non-trivial -pass) semi-streaming algorithm was known for them for fully general graphs.
As a consequence of our topological ordering algorithm, we obtain semi-streaming algorithms with the same number of passes for a variety of problems on DAGs. We mention the most general of them, from which algorithms for their special but important variants follow.
Theorem 1.5. Given a -pass semi-streaming algorithm for topological sorting, there are -pass semi-streaming algorithms for the following problems on DAGs:
-
Weighted Single-Source Shortest Path Tree (negative weights allowed)
-
Weighted (Global) Longest Path
-
Lexicographically-First DFS Forest
-
-coloring
In particular, there are -pass semi-streaming algorithms for the above problems.
Except -coloring, all problems considered in this work can be shown to be at least as hard as , -reachability on DAGs. Hence, our bounds for the problems are optimal up to an -factor in passes subject to the natural conjecture that reachability on DAGs requires passes. However, since we can express our algorithms' pass usage by the number of passes required for topological sort and single-source reachability, we can show stronger bounds for a subset of these problems even under weaker conjectures that single-source reachability on DAGs or the topological sorting problem require passes: under the former, our algorithms are optimal up to factors, and under the latter, they are optimal to constant factors; see Section 5 for details.
1.2 Other Related Work
Apart from the works mentioned above, prior work relevant to ours include that of Laura and Santaroni [LS11] who gave an algorithm for SCC decomposition on W-streams (that allow streaming outputs) using working memory and passes. Ghosh and Kuchlous [GK24], and a subsequent work by Ghosh, Kuchlous, Mehra, and Mukhopadhyay [GKMM26] studied reachability, acyclicity, topological ordering, and SCC decomposition on the special class of digraphs called tournaments (oriented complete graphs), showing that there exist single-pass semi-streaming algorithms for the problems on such digraphs. They also gave single-pass -space algorithms for digraphs that are edges away from being a tournament. Very recently, [ABC+26] gave a -pass -approximate streaming algorithm for distance to monotonicity and argued about its optimality subject to the , -reachability bound.
1.3 Technical Overview
Topological Sorting. At a high level, our algorithm for topological sorting follows a divide-and-conquer strategy reminiscent of quicksort. Suppose that, for a given vertex, we can determine its ancestor and descendant sets in the streaming model. A sampled vertex can then be used as a pivot to partition the remaining vertices into three classes: its ancestors, its descendants, and the vertices unrelated to it. These classes have a natural relative order for topological ordering. By sampling multiple pivots simultaneously and combining their reachability information, we obtain a finer partition of the graph into subproblems whose relative ordering can be determined consistently.
The main challenge is to balance the rate at which the subproblems shrink against the resources required to process the sampled pivots. On the one hand, sufficiently aggressive sampling is needed to reduce the size of each subproblem quickly, thereby keeping the recursion depth, and hence the number of passes, small. On the other hand, increasing the number of sampled vertices creates more reachability queries and potentially many more subproblems. To execute these queries in parallel within semi-streaming space, the reduction in subproblem size must compensate for the growth in the number of sampled pivots.
To achieve this balance, we adopt the aggressive sampling scheme of [JLS19], in which the sampling probability increases exponentially with the recursion depth. This choice ensures that progressively smaller subproblems are paired with progressively larger pivot sets while keeping the total amount of reachability information manageable. We use the resulting ancestor–descendant relations not only to partition the graph recursively, but also to impose a consistent ordering on the generated subproblems. After sufficiently many recursion levels, the remaining subproblems have a very small size that can be completely stored.
SCC Decomposition. The SCC decomposition algorithm builds on essentially the same recursive partitioning framework. The key additional observation is that the strongly connected component containing a sampled vertex can be identified directly from its reachability information as . Thus, whenever a vertex is sampled, we can immediately identify and remove its entire SCC. The remaining vertices are partitioned according to their ancestor, descendant, or unrelated relationship with the sampled vertices, using the same aggressive sampling scheme as in the topological sorting algorithm.
The crucial property of this partitioning is that vertices belonging to the same SCC always have identical relationships with every sampled vertex, and therefore can never be separated into different subproblems. Consequently, the recursion preserves every undiscovered SCC while progressively reducing the sizes of the remaining subproblems. After the recursive phase, the residual subproblems are sufficiently small that we can compute reachability from all remaining vertices in parallel and recover their SCCs from the intersections of their ancestor and descendant sets.
Shortest and Longest Paths via Dynamic Programming. Many problems on DAGs admit natural dynamic programming algorithms that process the vertices according to a topological ordering. A simple example is computing the length of the shortest path from a fixed source s to every other vertex: when processing a vertex v, its distance can be obtained from the already-computed distances of its in-neighbors. A direct attempt to simulate such a dynamic program in the streaming model is to repeatedly scan the edge stream and update the DP values. The difficulty is that the value of a vertex cannot be finalized until the values of all of its relevant predecessors have themselves been finalized. Consequently, a straightforward simulation may require a large number of passes over the stream.
Our main idea for reducing the number of passes is to partition the topological ordering into consecutive blocks of size roughly . Since a block contains only vertices, all edges whose endpoints lie inside a single block can be stored explicitly using space. The blocks can then be processed sequentially. For shortest paths, while scanning the stream for a block , we aggregate for every the best contribution coming from in-neighbors in previously processed blocks. After the scan, the stored internal edges of allow us to complete the DP computation for all vertices of the block offline. Thus, one pass suffices per block, yielding passes overall.
This argument is not specific to shortest paths. In Section 4, we formalize a generic class of DAG dynamic programs in which the contributions of in-neighbors can be incrementally combined by an associative operation. For every problem admitting such a formulation together with a semi-streaming-size representation of its DP state, the same block decomposition gives an -pass semi-streaming algorithm.
DFS. For the DFS, our key observation is that, in a DAG, the lexicographically first DFS tree rooted at a vertex can be characterized through lexicographically minimum paths: for every vertex reachable from , the unique -to- path in the lexicographically first DFS tree is precisely the lexicographically smallest path from to . This characterization turns the problem into a dynamic program over the topological ordering, where for each vertex we select the in-neighbor that yields the lexicographically smallest path. Finally, the lexicographically first DFS forest problem follows from the rooted-tree version through a standard reduction.
()-coloring. For the -coloring problem, we aim to simulate the standard offline greedy algorithm, which processes vertices in reverse topological order and colors a vertex once all of its out-neighbors have been colored. In the semi-streaming model, however, we cannot store the complete out-neighborhood of every vertex. We therefore again partition the topological ordering into blocks of size roughly and process them in reverse order, storing all edges whose endpoints lie in the current block. At this point, all out-neighbors outside the current block have already been colored. Thus, it suffices to obtain, for each vertex in the current block, a sufficiently large list of colors that remain available with respect to these already-colored out-neighbors. We construct such lists using -sampling sketches. In particular, we show that with high probability we can sample at least one more color than the degree of each vertex within its block. Since only as many of these colors as the degree of the vertex within its block can be occupied by out-neighbors inside the block, the stored internal edges then allow us to complete the greedy coloring of the entire block offline. This yields an -pass algorithm while using only semi-streaming space.
1.4 Organization
The rest of the paper is organized as follows. In Section 2, we go over preliminary facts and definitions that we use throughout the paper. In Section 3, we prove our two main results on topological sorting and SCC decomposition. In Section 4, we show the applications of our topological sorting result to algorithms for several DAG-based problems.
In Section 5, we investigate conditional lower bounds for the problems. Finally, in Section A, we present two lower bounds on the -coloring problem.
2 Preliminaries
2.1 Notation, Terminology, and Model
Notation and terminology. We use to denote a directed graph with vertices and edges. For a positive integer , we write . Unless stated otherwise, all graphs are directed, simple, and unweighted. For a vertex , let
denote its sets of out-neighbors and in-neighbors, respectively. We write and for its out-degree and in-degree, and let
When the graph is clear from context, we simply write . For vertices , we write if there exists a directed path from to in .
The semi-streaming model. This model was introduced by Feigenbaum et al. [FKM 05] to study graph problems in the streaming setting where the input is built by a sequence of updates, and the goal is to optimize the information stored to solve a given problem. A semi-streaming algorithm is restricted to bits of space to process the stream, allowing it to store a small amount of information about each node. In this work, we focus on the insert-only model where edges can be only inserted. The input graph and the stream order are assumed to be chosen adversarially (worst-case) and are fixed before the algorithm sees it. The algorithm can make multiple passes over the stream. Its main goal is to optimize the number of passes. The standard assumption is that the stream order remains the same in every pass (our algorithms, however, do not use this property). After the final pass, the algorithm post-processes the stored data to generate an output. For randomized algorithms, the answer is required to be correct with probability at least 2/3.
2.2 Problems
We formally define the problems that we consider in this paper and the shorthand we use for them. To each of them, the input is a directed graph .
REACH -Reachability): Given nodes , is reachable from ?
TOPO (Topological Sorting): Given that G is a DAG, output a topological ordering of V.
SSREACH (Single-Source Reachability): Given a node , output the set of all nodes reachable from s.
MSREACH (Multi-Source Reachability): Given a set of nodes , output the set of all nodes reachable from at least one vertex in .
ACYC (Acyclicity Testing): Is G acyclic?
STR-CONN (Strong Connectivity): Is strongly connected, i.e., is each node in reachable from every other node?
SCC (Strongly Connected Components): Output the partition of into vertex subsets such that each induces a strongly connected component of , i.e., a maximal strongly connected subgraph of .
SCC-TOPO (Topological Ordering of SCCs): Output a topological ordering of the SCC-DAG obtained by contracting each SCC of into a supernode.
SSSP-W (Weighted Single-Source Shortest Path): Given a source node and edge weights , output the length of the shortest path from to every node , where the weight of a path containing edges is given by (shortest-path length from to is if is not reachable from ).
SSSP-POSW denotes the version where all edge weights are positive and SSSP-UW denotes the unweighted version where for all .
SPTREE-W (Weighted Shortest-Path Tree): Given a source node and edge weights , output a shortest path tree rooted at .
SPTREE-POSW denotes the version where all edge weights are positive and SPTREE-UW denotes the unweighted version where for all .
DFS (Rooted DFS forest): Output a forest obtained by a DFS on from a given root with arbitrary tie-breaking. DFS-FIN is the version where we also want the finish time of each vertex.
LF-DFS (Lexicographically-First DFS Forest): Given a total lexicographic ordering of , output the forest obtained by the DFS on that breaks ties by the lexicographic order.
LONGPATH (Longest Path): Given edge weights , output a longest path in . LONGPATHSIZE denotes the variant where we just want the length (sum of edge weights) of a longest path.
For the above problems that are defined on general digraphs, we use the suffix -DAG to denote the variant of the problem where the input is promised to be a DAG, e.g., REACH-DAG, LF-DFS-DAG, etc.
2.3 Basic Tools and Facts
We use the following version of Chernoff bound.
Fact 2.1 (Chernoff bound [DP09]). Let be independent indicator random variables. Let and . Then, for any ,
The -sampling problem asks to sample an element uniformly at random from the support (non-zero entries) of a vector. We use the following standard subroutine for the problem.
Fact 2.2 (-Sampling [JST11]). Suppose that we are given streaming updates of to the entries of an -length vector . For , there is an -space algorithm that after reading the stream, outputs an element from the support of with probability (or reports that the support is empty).
We exploit the following subroutine in our algorithms.
Fact 2.3 (Streaming Single-Source Reachability [AJJ+22]). There is a randomized -pass semi-streaming algorithm for SSREACH. It can be extended to find one explicit path (may not be the shortest) from the source to any node in the graph.
3 Algorithms for Topological Sort and SCC Decomposition
3.1 Topological Sorting
Theorem 1.1. Given a -pass semi-streaming algorithm for single-source reachability, there is an -pass semi-streaming algorithm for topologically sorting a DAG. In particular, there is an -pass semi-streaming algorithm for the problem.
The algorithm then proceeds in two phases.
Phase 1: Recursive Partitioning. Phase 1 is a recursive algorithm of depth at most , where is a fixed constant.
At recursion level , consider a subgraph . We independently sample each vertex into a set with probability
For each sampled vertex , we compute its ancestors, descendants, and unrelated vertices in . We then compute a valid topological ordering of the vertices in ; denote this ordering by
Each vertex is assigned a label vector of length , where the -th coordinate is one of , indicating whether is an ancestor of, a descendant of, or unrelated to . Vertices with identical label vectors are grouped together, forming subgraphs
These subgraphs are ordered lexicographically according to their label vectors (), and the algorithm recurses independently on each . After completing recursion levels, Phase 1 terminates.
Phase 2: Sorting the Remaining Subproblems. In Phase 2, we compute the topological sorting of each remaining subproblem in parallel.
Algorithm 1 TOPOSORT()
1: if then 2: compute the topological sorting of G 3: 4: 5: for each do 6: add to with probability 7: for each sampled vertex do 8: compute , , and 9: let be a valid ordering of nodes in 10: assign labels to vertices in according to their relation to vertices in 11: partition into groups of vertices that share the same label vector 12: let be the subgraphs induced by these groups 13: order the subgraphs lexicographically according to their label vectors (with ) 14: for to do 15: TOPOSORT()
Correctness and Complexity Analysis
Lemma 3.1. Let be a vertex that lies in a subgraph at recursion level . Then, with probability at least ,
where and denote the sets of ancestors and descendants of in , respectively.
Proof. We prove the bound for ancestors; the argument for descendants is symmetric.
The proof is by induction on . For , the claim is trivial since .
Assume the claim holds at recursion level with probability . Consider a vertex that appears in subgraph at level , and let be the subgraph containing at level . By the induction hypothesis, with probability at least .
If , then the claim holds trivially. Otherwise, let
and list the ancestors as , ordered so that there is no path from to for .
If the algorithm samples at least one vertex among the last vertices of this list, then all earlier ancestors are separated from , and we obtain
The probability that none of these vertices is sampled is at most
Thus, with probability at least , the bound holds at level . Taking a union bound over all vertices and recursion levels completes the proof.
Lemma 3.2. The output ordering produced by the algorithm is a valid topological ordering of the input graph.
Proof. The peeling algorithm used in Phase 2 produces a valid topological ordering within each subproblem.
It suffices to show that at recursion level , concatenating the correctly ordered subgraphs
according to the lexicographic order of their label vectors yields a valid ordering for the parent graph .
Suppose for contradiction that there exist vertices and with such that can reach in . Since each is internally ordered correctly, and must belong to different subgraphs.
Let be the first index where the label vectors of and differ. The only possible label pairs at index are , , or . None of these is compatible with a path from to , since reachability relations are transitive with respect to ancestors and descendants.
This contradiction shows that no such pair exists, and the concatenation is a valid topological ordering. ☐
Lemma 3.3. The algorithm can be implemented in the semi-streaming model using passes and space.
Proof. At each recursion level, we use Fact 2.3 to compute SSREACH for all sampled nodes in parallel, which can be done in .
By Chernoff bounds Fact 2.1, the number of sampled vertices at level is with high probability. Moreover, by Lemma 3.1, each vertex has and of size at most . Summing over all subproblems at level , the total space usage is . Also, it is not necessary to construct the full label vectors explicitly for every node which may requires more than space. Instead, for a sampled node and a vertex , we include in 's label vector only if is an ancestor or a descendant of . This information suffices to determine the relationship between each sampled node and every other vertex. Combining this observation with Lemma 3.1, we conclude that the total space required to construct the label vectors at each recursive level is .
Since the number of recursion levels is , Phase 1 uses passes in total. For Phase 2, by Lemma 3.1, the total size of the remaining graph (summed over all subproblems) is . We can therefore store all edges of the remaining subproblems explicitly and run any offline algorithm to compute their topological sorting. Since no additional passes are required beyond storing the edges, the overall pass complexity remains .
An algorithm for acyclicity testing with the same space and pass usage follows due to the reduction shown by [CGMV20]: given an algorithm for topological sorting, we can run it on the input for acyclicity. If it is a DAG, we get a valid topological ordering w.h.p., and if it is not, the algorithm either raises an error (if it can detect that the DAG promise was broken) or it returns an invalid topological ordering (since a graph containing a cycle cannot have a valid topological ordering). If an error is raised, we immediately know that the graph has a cycle. Otherwise, we make another pass and check if the returned ordering induces a back edge, which determines whether a cycle exists. The additional pass takes space and the asymptotic pass bound remains the same.
Corollary 1.2. Given a p-pass semi-streaming algorithm for single-source reachability, there is an -pass semi-streaming algorithm for testing whether a graph has a directed cycle. In particular, there is an -pass semi-streaming algorithm for the problem.
3.2 SCC Decomposition
We describe a recursive algorithm for computing the strongly connected components (SCCs) of a directed graph in the semi-streaming model.
The algorithm proceeds in rounds (recursion levels). At the -th recursion level, the algorithm is applied independently to each current subproblem .
High-level idea. At each recursion level, we sample a set of vertices and use reachability information to identify SCCs containing the sampled vertices. The remaining vertices are then partitioned according to their relationships with the sampled vertices, which induces a partial ordering between the resulting subproblems. The algorithm then recurses on each subproblem.
Detailed description. The algorithm consists of two phases.
Phase 1: Recursive SCC discovery and partitioning. Let be a subproblem in the -th recursion. The algorithm performs the following steps:
-
Sampling. Sample a set of vertices independently at random.
-
Reachability computation. For each , compute its set of ancestors and descendants in
-
Identifying SCCs of sampled vertices. For each , compute its strongly connected component
For every vertex , assign as the strongly connected component of and remove all vertices of from the current subproblem.
- Labeling remaining vertices. For each vertex
Assign a label vector describing whether is
-
an ancestor of ,
-
a descendant of ,
-
unrelated to
for each .
-
Partitioning. Partition the remaining vertices into groups according to identical label vectors.
-
Recursion. Each group defines a new subproblem. The algorithm recurses independently on each subproblem.
The number of total rounds in phase 1 is .
Phase 2: Final SCC computation. After Phase 1 terminates, some vertices may remain in the final subproblems. For each remaining vertex , we compute its ancestor set and descendant set by running BFS in parallel. The strongly connected component of is then determined as . This procedure identifies all remaining strongly connected components.
Pseudocode
Algorithm 2 SCC(G, r)
1: if then 2: for each vertex do 3: compute and 4: 5: assign as the SCC of 6: 7: 8: for each do 9: add to with probability 10: for each do 11: compute and 12: 13: for each do 14: assign as the SCC of 15: 16: assign labels to vertices in according to their relation to vertices in 17: partition into subgraphs based on label vectors 18: obtain subgraphs 19: for to do 20: SCC()
Lemma 3.4. Let be a vertex that lies in a subgraph at recursion level . Then, with probability at least ,
where and denote the sets of ancestors and descendants of in , respectively.
Proof. The proof is completely analogous to that of Lemma 3.1, except for one step. In the proof of Lemma 3.1, we used the assumption that the input graph is a DAG only for the step where we ordered all ancestors of so that there is no path from to whenever . Here, we modify the argument as follows. Let be the strongly connected components of the induced subgraph , ordered according to a topological ordering of the SCC DAG of . We place the vertices within each component arbitrarily, and arrange the components consecutively to obtain an ordering of the vertices in . Now, if we sample a node from the last vertices of this ordering, say , then all vertices in are removed. Moreover, every vertex preceding in this order has relation or to , which differs from the relation of to .
Lemma 3.5. Let and be two vertices that belong to the same strongly connected component of . Then throughout the execution of the algorithm, the vertices and are never separated into different subproblems.
Proof. Let and be two vertices in the same strongly connected component. Then is reachable from and is reachable from in .
Consider an arbitrary recursion step applied to a subproblem containing both and . For every sampled vertex , the algorithm computes the sets and inside and assigns label vectors to vertices according to their relations with the sampled vertices.
Since and are strongly connected, for every sampled vertex the following holds:
• If then , so .
• If then , so .
• If is unrelated to , then is also unrelated to , since otherwise reachability between and would imply a path between and .
Therefore and receive identical label vectors with respect to all sampled vertices in . Consequently, the algorithm assigns and to the same partition when forming the subproblems.
Moreover, if a sampled vertex belongs to the same strongly connected component as and , then
contains both and , and the algorithm removes them together as a single component.
Thus and remain in the same subproblem throughout all recursion levels and are never separated by the algorithm.
Corollary 3.6. The algorithm correctly identifies all strongly connected components of .
Lemma 3.7. The algorithm can be implemented in the semi-streaming model using passes and space.
Proof. At each recursion level, we use Fact 2.3 to compute SSREACH for all sampled nodes in parallel, which can be done in .
By Chernoff bounds Fact 2.1, the number of sampled vertices at level is with high probability. Moreover, by Lemma 3.4, each vertex has and of size at most . Summing over all subproblems at level , the total space usage is . Also, similar to the algorithm for topological sorting, it is not necessary to construct the full label vectors explicitly for every node. We can do it in a similar way using only space. Since the number of recursion levels is , Phase 1 uses passes in total.
By Lemma 3.4, we can run BFS from all remaining nodes in parallel, and it requires only passes and at most space, since the number of ancestors and descendant for each node in each subproblem is . Hence the overall pass complexity and space usage for this phase are and , respectively.
Thus, we get the following theorem.
Theorem 1.3. Given a p-pass semi-streaming algorithm for single-source reachability, there is an -pass semi-streaming algorithm on general digraphs for SCC decomposition, and in fact, for returning the SCCs in topological order. In particular, there is an -pass semi-streaming algorithm for SCC decomposition.
An algorithm for finding a directed cycle (if exists, or report NONE otherwise) using the same asymptotic space and passes follows from the above theorem: we first run the SCC decomposition algorithm on the input graph. Every SCC is singleton iff it is a DAG. Otherwise, there is an SCC with at least two nodes and , and it must contain a cycle. To detect the cycle, parallelly find an path and a path using additional passes and space (Fact 2.3). Let be the first vertex in the path that is also in the path. Then is a cycle.
Corollary 1.4. Given a p-pass semi-streaming algorithm for single-source reachability, there is an -pass semi-streaming algorithm for finding a directed cycle in a digraph, if one exists, or correctly report that none exists. In particular, there is an -pass semi-streaming algorithm for the problem.
4 Algorithms for DAGs via Dynamic Programming
In this section, we apply our topological ordering framework to obtain algorithms for various DAG problems.
4.1 An Algorithm for a Generic DP
We prove the following theorem.
Theorem 4.1. Let be a problem whose input is an -node streaming DAG , for which a topological ordering is known. Let be an operation on some set that satisfies for all and all . Suppose that can be determined by an -length vector DP, indexed by the vertices in , which has the following properties.
-
with : .
-
There is a sketch of size that can (explicitly or implicitly) maintain the vector DP with streaming updates to its entries.
Then there is an -pass semi-streaming algorithm that solves .
Proof. We implement the offline DP recurrence in the semi-streaming model by partitioning the vertices into blocks , where each block contains at most consecutive vertices in the topological ordering. For each block , let denote its internal edges.
For the first block , the algorithm stores all edges in in one pass (there are such edges) and then runs the offline DP recurrence to compute for all .
For each subsequent block with , the algorithm proceeds in a single pass as follows. It stores all edges in in memory. Simultaneously, for every , it maintains an auxiliary value , initially set to a neutral element (i.e., the identity for op). Whenever the stream presents an edge such that and , the algorithm updates
After finishing the pass, all edges inside are available in memory. The algorithm then processes the vertices of in topological order. For each , it initializes and then, for every (in increasing topological order), it updates
Thus, becomes the aggregate of together with all internal in-neighbors.
Correctness follows by induction on the block index . For , there are no outside in-neighbors, so the offline computation is exact. Assume all blocks with have been correctly computed. Consider a vertex . Since is a DAG and the blocks follow the topological order, every in-neighbor of either lies in an earlier block () or appears earlier than within the same block . For all outside in-neighbors, is final by the induction hypothesis, and the streaming aggregation exactly constructs
For the in-neighbors inside , the offline loop processes them in topological order, so DP[u] is already correctly computed when needed. The associativity of op guarantees that the sequential left fold over the union of these two sets produces precisely
which matches the required recurrence. Hence, every vertex is updated correctly.
For the space complexity, by Property 2 of the theorem, the sketch storing DP uses space. Additionally, each block has size at most , so its internal edge set has size at most ; thus, storing one block's edges at a time requires only space. Finally, since exactly one pass is spent per block and there are blocks, the total number of passes is . This yields the claimed -pass semi-streaming algorithm.
Corollary 4.2. Theorem 4.1 can be applied to the following problems on directed acyclic graphs, yielding for each an -pass semi-streaming algorithm:
• SSSP-W (hence, SSSP-UW as well),
• SPTREE-W (hence, SPTREE-UW as well),
LONGPATH and LONGPATHSIZE.
• SSREACH and MSREACH.
Proof. For each problem, we verify that it satisfies the conditions of Theorem 4.1.
SSSP-W and SSSP-UW. Let DP[v] denote the length of the shortest path from the source s to vertex v. For any vertex with , the shortest path to v satisfies the recurrence
where is the weight of edge (with for the unweighted version). This fits the theorem's framework by setting , (which is associative), and . The sketch stores the vector DP explicitly, requiring space.
SPTREE-W and SPTREE-UW. For each vertex , let DP[v] store both the shortest-path distance from to and the predecessor of on a shortest path. The distance component satisfies the same recurrence as in the SSSP case:
To compute , the algorithm only needs the distances of the in-neighbors u of v; the actual paths themselves are not required for the recurrence. Once the minimum is determined, the predecessor of v is set to the in-neighbor u that achieves this minimum. Thus, the sketch maintains two arrays: one storing the distance for every vertex v, and another storing the predecessor pointer . The distance array is used to perform the DP updates, while the predecessor pointers are used to reconstruct the shortest-path tree at the end. Both arrays require total space, so the sketch satisfies the space requirement of Theorem 4.1. The tree is then reconstructed from the predecessor pointers by following them from each vertex back to the root s.
LONGPATH and LONGPATHSIZE. Let DP[v] denote the length of the longest path in G that ends at vertex v. For any vertex v with , we have
and for a source vertex (with ), we set . This fits the theorem by taking , (which is associative), and . The sketch stores the vector DP explicitly, requiring total space. The length of the longest path in the entire graph is then , and the path itself can be reconstructed by storing a predecessor pointer for each vertex.
SSREACH. For a fixed source , let DP[v] be a Boolean value indicating whether is reachable from . For any vertex , we have
where denotes logical OR, and . This fits the theorem by taking , (which is associative), and . The sketch stores the reachability vector DP explicitly, requiring space.
MSREACH. For a set of sources , the multi-source reachability problem asks to determine which vertices are reachable from any source in . This can be reduced to the single-source reachability problem by constructing an auxiliary graph as follows. Add a new dummy source and directed edges from to every vertex in . Since every original edge of is preserved, a vertex is reachable from in if and only if it is reachable from some source in in . The reduction adds only edges and one vertex, so the asymptotic pass and space complexities are preserved. Thus, the SSREACH algorithm applies directly to MSREACH.
In each case, the DP vector is of length , can be maintained with streaming updates, and satisfies the required recurrence with an associative operation. Therefore, Theorem 4.1 applies to all of these problems.
Not every problem of interest, however, fits directly into the DP framework of Theorem 4.1. In particular, the LF-DFS-tree and LF-DFS-forest problems do not admit the requirements of Theorem 4.1. Nonetheless, in the next subsection we will show that a similar result can be obtained: we first reduce the forest problem to the single-root tree case, and then prove a structural property of the LF-DFS-tree that allows us to compute it using the block-decomposition and the generic DP approach.
In the last subsection of this section, we turn our attention to the -coloring problem. This problem is even more different from the generic DP setting, as even its standard offline algorithm is not a dynamic program in the usual sense. Instead, the offline algorithm follows a greedy strategy that processes vertices in the reverse topological order, assigning to each vertex the smallest available color not used by its out-neighbors. We will show that the same block-partitioning idea can still be applied. By processing the blocks in reverse topological order and appropriately sampling available colors for each node, we obtain an -pass semi-streaming algorithm for -coloring as well.
4.2 Lexicographically-First DFS Forest
In this subsection, we turn our attention to the problem of computing the LF-DFS-forest of a DAG , where the standard DFS procedure is initialized on the smallest unvisited vertex at each step. While our algorithm in this section is formally designed for computing the LF-DFS-tree rooted at a fixed starting vertex, it actually suffices to solve only this restricted version. Indeed, the general forest problem can be reduced to the tree problem by a simple and standard transformation, which we describe below.
Given an arbitrary DAG for which we wish to obtain the LF-DFS-forest, we construct an auxiliary graph as follows. Let
where r is a new dummy root node. The edge set of consists of all original edges of G, together with a directed edge from r to every vertex in V:
Furthermore, we extend the global vertex ordering by declaring r to be strictly smaller than every vertex in V.
The key observation is that running the LF-DFS-tree algorithm on starting from the single root r exactly simulates the iterative forest construction on G. When the DFS begins at r, it first visits this dummy root. Since r has outgoing edges to all vertices of V, its adjacency list, sorted lexicographically, contains every vertex of the original graph. The DFS then proceeds to the smallest unvisited vertex in V, say , and from there it explores the entire reachable region of according to the DFS rules, backtracking only when no further unvisited outgoing edges remain. This exhaustive exploration from precisely yields the first tree of the desired LF-DFS-forest.
Once this first tree has been fully explored, the DFS returns to . At this point, still has unvisited neighbors in its adjacency list (namely, all vertices of that were not reached in the first component). The DFS thus advances to the next smallest unvisited vertex and initiates the second tree of the forest. This process repeats until every vertex of has been visited. Consequently, the LF-DFS-tree rooted at in the auxiliary graph consists of the dummy root with, attached as its children, all the individual DFS trees of the forest, arranged in the correct lexicographic order.
Therefore, if we remove and all incident edges from the resulting LF-DFS-tree of , the remaining disconnected subtrees form exactly the LF-DFS-forest of the original graph .
Now, we describe an algorithm for computing a DFS tree rooted at an arbitrary vertex in a DAG in -passes, assuming that a topological ordering of the DAG is known.
The high-level idea is to compute, for every vertex that is reachable from , the lexicographically minimum path from to . We then show that the collection of these paths forms exactly the LF-DFS-tree rooted at .
To compute these paths efficiently in the semi-streaming model, we partition the vertices according to the known topological ordering into consecutive blocks. We then use a dynamic programming procedure to compute the desired paths. In particular, for every vertex appearing after in the topological ordering, we compute the lexicographically minimum path from to .
The remainder of this section is organized as follows. We first prove that computing the lexicographically minimum paths from to all reachable vertices is equivalent to computing the LF-DFS-tree rooted at . We then describe how to fit this new problem into the generic DP.
Let be a directed acyclic graph, and let the vertices be totally ordered by a relation . We write if the vertex sequence of is lexicographically smaller than that of .
Fix a root vertex . Perform a depth-first search (DFS) starting at , where at every vertex its outgoing neighbors are examined in strictly increasing order according to . Let be the resulting DFS tree rooted at , and for any vertex reachable from , denote by the unique path from to in .
Lemma 4.3. For every vertex reachable from , the path is the lexicographically smallest path among all simple paths from to in .
Proof. Let be an arbitrary reachable vertex, and let
be the unique path from to in the DFS tree .
Take any other simple path
If there is nothing to prove. Otherwise, let be the smallest index such that . Since both paths start at , we have . Let
Thus , and both and are outgoing neighbours of .
At the moment when DFS processes vertex , it inspects its neighbours in increasing order. It chooses the first neighbour that is still unvisited and adds the edge to the DFS tree. Therefore one of the following two cases must hold:
-
is unvisited when is processed. Since DFS explores neighbors in increasing lexicographic order and chose over , we must have . Thus, at the first position where and differ, the vertex in is lexicographically smaller than the vertex in .
-
was already visited before is processed. Because DFS is recursive, a vertex that is visited before and is not an ancestor of must have been completely explored (finished) before the exploration of begins.
Since lies on the tree path to , is an ancestor of in ; hence is discovered before . On the other hand, from the suffix of we have a path from to . Since was already visited and finished before , is forced to be discovered and finished within the subtree of , thus is discovered before . This gives the contradiction, which is impossible. Hence this case cannot occur either.
Because was an arbitrary simple path from to , the DFS-tree path is lexicographically minimal. This holds for every reachable vertex , completing the proof.
By the above lemma, computing the LF-DFS-tree rooted at is equivalent to computing, for every vertex reachable from , the lexicographically minimum path from to . We now show that this task fits precisely into the DP framework of Theorem 4.1.
For each vertex , let store the predecessor of on the lexicographically minimum path from to (with ). The lexicographically minimum path to satisfies the recurrence
where denotes the path obtained by following the predecessor pointers from back to , and the minimum is taken with respect to the lexicographic ordering of paths.
To apply Theorem 4.1, we define the operation op and the function f as follows. Let S be the set of all possible paths starting at r, and let op take the node u such that is the lexicographic minimum over the set of candidate paths. This operation is associative, as taking the minimum over a set is independent of the order in which the elements are aggregated. For an edge , the function represents the path , which is implicitly encoded by setting the predecessor of v to u.
A subtle but important point is that the sketch does not store the full vertex sequence of explicitly for every , as that would require space. Instead, the sketch maintains the partial LF-DFS-tree formed by the current predecessor pointers. Crucially, when the algorithm needs to compare two candidate paths and , it suffices to compare and , which can be done by traversing the maintained parent pointers of the tree. Thus, the entire collection of paths is implicitly represented by the tree, and the sketch meets the space requirement of Theorem 4.1 (Property 2). The recurrence clearly satisfies the associative aggregation form required by Property 1.
Therefore, applying Theorem 4.1 immediately yields an -pass semi-streaming algorithm for computing the lexicographically minimum paths from to all reachable vertices. Now, we are ready to state the main results of this subsection.
Theorem 4.4. Let be a directed acyclic graph for which a topological ordering is known, and let be an arbitrary root vertex. There exists an -pass semi-streaming algorithm that computes the LF-DFS-tree rooted at .
Proof. By Lemma 4.3, computing the LF-DFS-tree rooted at is equivalent to computing the lexicographically minimum path from to every reachable vertex. As argued above, this problem satisfies the conditions of Theorem 4.1: the recurrence for the predecessor pointers uses an associative arg min operation, and the sketch requires only space to store the predecessor pointers. Theorem 4.1 then yields an -pass semi-streaming algorithm.
Theorem 4.5. Let be a directed acyclic graph for which a topological ordering is known. There exists an -pass semi-streaming algorithm that computes the Lexicographically-First DFS forest of .
Proof. This follows directly from the reduction described at the beginning of this subsection. Construct the auxiliary graph by adding a dummy root r as described above. Applying Theorem 4.4 to rooted at r yields the LF-DFS tree of in -passes and space. Removing the dummy root r and its incident edges from this tree leaves exactly the LF-DFS forest of the original graph G. The reduction adds only edges and one vertex, so the asymptotic pass and space complexities are preserved.
4.3 -coloring
Theorem 4.6. Let be a directed acyclic graph for which a topological ordering is known, there is a randomized semi-streaming algorithm that computes a proper -coloring of using passes with high probability.
Proof. Partition the vertices according to the given topological ordering into consecutive blocks , where each block contains at most vertices. For every block , let denote the subgraph induced by the vertices of .
The algorithm processes the blocks in reverse order. At the beginning of the algorithm, all vertices are uncolored. When processing a block , all vertices in blocks appearing after in the topological ordering have already been colored. We construct a list of available colors for every and then color using these lists.
For every vertex , we maintain independent -sampling sketches, where is a sufficiently large constant. The sketches are used to sample available colors for . The sketches are processed in groups of size . Importantly, when processing the next group, we remove from the current sketch the colors already returned by the previous groups. Thus, the same color is never counted twice.
More precisely, consider a vertex . Let be its color vector. Initially, every coordinate is set to 1. Whenever the stream contains an edge such that has already been colored with color , we subtract 1 from coordinate . Thus, a positive coordinate corresponds to an available color, a zero coordinate corresponds to a color used exactly once by an already colored out-neighbor, and a negative coordinate corresponds to a color used by at least two already colored out-neighbors.
For every group of sketches, we additionally remove from the current sketches all colors returned by the previous groups. This ensures that previously discovered available colors are not sampled again. We also remove the contribution of these colors from the sketches so that the number of negative coordinates does not increase when passing from one group to the next.
We now prove that, with high probability, contains at least available colors. In fact, we prove the following stronger statement by induction. For every
the first sketches return at least distinct available colors with probability at least .
For the base case , consider the first sketches. The probability that an -sample returns an available color is greater than . Indeed, let denote, respectively, the number of negative, zero, and positive coordinates of the original color vector. Here, is the number of colors used by at least two already colored out-neighbors of , is the number of colors used by exactly one such out-neighbor, and is the number of colors available before considering the vertices in .
Since every color counted by is used at least twice, we have
Moreover,
Therefore,
and hence an -sample returns an available color with probability
Consequently, by taking independent samples, the probability that none of them returns an available color is at most , for a sufficiently large constant c. This proves the base case.
Now assume that the statement holds for , where
Condition on the event that the first sketches return at least distinct available colors. If they return at least colors, there is nothing to prove. Otherwise, suppose that they return exactly colors.
Let denote the numbers of negative, zero, and positive coordinates seen by the sketches in the -th group. Because the colors returned by the previous groups are removed from the current group, and because their contributions are removed as well, we have
The important point is that the number of negative coordinates remains ; only the previously discovered available colors are removed. Since and , we obtain
Thus, conditioned on the previous groups having found exactly available colors, every sketch in the -th group returns a new available color with probability
For a sufficiently large constant , the probability that the sketches in this group fail to produce a new available color is at most .
Now, let denote the set of all outputs produced by the first sketches of the algorithm. Thus, the event that the first sketches output at least colors is equivalent to .
We now bound the probability that the first sketches output at least colors. By the induction hypothesis . Using the law of total probability and conditioning on the outcome of the first sketches, we obtain
This completes the induction.
The argument holds for every . Since every block contains at most vertices, . Hence, using sketches for every vertex is sufficient to obtain at least distinct available colors for every vertex in , with high probability. We also spent another pass to validate the output colors for and store of them in .
We now color the vertices of greedily in reverse topological order. For a vertex , all out-neighbors of that lie outside have already been colored. By construction, contains at least available colors. Since has only out-neighbors inside , at least one color in is not used by an out-neighbor of in . Therefore, the greedy procedure produces a proper coloring of , while preserving the proper coloring of all previously processed blocks.
It remains to bound the space and number of passes. For every vertex we maintain -sampling sketches, each requiring polylogarithmic space. Thus, over all vertices of a fixed block, the total space used by the sketches is .
The edges of the current induced subgraph contain at most edges and can also be stored in space. Hence the algorithm uses semi-streaming space.
Finally, each block requires two passes over the stream: one pass to construct the sampling sketches, store the output colors and the edges of , and a second pass to validate the sampled colors and find the actual available colors. Since there are blocks, the total number of passes is . By choosing sufficiently large and applying a union bound, all lists are constructed correctly with high probability. Therefore, the algorithm outputs a proper -coloring in passes using semi-streaming space.
Theorem 1.5. Given a -pass semi-streaming algorithm for topological sorting, there are -pass semi-streaming algorithms for the following problems on DAGs:
-
Weighted Single-Source Shortest Path Tree (negative weights allowed)
-
Weighted (Global) Longest Path
-
Lexicographically-First DFS Forest
-
-coloring
In particular, there are -pass semi-streaming algorithms for the above problems.
5 Complexity Classes Based on Semi-Streaming Passes and Consequences
Let and be graph streaming problems. We say that is -Hard if, given a -pass semi-streaming algorithm for , we can get an -pass algorithm for .
Conjecture 5.1. Any randomized semi-streaming algorithm for REACH-DAG requires passes.
Proposition 5.2. All problems listed in Section 2.2 and their DAG versions (if non-trivial) are REACH-DAG-Hard.
Proof. The statement is immediate for SSREACH-DAG since an algorithm for it also solves REACH-DAG. It then follows for DAG versions of SSREACH, MSREACH, SSSP-UW (and hence, SSSP-W), SPTREE-UW (and hence, SPTREE-W), and DFS (and hence, LF-DFS), and extend to their general versions. For ACYC and SCC, the DAG versions are trivial, so consider their general version. There are easy reductions from REACH-DAG to these problems: add the edge to the input DAG for REACH-DAG and run the algorithm for ACYC or SCC. For the former, the graph has a cycle iff . For the latter, and will be in the same SCC iff . It then trivially follows for SCC-TOPO. It also follows for TOPO since [CGMV20] showed that TOPO is harder than ACYC modulo one more pass. For STR-CONN, [CLT25] showed a simple reduction from REACH (which is obviously harder than REACH-DAG): store edges incident on and from the stream (takes space) and after the stream, add edges from to all other nodes and edges to from all other nodes. Then the resultant graph is strongly connected iff . For unweighted LONGPATHSIZE, we show a reduction, which them implies the hardness for the more general versions of the problem.
Add new vertices and . Add edges and edges . The new graph contains a path of length at least if and only if is reachable from in . If is reachable from , then there is a path of length at least from to . Any path in the original graph that is not an , -path can connect at most one of the two new chains added, and hence, if is not reachable from , then length of any path in the new graph is at most .
This completes the proof of the proposition.
Since all our algorithms for the DAG problems use passes, the following proposition follows.
Proposition 5.3. If Conjecture 5.1 is true, then all our algorithms are optimal up to a factor of in passes. This means the semi-streaming pass complexity of all problems listed in Section 2.2 is .
Since TOPO is REACH-DAG-Hard, the following conjecture is weaker than Conjecture 5.1.
Conjecture 5.4. Any randomized semi-streaming algorithm for TOPO requires passes.
Proposition 5.5. The problems SCC-TOPO, SSSP-W-DAG, SPTREE-W-DAG, DFS-FIN-DAG, and LF-DFS-DAG are TOPO-Hard.
Proof. The claim about SCC-TOPO is trivial since it precisely solves TOPO on a DAG. For reduction to SSSP-W-DAG, add a source and edges of weight 0 from to all nodes in the original graph, and assign every original edge a weight of . Then where is the maximum number of edges in a path ending at . Thus, for each edge in the original graph, . Hence, we can order the nodes by decreasing distance from and obtain a topological order. The argument of SPTREE-W-DAG is the same since it also gives the distance from to every node. Finally, DFS-FIN-DAG can be used to obtain a topological ordering by sorting by decreasing order of finish time (the classical textbook algorithm), and LF-DFS-DAG gives the finish times if we run DFS on the returned LF-DFS.
Proposition 5.6. If Conjecture 5.4 is true, then our algorithms for SSSP-W-DAG, SPTREE-W-DAG, DFS-FIN-DAG, and LF-DFS-DAG are optimal up to a factor of in passes. Hence, all these problems are TOPO-complete.
Proof. Let be the optimal number of semi-streaming passes required to solve TOPO. By Theorem 1.5, our algorithms solve these problems using passes. If Conjecture 5.4 is true, then , which means we solve these problems in passes. Since the problems are TOPO-Hard, they need passes by definition and it also follows that they are TOPO-complete. Thus, the proposition follows.
Conjecture 5.7. Any randomized semi-streaming algorithm for SSREACH requires passes.
Proposition 5.8. The problems SSSP-UW-DAG, SSSP-POSW-DAG, SPTREE-UW-DAG, SPTREE-POSW-DAG, and LF-DFS-DAG are SSREACH-Hard.
Proof. All but LF-DFS-DAG not only tells whether each vertex is reachable from the source node but also gives the distances ( if unreachable). For LF-DFS-DAG, if we keep the source first in the lexicographic ordering, then it will be first root and the DFS forest returned will contain the DFS tree rooted at , which in turn contains all nodes reachable from .
Proposition 5.9. If Conjecture 5.7 is true, then our algorithms for SSSP-UW-DAG, SSSP-POSW-DAG, SPTREE-UW-DAG, SPTREE-POSW-DAG, and LF-DFS-DAG are optimal up to a factor of in passes.
Proof. Let be defined as above. By Theorem 1.5, our algorithms solve these problems using passes. If Conjecture 5.7 is true, then , which means we solve these problems in passes. Since the problems are SSREACH-Hard, they need passes by definition. Thus, the proposition follows.
6 AI Disclosure Statement
We used ChatGPT 5.6 by OpenAI to assist with brainstorming on the problems. The tool materially affected Section 4.2 and Section A. All proofs are written by the author(s) and they take full responsibility of the material in the article. The author(s) verified the correctness and originality of all content including references.
References
[ABC+26] Amir Azarmehr, Soheil Behnezhad, Lily Chung, Alma Ghafari, Jane Lange, and Ronitt Rubinfeld. Streaming algorithms for monotonicity testing. arXiv preprint arXiv:2608.07073, 2026. 5
[Abl96] Farid Ablayev. Lower bounds for one-way probabilistic communication complexity and their application to space complexity. Theoretical Computer Science, 175(2):139–159, 1996. 25
[ACK19] Sepehr Assadi, Yu Chen, and Sanjeev Khanna. Sublinear algorithms for vertex coloring. In Proceedings of the Thirtieth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2019, San Diego, California, USA, January 6-9, 2019, pages 767–786, 2019. 3
[AGL 24] Sepehr Assadi, Prantar Ghosh, Bruno Loff, Parth Mittal, and Sagnik Mukhopadhyay. Polynomial pass semi-streaming lower bounds for K-cores and degeneracy. In 39th Computational Complexity Conference (CCC 2024), volume 300 of Leibniz International Proceedings in Informatics (LIPIcs), pages 7:1–7:16. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. 3
[AHS26] Sepehr Assadi, Gary Hoppenworth, and Janani Sundaresan. Better bounds for semi-streaming single-source shortest paths. In Proceedings of the 2026 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA 2026), pages 5093–5116. SIAM, 2026. 3
[AJJ 22] Sepehr Assadi, Arun Jambulapati, Yujia Jin, Aaron Sidford, and Kevin Tian. Semi-streaming bipartite matching in fewer passes and optimal space. In SODA, pages 627–669. SIAM, 2022. 2, 8
[AKM22] Sepehr Assadi, Pankaj Kumar, and Parth Mittal. Brooks’ theorem in graph streams: A single-pass semi-streaming algorithm for -coloring. In Proceedings of the 54th Annual ACM SIGACT Symposium on Theory of Computing (STOC 2022), pages 234–247. Association for Computing Machinery, 2022. 3
[AR20] Sepehr Assadi and Ran Raz. Near-quadratic lower bounds for two-pass graph streaming algorithms. In FOCS, pages 342–353. IEEE, 2020. 2
[BCG20] Suman K. Bera, Amit Chakrabarti, and Prantar Ghosh. Graph coloring via degeneracy in streaming and other space-conscious models. In 47th International Colloquium on Automata, Languages, and Programming, ICALP 2020, July 8-11, 2020, Saarbrücken, Germany (Virtual Conference), pages 11:1–11:21, 2020. 3
[BCK 14] Joshua Brody, Amit Chakrabarti, Ranganath Kondapally, David P. Woodruff, and Grigory Yaroslavtsev. Certifying equality with limited interaction. In Approximation, Randomization, and Combinatorial Optimization. Algorithms and Techniques (APPROX/RANDOM 2014), volume 28 of Leibniz International Proceedings in Informatics (LIPIcs), pages 545–581. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2014. 26
[BJW22] Anubhav Baweja, Justin Jia, and David P. Woodruff. An efficient semi-streaming PTAS for tournament feedback arc set with few passes. In 13th Innovations in Theoretical Computer Science Conference (ITCS 2022), volume 215 of Leibniz International Proceedings in Informatics (LIPIcs), pages 16:1–16:23. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2022. 2
[CCLT26] Ho-Lin Chen, Tsun Ming Cheung, Peng-Ting Lin, and Meng-Tsung Tsai. Independence-number parameterized space complexity for directed connectivity certificate, 2026. 2
[CFHT20] Yi-Jun Chang, Martin Farach-Colton, Tsan-sheng Hsu, and Meng-Tsung Tsai. Streaming complexity of spanning tree computation. In 37th International Symposium on Theoretical Aspects of Computer Science, STACS 2020, March 10-13, 2020, Montpellier, France, pages 34:1–34:19, 2020. 3
[CGMV20] Amit Chakrabarti, Prantar Ghosh, Andrew McGregor, and Sofya Vorotnikova. Vertex ordering problems in directed graph streams. In Proceedings of the 2020 ACM-SIAM Symposium on Discrete Algorithms, SODA 2020, Salt Lake City, UT, USA, January 5-8, 2020, pages 1786–1802, 2020. 2, 11, 21
[CKP 21] Lijie Chen, Gillat Kol, Dmitry Paramonov, Raghuvansh R. Saxena, Zhao Song, and Huacheng Yu. Almost optimal super-constant-pass streaming lower bounds for reachability. In Proceedings of the 53rd Annual ACM SIGACT Symposium on Theory of Computing (STOC 2021), pages 570–583. ACM, 2021. 2
[CLRS22] Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms. MIT Press, Cambridge, MA, 4 edition, 2022. 3
[CLT25] Ho-Lin Chen, Peng-Ting Lin, and Meng-Tsung Tsai. Parameterized streaming algorithms for topological sorting. In 19th International Symposium on Algorithms and Data Structures (WADS 2025), volume 349 of Leibniz International Proceedings in Informatics (LIPIcs), pages 18:1–18:20. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2025. 2, 21
[CSWY01] Amit Chakrabarti, Yaoyun Shi, Anthony Wirth, and Andrew Chi-Chih Yao. Informational complexity and the direct sum problem for simultaneous message complexity. In 42nd Annual Symposium on Foundations of Computer Science, FOCS 2001, 14-17 October 2001, pages 270–278, 2001. 26
[DP09] Devdatt P. Dubhashi and Alessandro Panconesi. Concentration of Measure for the Analysis of Randomized Algorithms. Cambridge University Press, 2009. 8
[Elk11] Michael Elkin. Streaming and fully dynamic centralized algorithms for constructing and maintaining sparse spanners. ACM Trans. Algorithms, 7(2):20:1–20:17, 2011. 3
[FKM 05] Joan Feigenbaum, Sampath Kannan, Andrew McGregor, Siddharth Suri, and Jian Zhang. On graph problems in a semi-streaming model. Theor. Comput. Sci., 348(2-3):207–216, 2005. 2, 7
[GK24] Prantar Ghosh and Sahil Kuchlous. New algorithms and lower bounds for streaming tournaments. In 32nd Annual European Symposium on Algorithms (ESA 2024), volume 308 of Leibniz International Proceedings in Informatics (LIPIcs), pages 60:1–60:19. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. 5
[GKMM26] Prantar Ghosh, Sahil Kuchlous, Shravan Mehra, and Sagnik Mukhopadhyay. The power of the score sequence of a tournament. In 34th Annual European Symposium on Algorithms (ESA 2026), volume 388 of Leibniz International Proceedings in Informatics (LIPIcs), pages 156:1–156:19. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2026. 5
[GO13] Venkatesan Guruswami and Krzysztof Onak. Superlinear lower bounds for multipass graph processing. In Proceedings of the 28th Conference on Computational Complexity, CCC 2013, K.lo Alto, California, USA, 5-7 June, 2013, pages 287–298, 2013. 2
[Jan14] Abhabongse Janthong. Streaming algorithm for determining a topological ordering of a digraph, April 2014. Advisor: Paul Valiant. 2
[JLS19] Arun Jambulapati, Yang P. Liu, and Aaron Sidford. Parallel reachability in almost linear work and square root depth. In David Zuckerman, editor, Proceedings of the 60th IEEE Annual Symposium on Foundations of Computer Science (FOCS 2019), pages 1664–1686. IEEE Computer Society, 2019. 2, 5
[JST11] Hossein Jowhari, Mert Sağlam, and Gábor Tardos. Tight bounds for lp samplers, finding duplicates in streams, and related problems. In Proceedings of the thirtieth ACM SIGMOD-SIGACT-SIGART symposium on Principles of database systems, pages 49–58. ACM, 2011. 8
[KM19] Shahbaz Khan and Shashank K. Mehta. Depth first search in the semi-streaming model. In 36th International Symposium on Theoretical Aspects of Computer Science, STACS 2019, March 13-16, 2019, Berlin, Germany, pages 42:1–42:16, 2019. 3
[KSS16] Lasse Kliemann, Christian Schielke, and Anand Srivastav. A streaming algorithm for the undirected longest path problem. In 24th Annual European Symposium on Algorithms (ESA 2016), volume 57 of Leibniz International Proceedings in Informatics (LIPIcs), pages 56:1–56:17. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2016. 3
[KT25] Christian Konrad and Chhaya Trehan. Constructing long paths in graph streams. In 33rd Annual European Symposium on Algorithms (ESA 2025), volume 351 of Leibniz International Proceedings in Informatics (LIPIcs), pages 22:1–22:19. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2025. 3
[KW59] James E. Kelley and Morgan R. Walker. Critical-path planning and scheduling. In Papers Presented at the December 1–3, 1959, Eastern Joint IRE-AIEE-ACM Computer Conference, pages 160–173. Association for Computing Machinery, 1959. 3
[LS11] Luigi Laura and Federico Santaroni. Computing strongly connected components in the streaming model. In Theory and Practice of Algorithms in (Computer) Systems (TAPAS 2011), volume 6595 of Lecture Notes in Computer Science, pages 193–205. Springer, 2011. 5
[Yao79] Andrew Chi-Chih Yao. Some complexity questions related to distributive computing (preliminary report). In Proceedings of the 11th Annual ACM Symposium on Theory of Computing, April 30 - May 2, 1979, Atlanta, Georgia, USA, pages 209–213, 1979. 25
A Lower Bounds for -coloring
In this section, we study lower bounds for semi-streaming algorithms for proper -coloring. We first show an space lower bound for one-pass algorithms. In fact, the reduction continues to work even when the topological ordering of the graph and the value of are given to the algorithm before the stream starts.
We then consider the multi-pass setting. In this case, we allow the stream to contain multiple copies of the same edge and show an space lower bound for a -pass algorithm.
Before proving the results, we discuss communication complexity preliminaries that we use for the proofs.
Communication Complexity with Applications to Streaming Lower Bounds. In the two-player communication model of Yao [Yao79], the players Alice and Bob receive and respectively, and the goal is to communicate as few bits as possible to output for a given function . We consider the randomized setting where the players may use private random coins to generate the messages. The communication cost of a randomized protocol for is the maximum number of bits exchanged by the players, over all possible inputs and all possible random strings. The randomized communication complexity of a function , denoted by , is the minimum communication cost over all randomized protocols (allowing unlimited rounds of interaction) that, for all possible input pairs , output correctly with probability at least .
A restrictive variant of the model is the one-way communication model where Alice sends one message to Bob, following which he must output . The one-way randomized communication complexity of , denoted by , is defined as the minimum communication cost over all randomized one-way protocols.
To prove our lower bounds, we reduce from the Index (INDEX) and (a generalized version of) the Unique Set Intersection (UNIQ-SETINT) problems. We formally define them below and mention the results on their communication complexity that we use.
INDEX: Alice gets and Bob gets an index . The goal is to find , the th bit of .
Fact A.1 ([Abl96]). The one-way randomized communication complexity .
UNIQ-SETINT: Alice gets and Bob gets , where and are promised to intersect uniquely as sets, i.e., there is a unique such that . The goal is to output .
We actually use the communication complexity of k-fold Unique Set Intersection problem k-UNIQ-SETINT, where Alice and Bob are given k independent instances of UNIQ-SETINT for some and . The “direct sum” theorem says that its communication complexity is times that of UNIQ-SETINT.
Fact A.2 (Direct sum theorem [CSWY01]). Let be a function such that Alice and Bob need to compute each of with probability at least 2/3. Then the required communication is .
Since [BCK14], the following fact follows from Fact A.2.
Fact A.3. The randomized communication complexity .
A.1 One-Pass Space Lower Bound.
Theorem A.4. Let be a randomized one-pass insertion-only streaming algorithm that, given an -vertex DAG , outputs with probability at least 2/3 a proper -coloring. Then requires space.
We prove the theorem by a reduction from the one-way communication problem INDEX. In an instance of INDEX, Alice has a binary matrix and Bob has a pair . Bob's goal is to find the entry . It is known that any randomized one-way protocol for INDEX with constant success probability requires bits of communication.
We first describe the reduction.
Lemma A.5. Suppose there is a randomized one-pass insertion-only streaming algorithm that computes a proper -coloring of every -vertex DAG using bits of space. Then there is a one-way communication protocol that solves a instance of INDEX using bits of communication, where .
Proof. Suppose Alice is given a binary matrix . She constructs a graph with vertices, partitioned into the following four sets:
and
For every , Alice adds exactly one of the two edges and according to the value of :
and
She also adds a directed clique on , where the edges are oriented according to the order
That is, is added for every .
Alice now runs on the edges she constructed. After processing her part of the stream, she sends the current memory state of to Bob.
Suppose Bob's input is . He defines a mapping by
and
Bob then continues the execution of . For every , he adds an edge from to every vertex in except . Thus, he adds
The directed clique on contains vertices. Hence, in every proper -coloring, all vertices in must receive different colors. Also, the maximum out-degree of the resulting graph is , and therefore .
Consider first . Both and have an edge to every vertex of except . Since all vertices in have different colors and there are exactly available colors, the only possible color for both and is the color of . Thus,
For the special index , the same argument gives and .
We now consider . For every , Alice added either or . In both cases, the corresponding vertex has color . Therefore, cannot use any of the colors for . The only two possible colors for are and .
If , then is present. Since , cannot use , and hence . On the other hand, if , then is present. Since , we must have . Therefore, Bob can recover by comparing the color of with the colors of and :
It remains to check that the graph is a DAG. One valid topological ordering is obtained by placing the four sets in the order
and ordering the vertices of as . All edges added by Alice go from to or are edges inside . All edges added by Bob go from to . Thus, this ordering is a valid topological ordering.
The graph has vertices. This proves the lemma.
Proof of Theorem 3.1. The one-way communication complexity of a instance of INDEX is . By the lemma, an -space streaming algorithm would give a one-way protocol using bits of communication. Therefore,
since . The theorem follows.
Remark A.6. The reduction also shows that the lower bound holds even if the topological ordering and are known to the algorithm before the stream starts. In fact, neither of these pieces of information depends on Alice's matrix X. Hence, they can be given to both Alice and Bob in advance without affecting the communication reduction.
A.2 Multipass lower bound for repeated edges
We next consider the multi-pass setting in which the stream may contain multiple copies of the same edge. We prove a space lower bound by reducing from the n-fold Unique Intersection problem.
Theorem A.7. Let be a randomized -pass streaming algorithm that, given an -vertex DAG whose stream may contain multiple copies of the same edge, outputs a proper -coloring with constant success probability. Then requires space.
In the n-fold Unique Intersection problem, Alice is given n binary vectors
and Bob is given another n binary vectors
It is promised that, for every , there is a unique index such that . The goal is for Bob to recover all indices . We use the following reduction.
Proof of. Suppose that uses bits of space. We construct a communication protocol for the -fold Unique Intersection problem.
Let Alice have and Bob have , satisfying the unique-intersection promise. The graph has 2n vertices, divided into two sets
Alice first constructs the part of the stream determined by her input. For every such that , she inserts the edge . She then simulates on this part of the stream.
Since makes multiple passes over the stream, Alice and Bob simulate the passes one by one. At the end of each pass, Alice sends the current memory state of to Bob, and Bob continues the same pass on his part of the stream. At the end of Bob's part, the current memory state is sent back to Alice so that she can start the next pass. Thus, each pass requires bits of communication, and the complete simulation uses bits.
During his part of the stream, Bob inserts an edge whenever . Notice that an edge can occur in both Alice's and Bob's parts of the stream. This is exactly where we use the fact that the streaming model allows multiple copies of the same edge.
After processing the edges determined by his vectors, Bob adds the edges for every . Therefore, the vertices in induce a directed clique.
We now consider the coloring produced by . By the promise, for every , there is a unique index for which . Hence, for every , at least one of and is zero. Therefore, the edge appears in the stream for every . On the other hand, never appears.
Consequently, , and hence . The directed clique on also implies that and all vertices of receive different colors in every proper coloring. Thus, the algorithm uses exactly available colors.
It follows that is adjacent to vertices having pairwise different colors. The only color that can be assigned to is therefore the color of the unique vertex that is not an out-neighbor of . Hence, . Since all vertices of have distinct colors, Bob can recover by comparing the color of with the colors of the vertices in . Doing this for every allows Bob to recover .
We finally check that the graph constructed in the reduction is a DAG. All edges between and are directed from to , and the edges inside are directed according to the ordering . Thus, is a valid topological ordering.
The reduction gives a communication protocol for the -fold Unique Intersection problem using bits. The communication complexity of this problem is . Therefore, , which gives . This proves the theorem.