<?xml-model href='http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng' schematypens='http://relaxng.org/ns/structure/1.0'?><TEI xmlns="http://www.tei-c.org/ns/1.0">
	<teiHeader>
		<fileDesc>
			<titleStmt><title level='a'>Incremental Topological Ordering and Cycle Detection with Predictions</title></titleStmt>
			<publicationStmt>
				<publisher>Icml</publisher>
				<date>07/01/2024</date>
			</publicationStmt>
			<sourceDesc>
				<bibl> 
					<idno type="par_id">10563549</idno>
					<idno type="doi"></idno>
					
					<author>S McCauley</author><author>B Moseley</author><author>A Niaparast</author><author>S Singh</author>
				</bibl>
			</sourceDesc>
		</fileDesc>
		<profileDesc>
			<abstract><ab><![CDATA[This paper leverages the framework of algorithmswith-predictions to design data structures for two fundamental dynamic graph problems: incremental topological ordering and cycle detection. In these problems, the input is a directed graph on n nodes, and the m edges arrive one by one. The data structure must maintain a topological ordering of the vertices at all times and detect if the newly inserted edge creates a cycle. The theoretically best worst-case algorithms for these problems have high update cost (polynomial in n and m). In practice, greedy heuristics (that recompute the solution from scratch each time) perform well but can have high update cost in the worst case. In this paper, we bridge this gap by leveraging predictions to design a learned new data structure for the problems. Our data structure guarantees consistency, robustness, and smoothness with respect to predictions-that is, it has the best possible running time under perfect predictions, never performs worse than the best-known worst-case methods, and its running time degrades smoothly with the prediction error. Moreover, we demonstrate empirically that predictions, learned from a very small training dataset, are sufficient to provide significant speed-ups on real datasets.]]></ab></abstract>
		</profileDesc>
	</teiHeader>
	<text><body xmlns="http://www.tei-c.org/ns/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1.">Introduction</head><p>A recent line of research has focused on how learned predictions can be used to enhance the running time of algorithms. This novel approach, often referred to as warm starting, initializes an algorithm with a machine-learned starting state to optimize efficiency on a new problem instance. This starting state can significantly improve performance over the conventional method of solving problems from scratch.</p><p>Warm starting algorithms with machine-learned predictions can be viewed through the lens of beyond-worst-case analysis. While the predominant algorithmic paradigm for decades has been to use worst-case analysis, warm starting takes into account that real-world applications repeatedly solve a problem on similar instances that share a common underlying structure. Predictions about these input instances can be used to the improve running time of future computations.</p><p>This new line of research, called algorithms with predictions or learning-augmented algorithms, leverages predictions to achieve strong guarantees-much like those achieved using worst-case analysis-for warm-started algorithms. Under this setting, the performance of the algorithm is measured as a function of the prediction quality. This ensures that the algorithm is robust to prediction inaccuracies and has performance that interpolates smoothly between ideal and worst-case guarantees with respect to predictions.</p><p>Recent proof-of-concept results have demonstrated the potential to enhance the running time of offline algorithms. The area was empirically initiated by <ref type="bibr">Kraska et al. (2018)</ref>. Theoretically, <ref type="bibr">Dinitz et al. (2021)</ref> were the first to provide a theoretical framework for using warm-start to improve the running time of the weighted bipartite matching problem. Follow-up works include the application of learned predictions to improve the efficiency of computing flows using Ford-Fulkerson <ref type="bibr">(Davies et al., 2023)</ref>, shortest path computations using Bellman-Ford <ref type="bibr">(Lattanzi et al., 2023)</ref>, binary search <ref type="bibr">(Bai &amp; Coester, 2023)</ref>, convex optimization <ref type="bibr">(Sakaue &amp; Oki, 2022)</ref> and maintaining a dynamic sorted array <ref type="bibr">(Mc-Cauley et al., 2023)</ref>. These results showcase the promising potential to harness predictions more broadly for algorithmic efficiency.</p><p>Data structures are one of the most fundamental algorithmic domains, forming the backbone of most computer systems and databases. Leveraging predictions to improve data structure design remains a nascent research area. Empirical investigations, initiated by <ref type="bibr">Kraska et al. (2018)</ref> and follow-ups such as <ref type="bibr">Ferragina et al. (2021)</ref>, demonstrate the exciting potential of speeding up indexing data structures using machine learning. More recently <ref type="bibr">(McCauley et al., 2023)</ref> developed the first data structure in the new theoretical framework of algorithms with predictions. They design a learned data structure to maintain a sorted array efficiently under insertions (aka online list labeling). Since then, two concurrent works <ref type="bibr">(Brand et al., 2024)</ref> and <ref type="bibr">(Henzinger et al., 2024)</ref> show how to leverage predictions for maintaining dynamic graphs for problems such as shortest paths, reachability, and triangle detection via predictions for the matrix-vector multiplication problem. This paper focuses specifically on developing the area of data structures for dynamic graph problems. We study the fundamental problems of maintaining an incremental topological ordering of the nodes of a directed-acyclic graph (DAG) and the related problem of incremental cycle detection. In the problem, a set of n nodes V is given and the edge set is initially empty. Over time, directed edges arrive that are added to the graph. The algorithm must maintain a topological ordering of V at all times. A topological ordering is a labeling L : V ! Z of the vertices V such that L(v) &lt; L(u) if there is a directed path from v to u. A topological ordering exists if and only if the directed graph is acyclic. Thus, if an edge is inserted that creates a cycle, the data structure must report that a cycle has been detected, after which the algorithm ends.</p><p>The goal is to design an online algorithm that has small total update time for the m edge insertions. Offline, when all edges are available a priori, the problem can be solved in O(m) (linear time) by running Depth-First-Search (DFS). A naive approach to the incremental problem is to use DFS from scratch each time an edge arrives, giving O(m 2 ) total time. The goal is to design dynamic data structures that can perform better than this naive approach.</p><p>Topological ordering and cycle detection are foundational textbook problems on DAGs. Incremental maintenance of DAGs is ubiquitous in database and scheduling applications with dependencies between events (such as task scheduling, network routing, and causal networks). Due to their wide use, there has been substantial prior work on maintaining incremental topological ordering in the worst case (without predictions). Prior work can roughly be partitioned into the cases where the underlying graph is sparse or dense. A line of work <ref type="bibr">(Bender et al., 2009;</ref><ref type="bibr">Haeupler et al., 2012;</ref><ref type="bibr">Bender et al., 2015;</ref><ref type="bibr">Bernstein &amp; Chechi, 2018;</ref><ref type="bibr">Bhattacharya &amp; Kulkarni, 2020)</ref> for sparse graphs led to <ref type="bibr">(Bhattacharya &amp; Kulkarni, 2020)</ref> giving a randomized algorithm with total update time e O(m 4/3 ). The e O suppresses logarithmic factors. For dense graphs, a line of work <ref type="bibr">(Cohen et al., 2013;</ref><ref type="bibr">Bender et al., 2015)</ref> has total update time e O(n 2 ). These results hold for both incremental topological ordering and cycle detection. A recent breakthrough <ref type="bibr">(Chen et al., 2023)</ref> uses new techniques to improve the running time of incremental cycle detection to O(m 1+o(<ref type="foot">foot_0</ref>) ); their results do not extend to topological ordering. At present there are no nontrivial lower bounds for either problem, that is, it is not known if there exists an algorithm with update time e O(m).</p><p>Despite the rich theoretical literature on the problem, there is limited empirical evidence of their success <ref type="bibr">(Ajwani et al., 2008)</ref>. As most practical data is non-worst-case, greedy brute-force methods do well empirically <ref type="bibr">(Baswana et al., 2018)</ref>. The algorithms-with-predictions framework is motivated precisely by this disconnect between high-cost worstcase methods and simple practical heuristics. The goal of designing learned algorithms in this framework is to extract beyond-worst-case performance on typical instances, while being robust to bad predictions in the worst case.</p><p>More formally, in the algorithms-with-predictions framework, an algorithm is (a) consistent if it matches the offline optimal (or outperforms the worst case) under perfect predictions, (b) robust if it is never worse than the best worst-case algorithm under adversarial predictions, and (c) smooth if it interpolates smoothly between these extremes. We call an algorithm ideal if it is consistent, robust, and smooth.</p><p>In this paper, we initiate the study of how learned predictions can be leveraged for incremental topological ordering.</p><p>We propose a coarse-grained prediction model and use it to design a new ideal data structure for the problem; see Section 1.1. Moreover, we present a practical learned DFS algorithm and our experiments show that using even mildly accurate predictions leads to significant speedups. All our results extend to incremental cycle detection. Our results complement the concurrent theoretical work by <ref type="bibr">(Brand et al., 2024)</ref> on dynamic graph data structures; see Section 1.2.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1.1.">Our Contributions</head><p>We first propose a prediction model for the problem and then use it to formally describe our results.</p><p>Coarse Prediction Model. For the incremental topological ordering problem, it is natural to consider predictions on the nodes which give information about their relative ordering in the final graph. Intuitively, a vertex is earlier in the ordering if it has few ancestors and many descendants. For technical reasons, instead of predicting the number of ancestor and descendant vertices, we predict the number of ancestor and descendant edges. 1 More formally, for each vertex v, let &#8629;(v) be the total number of ancestor edges of v after all edges arrive, and let (v) be the number of descendant edges. An edge (u, w) is an ancestor edge of v in there is a directed path from w to v. The edge (u, w) is a descendent edge of v if there is a directed path from v to u. At the beginning of time, the algorithm is given predictions e &#8629;(v)</p><p>and e (v) for &#8629;(v) and (v) for each vertex v. The error in the prediction for vertex v is</p><p>We note that our prediction model predicts a small amount of information about the input, in contrast to models that predict the entire input sequence, e.g. <ref type="bibr">(Brand et al., 2024;</ref><ref type="bibr">Henzinger et al., 2024)</ref>. In particular, predictions that predict the entire input are fine-grained-each possible input sequence maps to a unique perfect prediction. Our predictions are coarse-grained because there are many possible input graphs that can map to a single perfect prediction. Intuitively, the more coarse-grained the prediction, the more robust it is to small changes in the input.</p><p>Ideal Learned Ordering. We present a new learned data structure for the incremental topological ordering, called Ideal Learned Ordering. This data structure has total update time e O(min{n&#8984; + m, m&#8984; 1/3 , n<ref type="foot">foot_1</ref> }). The data structure is ideal with respect to predictions; in particular, it is: <ref type="formula">1</ref>), its performance matches (up to logarithmic factors) the best possible running time e O(m) of an offline optimal algorithm. &#8226; Robust: For any &#8984; &#63743; m, the total running time is e O(min{m 4/3 , n 2 }), and thus its performance is never worse than the best-known worst-case algorithms <ref type="bibr">(Bender et al., 2015)</ref> and <ref type="bibr">(Bhattacharya &amp; Kulkarni, 2020)</ref>.</p><p>&#8226; Smooth: For any intermediate error &#8984;, the performance smoothly interpolates as a function of &#8984; (and n and m), between the above two extremes.</p><p>At a high level, the ideal learned ordering decomposes the vertices into subproblems based on the predictions. On each subproblem, it runs the best-known worst-case algorithm, which is warm-started with the predictions.</p><p>Learned DFS Ordering and Empirical Results. In addition to the above ideal algorithm, we present a simple practical data structure that essentially warm-starts depthfirst search using predictions. We call this the learned DFS ordering (LDFS). This data structure has total update time O(m&#8984;); thus each insert has running time O(&#8984;). We implement LDFS and our experiments show that with very little training data, the predictions deliver excellent speed-ups. In particular, we demonstrate on real time-series data that using only 5% of training data, LDFS explores over 36x fewer vertices and edges than baselines, giving a 3.1x speedup in running time. Moreover, its performance is extremely robust to prediction errors; see Figure <ref type="figure">1b</ref>.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1.2.">Related Work</head><p>Recently, <ref type="bibr">(Brand et al., 2024)</ref> leverage predictions for dynamic graph data structures. They give a general result for the online matrix-vector multiplication problem where the matrix is given and a sequence of vectors arrive online. They apply this to several dynamic graph problems including cycle detection. Their data structure requires O(n ! + n P i2V min{ i , n}) total time where i is the error between when edge i arrives and when it is predicted to arrive, and n ! is the time to perform matrix multiplication. Their prediction is the entire input, that is, the online sequence of vectors. The predictions used in this work are more coarse-grained (only require a pair of numbers per vertex), and thus are robust to small perturbations to the input sequence. Moreover, their work is purely theoretical and leaves open (a) how predictions can be leveraged for maintaining topological ordering, and (b) how predictions can be empirically leveraged for dynamic graph problems. Our work addresses both and complements their findings.</p><p>Ideal Learned Ordering uses the best-known sparse algorithm <ref type="bibr">(Bhattacharya &amp; Kulkarni, 2020)</ref> and the best-known dense algorithm <ref type="bibr">(Bender et al., 2015)</ref>, referred to as BK and BFGT throughout. We briefly summarize them; we refer to the papers for more details.</p><p>The BFGT algorithm maintains levels `(u) for each vertex u: these are underestimates of the total number of ancestors of u in the final graph. The levels are initially set to 1. On an edge insertion (x, y), if `(x) &gt; `(y), they greedily update levels to maintain a topological ordering. To improve the efficiency, they update y's level even if `(x) &#63743; `(y) if a better underestimate of the number of ancestors of y is available (based on its predecessors' levels). The total time for all insertions is bounded by e O(m + P v `(v)). As `(v) is at most the number of ancestors, their total running time is e O(n 2 ). In Section 4, we use predictions to ensure that BFGT is run on subproblems containing vertices with O(&#8984;) ancestors. Thus, the levels can only increase at most &#8984; times, which leads to the total update time e O(m + n&#8984;).</p><p>The BK algorithm (which is based on <ref type="bibr">(Bernstein &amp; Chechi, 2018)</ref>) also partitions the vertices into levels, but these are based on their ancestors and descendants. It is a randomized algorithm and initializes the vertex levels using sampling.</p><p>In particular, they use an internal parameter &#8999; where each vertex v 2 V is sampled with probability &#8677;(log n/&#8999; ). A vertex is in a level (i, j) if it has i ancestors and j descendants among the sampled nodes. They bound the number of possible ancestors and descendants of a vertex within a level using the parameter &#8999; . In Section 4, we use their algorithm as a blackbox with the exception that we set &#8999; using predictions. For the analysis, we give a tighter bound of Phase I and II of their algorithm.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1.3.">Organization</head><p>Section 2 defines the model. Learned DFS Ordering is presented in Section 3; which is generalized to the Ideal Learned Ordering in Section 4. Finally, Section 5 presents experimental results. For space, many proofs and further experiments are deferred to the Appendices A and B.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.">Model and Definitions</head><p>Directed Graphs.</p><p>We say that a vertex v is an ancestor of vertex w if there is a path from v to w in the graph. We say w is a descendant of v if v is an ancestor of w. A vertex is an ancestor and descendant of itself. We say that an edge (u, v) is an ancestor edge of a vertex w if v is an ancestor of w. Similarly, an edge</p><p>A directed graph has a cycle if there exist vertices u and w that are mutually reachable from each other: that is, u is both an ancestor and descendant of w. A topological ordering of a directed graph exists if and only if it is acyclic.</p><p>Incremental Graph Problems. In the incremental topological ordering and cycle detection problems, initially, there are n vertices V and no edges. The m edges from the set E arrive one at a time and are inserted into the graph data structure. Let G t denote the graph after t edges have been inserted (which we also refer to as time t). We assume that after an edge is inserted, the graph continues to be acyclic.</p><p>If an edge insertion leads to a cycle, the algorithm must report the cycle and terminate. Thus G m denotes the final graph (after the last edge insertion that does not create a cycle).</p><p>The performance of the graph data structure is measured as its total running time to perform all m edge insertions.</p><p>In Sections 3 and 4, we use the terms total cost and total update time and total running time interchangeably. We use the notation e O defined as e O(f</p><p>Prediction Model. In the incremental topological ordering problem with predictions, the data structure additionally obtains a prediction for each vertex v 2 V at the beginning.</p><p>Intuitively, this prediction helps the data structure initialize the label of v to be closer to a feasible topological ordering.</p><p>For a vertex v, let &#8629;(v) be the total number of ancestor edges of v in the final graph G m . Analogously, let (v) be the total number of descendant edges of v in the final graph G m . The Learned-DFS Ordering in Section 3 receives a prediction e &#8629;(v) of &#8629;(v) for each vertex v. <ref type="foot">4</ref> The prediction error of a vertex v is</p><p>The Ideal Learned Ordering in Section 4 receives a prediction e &#8629;(v) of the number of ancestors &#8629;(v) and e (v) of the number of descendants (v) respectively, for each vertex v. The prediction error of the vertex v is</p><p>The overall error is &#8984; = max v &#8984; v throughout the paper.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.">Learned-DFS Ordering</head><p>In this section, we give a simple and easy-to-implement data structure that achieves O(m&#8984;) total update time. We refer to this algorithm as the Learned DFS Ordering (LDFS).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.1.">Algorithm Description</head><p>At all times, the algorithm maintains a level `(v) for each vertex, which is a number from 0 to m. For each vertex v, the algorithm maintains a linked list in(v) of v's parents at the same level (i.e. a linked list of all parents p of v with `(p) = `(v)). Finally, to maintain a topological ordering, the algorithm additionally maintains a (global) counter a, and for each vertex v an integer j(v) 2 {1, . . . , nm + 1}.</p><p>Initially, a = nm+1, and for each v,</p><p>{}, and j(v) = nm + 1. On insertion of an edge e = (u, v), if `(u) &gt; `(v), set `(v) `(u) and in(v) {u}. Then, do a forward search from v to recursively update v's descendants. That is, for each child w of v, if `(v) &gt; `(w), update `(w) and in(w) and recurse. Report a cycle if one is found; otherwise calculate a topological order T f on all vertices whose levels changed during this search.</p><p>Cycle detection. After the above update concludes, if `(u) = `(v), do a reverse DFS starting at u (i.e. a DFS where edges are followed backward) only following edges in(u) from vertices at the same level. If this search visits v, report a cycle. Otherwise, let T b be a topological order on the vertices visited during this DFS (e.g., T b can be computed by ordering vertices in the order of their DFS finish times).</p><p>Topological ordering. The ordering imposed by the level `(v) on the vertices is a pseudo-topological ordering <ref type="bibr">(Bender et al., 2015)</ref>. Indeed, our algorithm can be viewed as a simplification of the sparse algorithm in <ref type="bibr">(Bender et al., 2015)</ref> with the addition that levels are initialized using predictions.</p><p>Bender et al. describe how to extend their ordering to a topological order by breaking ties between vertices on a level using the order in which they are traversed in the reverse DFS. We use a similar technique here. Concatenate T b and T f to create a single topological order T . If `(u) = `(v) and j(u) j(v), proceed through each vertex w 2 T in reverse order. Set j(w) = a, then a = a 1, and then set w to the previous vertex in T .</p><p>We define the label of a vertex v to be L(v) = `(v)(nm + 2) + j(v). The algorithm maintains the following invariants.</p><p>Invariant 3.1. For any edge e = (u, v) in the graph G t at time t, `(u) &#63743; `(v).</p><p>Invariant 3.2 ( <ref type="bibr">(Bender et al., 2015, Theorem 2.5)</ref>). At all times, a 2 {1, . . . , nm + 1}; furthermore, a is nonincreasing over the entire run of the algorithm.</p><p>&#8629;(a).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.2.">Analysis</head><p>The following proves that the algorithm is always correct.</p><p>Lemma 3.4. If the insertion of the last edge creates a cycle in G t , the simple learned algorithm correctly detects and reports it. Furthermore, for any edge e = (u, v) in the graph G t at time t, L(u) &lt; L(v).</p><p>We bound the running time by bounding the cost of the forward search to update levels, and the reverse DFS within a level to detect a cycle.</p><p>We first upper bound how big the levels can get using &#8984;.</p><p>Lemma 3.5. Let `0 and `m denote the initial and final level of any vertex v. Then, `m `0 &#63743; 2&#8984;.</p><p>Lemma 3.5 is sufficient to bound the cost of all level updates during the forward search.</p><p>Lemma 3.6. The total cost to update the levels of all vertices is O(m&#8984;).</p><p>Proof. To obtain the total cost of updating the levels, note that each time we update the level of a vertex v, the algorithm recursively updates its children, and then checks each of its parents to update in(v). This takes O( (v)) time, where (v) is the sum of the outdegree and indegree of v. Thus, using Lemma 3.5 the total cost of all level updates is</p><p>To bound the cost of the reverse DFS on a level, we bound the number of incoming edges on any level at any time.</p><p>Lemma 3.7. At any time, if a vertex v has k ancestor edges on its level then &#8984; k/2. Now we can bound the cost of the reverse DFS. The algorithm maintains incoming edges in(v) of v from vertices on its level in a linked list. Performing the reverse DFS from v thus has cost O(1 + a t (v)), where a t (v) is the number of ancestor edges of v from vertices at level `(v) at time t. By Lemma 3.7, a t (v 1 ) &#63743; &#8984; and thus the reverse DFS costs O(&#8984;) for each insertion. Finally, combining with Lemma 3.6 and the O(n) time for initialization, we get the following result. Theorem 3.8. The Learned DFS Ordering solves the incremental topological ordering and cycle detection problem with predictions in total running time O(m&#8984; + n).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.">Ideal Learned Ordering</head><p>In this section, we give an ideal learned data structure for the incremental topological ordering and cycle detection problem with total update time e O(m + min{n&#8984;, n 2 , m&#8984; 1/3 }) for m edge insertions. We refer to this algorithm as Ideal Learned Ordering. The algorithm receives a prediction e &#8629;(v) and e (v) of the number of ancestor and descendant edges of each vertex in the final graph G m . By definition, |e</p><p>Prediction Decomposition. At a high level, the algorithm decomposes the problem instance into smaller subproblems based on each vertex's prediction, and uses the state-of-theart worst-case algorithm on each subproblem based on the instance's sparsity. Recall that BK and BFGT refer to the best-known sparse algorithm by <ref type="bibr">(Bhattacharya &amp; Kulkarni, 2020)</ref> and the best-known dense algorithm by <ref type="bibr">(Bender et al., 2015)</ref>; see Section 1.2. Using a tighter analysis for these algorithms under predictions, we then bound the running time of each subproblem using the prediction error.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.1.">Algorithm Description</head><p>The algorithm maintains an estimate &#8984; which is an estimate of the overall error &#8984; based on edges seen so far. It also maintains a level `(v) for each vertex, initialized using both e &#8629;(v) and e (v). It maintains a pseudo-topological ordering over these levels greedily. We decompose the initial set of vertices V into a sequence of subproblems based on the predictions for each vertex. When an edge e = (u, v) arrives, it is treated as an edge insertion into each subproblem that contains both u and v. The algorithm invokes the BK or BFGT algorithm to perform this insertion and to assign internal labels within each subproblem.</p><p>If an edge is inserted across subproblems that violates the ordering over the levels, the algorithm updates its estimate of &#8984; and rebuilds with an improved decomposition.</p><p>Algorithm setup. Let &#8984;i be the value of &#8984; after i edges are inserted. We begin with &#8984;0 = 1.</p><p>We maintain a level `(v) for each vertex v. Each `(v) consists of a pair of numbers: `(v) = (`a(v), `d(v)); we call this the ancestor level and descendant level of v respectively. The idea is that `a(v) and `d(v) are initialized using the predicted ancestors and descendants of v respectively and updated as edges are inserted.</p><p>At all times, the level `(v) has four possible values satisfying the constraints below. These are referred to as the possible levels for v.</p><p>We maintain that for any edge e = (u, v), `a(u) &#63743; `a(v) and `d(u) `d(v).</p><p>At any time, the vertex set V is decomposed into subproblems H j,k , where the indices j, k 2 {0, . . . , dm/&#8984; i e + 1}.</p><p>Each subproblem H := H j,k is a subgraph of G t and represents an instance of the incremental topological ordering problem (possibly at an intermediate state with some edges already inserted). A vertex v can be part of at most four subproblems, indexed by one of its possible levels:</p><p>As each vertex is in at most four subproblems, the algorithm maintains O(n) subproblems at any point; note that "empty" subproblems are not maintained.</p><p>Initialization and Build. We first describe how to perform a BUILD on a graph G t ; BUILD is called each time the estimate &#8984; changes. At initialization, BUILD(G 0 ) adds each vertex v to the subproblems H(v). If a sequence of edge insertions e 1 , . . . , e t are such that tth insertion causes &#8984;t to be updated, then BUILD(G t ) first updates H(v) for each v based on the updated value of &#8984;t and adds v to H(v).</p><p>Then it calls INSERT(e i ) for i 2 {1, . . . , t} using the insert algorithm described next.</p><p>The insert algorithm uses a further subroutine BUILD-BFGT(H), which is used to "switch" a subproblem from the sparse case to the dense case. Let V H and E H be the vertices and edges currently in H. BUILD-BFGT initializes an instance of BFGT on vertices V H , and then inserts all edges in E H one by one using BFGT.</p><p>Edge Insertion. On the insertion of the tth edge e t , IN-SERT(e t ) first recursively updates the ancestor and descendant levels of v and u in G t . That is, if `a(u) &gt; `a(v), set `a(v) = `a(u) and recurse on all out-edges of v.</p><p>and recurse on all in-edges of u. This maintains the following invariant.</p><p>Invariant 4.1. For any edge e = (u, v), `a(u) &#63743; `a(v) and `d(u) `d(v).</p><p>If for any vertex v, the updated value of `(v) is not one of the possible levels of v, the algorithm doubles &#8984; (i.e. set &#8984;i = 2&#8984; i 1 ) and calls BUILD on G t .</p><p>Next, we describe how the algorithm inserts e t into all subproblems H 2 H(u) \ H(v) using the BK or BFGT algorithm based on whether the subproblem is sparse or dense. Without predictions, a graph is termed sparse if m = o(n 3/2 ) and dense otherwise. To determine if a subproblem with predictions is sparse or dense, the algorithm takes error &#8984; into account. More formally, let n 0 and m 0 denote the number of vertices and edges in a subproblem H prior to the insertion of e t into H. Then:</p><p>&#8226; (Sparse) If m 0 + 1 &lt; n 0 &#8984; 2/3 , it inserts e t to the subproblem H using BK;</p><p>&#8226; (Dense) if m 0 &gt; n 0 &#8984; 2/3 , it inserts e t to subproblem H using BFGT;</p><p>&#8226; (Sparse to dense transition) if m 0 &lt; n 0 &#8984; 2/3 and m 0 + 1 &gt; n 0 &#8984; 2/3 , it calls BUILD-BFGT(H) first, then inserts e t into H using BFGT.</p><p>We refer to the label within a subproblem assigned by the BFGT or BK algorithm as an internal label of the vertex.</p><p>If after t edges are inserted (for any t) we have &#8984; &gt; n and t&#8984; 1/3 &gt; n 2 , the algorithm ignores all predictions and reverts to using the worst-case BFGT. The algorithm creates a new instance of BFGT using the vertices in G t , and inserts all t edges into this BFGT instance one by one. All future edges are inserted into this BFGT instance.</p><p>Defining Labels. For any vertex v, let i(v) be the internal label of v in subproblem H `(v) . Let k be a positive integer larger than the internal label of any node in a graph with n vertices in either BFGT or BK (we note that both algorithms maintain only nonnegative labels). Define the label L of v as</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.2.">Analysis</head><p>We analyze the correctness and running time of Ideal Learned Ordering.</p><p>Correctness. First, we show that if a cycle exists, then it is correctly reported by the algorithm.</p><p>By Invariant 4.1, if the insertion of an edge creates a cycle, all vertices in the cycle must have the same level `. The algorithm maintains the invariant that at all times H `(v) 2 H(v), so all vertices and edges in the cycle must be in some subproblem H and thus will be detected by BFGT or BK.</p><p>Lemma 4.2. For any edge e = (u, v) in G t , L(u) &#63743; L(v).</p><p>Proof.</p><p>then the lemma holds since i(u) &lt; k. Otherwise, suppose `a(u)+m `d(u) `a(v)+m `d(v). By Invariant 4.1, `a(u) &#63743; `a(v) and m `d(u) &#63743; m `d(v); thus we must have `(u) = `(v). Thus, i(u) and i(v) are both assigned by BFGT or BK on H `(u) . By correctness of BFGT and BK, i(u) &lt; i(v). Running Time Analysis. We give an overview of the running time analysis of Ideal Learned Ordering. Proofs are deferred to Appendix A. Lemma 4.3 bounds the number of ancestors and descendants of a vertex within the graph of any subproblem. Lemma 4.3. For any subproblem H j,k and vertex v 2 H j,k , v has at most 2(&#8984; + &#8984;) ancestor edges and 2(&#8984; + &#8984;) descendant edges in H j,k . Lemma 4.4 shows that the estimate &#8984; maintained by the algorithm is never more than 2&#8984;. Lemma 4.4. At all times, &#8984; &#63743; 2&#8984; Lemma 4.5 and Lemma 4.6 bound the cost of running BFGT and BK any subproblem respectively. Lemma 4.5. Consider a subproblem H with n 0 vertices and m 0 edges that are inserted into H one by one. If each vertex in H has at most O(&#8984;) edge ancestors, then the total running time of running BFGT on H is e O(n 0 &#8984; + m 0 ) time. Lemma 4.6. Consider a subproblem H with n 0 nodes and m 0 edges, such that: (1) m 0 &lt; &#8984;2 n 0 / log 2 n 0 , (2) each vertex in H has at most O(&#8984;) edge ancestors and O(&#8984;) edge descendants, and (3) &#8984; = O(&#8984;). Then running BK on H with parameter &#8999; = n 1/3 &#8984;2/3 /m 1/3 takes total time e O(m 0 &#8984; 1/3 ) in expectation.</p><p>Finally, Theorem 4.7 analyzes the total running time.</p><p>Theorem 4.7. Ideal Learned Ordering has total expected running time e O(min{m&#8984; 1/3 , n&#8984;, n 2 }).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5.">Experiments</head><p>This section presents experimental results for the Learned DFS Ordering (LDFS) described in Section 3. Our experiments show that using prediction significantly speeds up performance over baseline solutions on real temporal data. Moreover, only a small amount of training dataset (e.g., 5%) is sufficient to see one or two orders of magnitude of improvement. Finally, we show that LDFS is extremely robust to errors in the predictions.</p><p>Our implementation and datasets can be found at <ref type="url">https://github.com/AidinNiaparast/  Learned-Topological-Order</ref>.</p><p>Algorithms. We compare LDFS against two natural baseline solutions that we call DFS I and DFS II. Each of the three algorithms use a greedy depth-first-search approach to maintain a topological ordering, with the difference that LDFS warm-starts its levels using predictions.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>DFS I.</head><p>The first algorithm is equivalent to LDFS with zero predictions: that is, e &#8629;(v) = 0 for each v.</p><p>DFS II. This algorithm was presented by <ref type="bibr">(Marchetti-Spaccamela et al., 1993)</ref> for incremental topological ordering and revisited by <ref type="bibr">(Franciosa et al., 1997)</ref> for incremental DFS. It has total update time O(mn). <ref type="bibr">(Baswana et al., 2018)</ref> perform an empirical study on incremental DFS algorithms and show that DFS II (which they call FDFS) is the stateof-the-art on DAGs. DFS II maintains exactly one vertex at each level. When an edge (u, v) is inserted, if l(v) &lt; l(u), the algorithm performs a partial DFS to detect all the vertices w reachable from v such that l(v) &lt; l(w) &lt; l(u), and updates their levels to be larger than l(u).</p><p>We remark that the Ideal Learned Ordering algorithm is of theoretical interest. Our experiments focus on the practical algorithm (LDFS) and on showing the usefulness of predictions.</p><p>Datasets. We use real directed temporal networks from the SNAP Large Network Dataset Collection <ref type="bibr">(Leskovec &amp; Krevl, 2014)</ref>. To obtain the final DAG G, we randomly permute the vertices and only keep the edges that go from smaller to larger positions (this ensures G is acyclic). Then, we sort the edges in increasing order of their timestamps to obtain the sequence of edge insertions. Table <ref type="table">1</ref> summarizes these datasets. Note that these graphs are sparse.</p><p>Predictions. To generate the predictions for LDFS, we use a contiguous portion of the input sequence as the training set. Consider the graph that results from inserting the training set edges into an empty graph. For each node v, we define e &#8629;(v) to be the number of v's ancestor edges in that graph.</p><p>Experimental Setup and Results. On real datasets, we compare LDFS to DFS I and II in terms of the number of edges and vertices processed (cost) in Table <ref type="table">2a</ref> and in terms of runtime in Table <ref type="table">2b</ref>. The last 50% of the data in increasing order of the timestamps is used as the test data in all of the experiments in Table <ref type="table">2</ref>. The training data for LDFS is a contiguous subsequence of the data that comes right before the test data.</p><p>We include plots for the email-Eu-core<ref type="foot">foot_4</ref>  <ref type="bibr">(Paranjape et al., 2017)</ref> dataset, which contains the email communications in a large European research institution. A directed edge (u, v, t) in this dataset means that u has sent an e-mail to v at time t. Figure <ref type="figure">1a</ref> shows how the training data size affects the runtime of LDFS. Figure <ref type="figure">1b</ref> is a robustness experiment showing performance versus the noise added to predictions.</p><p>For testing robustness to prediction error, we add noise to the predictions. We first generate predictions as described.</p><p>Then, we calculate the standard deviation of the prediction error, which we denote by SD(predictions). Finally, we add a normal noise with mean 0 and standard deviation SD(noise) = C&#8226; SD(predictions) (for some constant C) independently to all of the predictions to obtain our noisy predictions. We repeat the experiment 10 times, each time regenerating the noisy predictions; we plot the mean and standard deviation of the resulting running time in Figure <ref type="figure">1b</ref>. Discussion. Results in Table <ref type="table">2</ref> demonstrate that, in all cases, even a very basic prediction algorithm can significantly enhance performance over the baselines. Only 5% of historical data is needed to see a significant difference between our methods's performance and the baselines; in some cases up to a factor of 36 in cost. Better predictions obtained from 50% of historical data improve performance further, up to a factor of 116. These experiments show that it is possible to learn predictions that give significant performance improvements from a small amount of training data.</p><p>Finally, Figure <ref type="figure">1b</ref> shows that LDFS is very robust to bad predictions. For example, note that if SD(noise) 2 &#8226; SD(predictions), then &#8673; 61% of the noisy predictions have noise added to them that is at least SD(predictions)<ref type="foot">foot_5</ref> thus, the relative value of the predictions becomes largely random for many items. Since the LDFS algorithm's performance only depends on how predictions for different nodes relate to each other (not their value), this represents a significant amount of noise, effectively nullifying the predictions of many nodes. Nonetheless, LDFS still outperforms the baselines even for this extreme stress test. Moreover, increasing the noise degrades the performance confirming that the efficiency does depend on the quality of predictions.</p><p>In Appendix B, we include additional plots for the datasets in Table <ref type="table">1</ref>. We also investigate the effect of edge density on performance for synthetic DAGs. These experiments further support our conclusions; in particular, even for very dense DAGs, our algorithm still outperforms the baselines, although with smaller margins.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.">Conclusion</head><p>This paper gave the first dynamic graph data structure that leverages predictions to maintain an incremental topological ordering. We show that the data structure is ideal: that is, it is consistent, robust, and smooth with respect to errors in prediction. Thus, predictions deliver speedups on typical instances while never performing worse than the state-ofthe-art worst case solutions. This paper is also the first empirical evaluation of using predictions on dynamic graph data structures. Our experiments show that the theory is predictive of practice: predictions deliver up to 6x speedup for LDFS compared to natural baselines.</p><p>Our results demonstrate the incredible potential for improving the theoretical and empirical efficiency of data structures using predictions. It would be interesting to explore how predictions can be leveraged for designing data structures</p><p>(a) (b)</p><p>Figure <ref type="figure">1</ref>. Total cost (number of nodes and edges processed) of LDFS compared to the two baselines for email-Eu-core dataset, in logarithmic scale. In Figure <ref type="figure">1a</ref>, the x-axis is the percentage of the input sequence used as training data for LDFS. The training data in this experiment is a contiguous subsequence of the data that comes right before the test data. Figure <ref type="figure">1b</ref> shows the effect of adding noise to predictions on the cost of LDFS. In this experiment, the first 5% of the input is used as the training data and the last 95% as the test data. For different values of C, a normal noise with mean 0 and standard deviation (SD) of C&#8226;SD(predictions) is independently added to each prediction. This noise is regenerated 10 times. The x-axis is SD(noise)/SD(predictions). The blue line is the mean and the cloud around it is the SD of these experiments.</p><p>for other dynamic graph problems.</p><p>We remark that the Ideal Learned Ordering algorithm is of theoretical interest and we did not implement it. Similarly, the subroutines BK and BFGT used by the algorithm as a black box are of theoretical interest and, as far as we are aware, have not been empirically evaluated. We leave it as an open question how to engineer these algorithms to work well in practice.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>A. Omitted Proofs</head><p>Proof of Lemma 3.4. By Invariant 3.1, for any cycle C in the graph, all vertices in C must at the same level. Each time we add an edge e = (u, v), if `(u) = `(v), the algorithm checks whether the addition of this edge creates a cycle within that level through a reverse depth-first search. Now, assume there is no cycle in G t ; we show that a weak topological sort is maintained. A weak topological sort is trivially maintained in G 0 , so assume inductively that the algorithm correctly maintains a weak topological sort in G t 1 . Consider an edge (u, v) 2 G t . If `(u) &lt; `(v), then the label of u is less than the label of v since j(u), j(v) &#63743; nm + 1. If `(u) = `(v), then we split into cases based on if the label of u or v was changed during the updates after the tth edge was inserted. If neither u or v were updated, the labels continue to be a topological ordering as in G t 1 . It is not possible that v is updated but u is not: for any v visited during DFS, since `(u) = `(v), u is also visited; for any v whose label is updated, u must have a strictly larger label than any other parent of v. If u is updated and v is not, then j(u) is set to a; since a decreases each time some j(w) is set, we must have j(u) &lt; j(v). If both u and v are updated, u must come before v in T . Again, since a decreases each time some j(w) is set, we must have j(u) &lt; j(v).</p><p>Proof of Lemma 3.7. Let A denote the set of all ancestors of v at level `(v) at the current time. Consider the vertices in A after all edges are inserted (in G m ): since G m is acyclic, there must be at least one vertex z 2 A such that no vertex w 2 A has that w is an ancestor of z in G m .</p><p>Since z is an ancestor of v, all ancestor edges of z are ancestor edges of v. However by definition of z, an ancestor edge of any w 2 A is never an ancestor edge of z. All k ancestor edges of v on its level are ancestor edges of some w 2 A. Therefore, &#8629;(v) &#8629;(z) + k, so &#8629;(v) &#8629;(z) k.</p><p>As levels only increase `(v) e &#8629;(v). By Invariant 3.3, `(v) &#63743; e &#8629;(z); equivalently, e &#8629;(v) + e &#8629;(z) 0. Summing the above two inequalities, we get</p><p>Proof of Lemma 4.3. Let H refer to the subgraph H j,k after the last edge is inserted into it (thus, H includes edges that are inserted in the future, whereas H j,k does not). We use &#8629; H (v) and H (v) to denote the number of number of ancestor and descendant edges of a vertex v in H.</p><p>Let u be an ancestor of v in H, such that no ancestor edge of v in H is an ancestor edge of u in H. Such a u always exists as H is acyclic and can be found by recursively following in-edges of v.</p><p>By definition of u, all ancestor edges of u are ancestor edges of v (in G m ); however, no ancestor edges of v in H are ancestor edges of w (in G m ). Thus, &#8629;(v) &#8629;(u) + &#8629; H (v), so &#8629;(v) &#8629;(u) a H (v).</p><p>As both v and u are in H j,k we can bound the difference of their predictions using &#8984;. That is, j de &#8629;(v)/&#8984;e, and therefore j e &#8629;(v)/&#8984;. Similarly, j &#63743; de &#8629;(u)/&#8984;e + 1, so j &#63743; e &#8629;(u)/&#8984; + 2. Combining, e &#8629;(u)/&#8984; + 2 e &#8629;(v)/&#8984;, so e &#8629;(u) e &#8629;(v) 2&#8984;.</p><p>Summing the two above equations, we obtain that</p><p>By the definition, &#8629;(v) e &#8629;(v) &#63743; &#8984; and e &#8629;(u) &#8629;(u) &#63743; &#8984;. Substituting, a H (v) &#63743; 2&#8984; + 2&#8984;.</p><p>The analysis for the number of descendants is analogous. Let w be a descendant of v in H, such that no descendant edge of v in H is a descendant edge of w in H . By definition of w, all descendant edges of w are descendant edges of v (in G m ); however, no descendant edges of v in H are descendant edges of w (in G m ). Therefore, (v)</p><p>As both v and w are in H j,k , we have that j &#63743; b e (w)/&#8984;c, and therefore j &#63743; e (w)/&#8984;. Similarly, j b e (v)/&#8984;c 1, so j e (v)/&#8984; 2. Combining, e (w)/&#8984; e (v)/&#8984; 2, so e (w) e (v) 2&#8984;.</p><p>Summing the two above equations, we obtain that</p><p>By the definition, (v) e (v) &#63743; &#8984; and e (w) (w) &#63743; &#8984;. Substituting, H (v) &#63743; 2&#8984; + 2&#8984;. As the number of ancestor and descendant edges are nondecreasing, this upper bound (in H after all edges are inserted), is also an upper bound at all times in H j,k .</p><p>Proof of Lemma 4.4. We proceed by induction. The lemma is trivially satisfied at time 0 (since &#8984;0 = 1), as well as any time where &#8984; does not change.</p><p>Consider a time when &#8984; is increased, from &#8984; to 2&#8984;; we show that &#8984; &#63743; 2&#8984;. When &#8984; is increased, there is some vertex v with `(v) / 2 H(v). We split into two cases based on if the ancestor level or the descendant level constraint is violated: `a(v) &gt; de &#8629;(v)/&#8984;e+1, and `d(v) &lt; b e (v)/&#8984;c 1. We begin with the first case. Without loss of generality, consider a vertex v that violates the constraint such that no ancestor of v violates the constraint. Specifically, `a(v) &gt; de &#8629;(v)/&#8984;e + 1, whereas `(u) &#63743; de &#8629;(v)/&#8984;e + 1 for all ancestors u of v.</p><p>When inserting an edge e = (x, y), the algorithm updates the ancestor levels of all descendants of x to have the same ancestor levels as x; no other ancestor levels are updated. Thus, v has an ancestor w with e &#8629;(w) = `a(v).</p><p>Noting that the label of v can only increase, we must have that e &#8629;(w) = `(v) &gt; de &#8629;(v)/&#8984;e+1. Thus, e &#8629;(w) e &#8629;(v) &gt; &#8984;.</p><p>Since w is an ancestor of v, &#8629;(w) &lt; &#8629;(v), so &#8629;(v) &#8629;(w) 0. Summing the above two equations,</p><p>The analysis for the descendant constraint is identical.</p><p>Proof of Lemma 4.5. For each vertex, BFGT maintains a vertex level (that determines the internal label for our algorithm), and a vertex count. In the proof of <ref type="bibr">(Bender et al., 2015, Theorem 3.6)</ref>, each edge traversal in BFGT increases the vertex level or a vertex count, and the running time of BFGT is upper bounded by the number of edge traversals plus m 0 (i.e. O(1) additional time for each inserted edge, even if no edge is traversed). Thus, our goal is to bound the number of times a vertex level or vertex count increases in H.</p><p>A vertex level begins at 0 and is nondecreasing for all vertices by definition. By <ref type="bibr">(Bender et al., 2015, Theorem 3.5)</ref>, the level of each vertex is upper bounded by the number of (vertex) ancestors, which is in turn upper bounded by the number of edge ancestors. Since each vertex has O(&#8984;) vertex ancestors by Lemma 4.5, the total number of vertex level increases is e O(&#8984;), giving e O(n 0 &#8984;) increases overall.</p><p>Next, we summarize how a vertex count changes over time, and use this to show that it increases by the maximum vertex level. Let `= e O(&#8984;) be the maximum vertex level of any vertex. See the proof of <ref type="bibr">(Bender et al., 2015, Theorem 3.6</ref>) for more details. The data structure maintains a parameter j for each vertex v, where j is at most log 2 (current vertex count of v). The count for a vertex v begins at 0, and increases up to 3 &#8226; 2 j , after which it is reset to 0. This count must increase by at least 2 j over the same time. Thus, so far, the number of times a vertex count is incremented is at most 3`. The count may be reset to 0 one additional time (at most 3`more increases); furthermore, the count may at the end of the algorithm increase up to 3 &#8226; 2 j without being reset (another 3`more increases). Thus, a vertex count can be incremented at most 9`times.</p><p>Proof of Lemma 4.6. The cost of BK as shown in <ref type="bibr">(Bhattacharya &amp; Kulkarni, 2020)</ref> </p><p>First, we show that if all vertices in H have at most O(&#8984;) edge ancestors and O(&#8984;) edge descendants, then the running time of BK on H is</p><p>Let us begin with the first term of Equation <ref type="formula">1</ref>. This term comes from (Bhattacharya &amp; Kulkarni, 2020, Lemma 2.2). Specifically, there are n/&#8999; sampled vertices in expectation; we maintain all ancestors and descendants of each sampled vertex. This can be done efficiently using the classic data structure presented in <ref type="bibr">(Italiano, 1986)</ref>.</p><p>The result as stated in <ref type="bibr">(Italiano, 1986)</ref> states that the descendants of all (rather than just sampled) vertices can be maintained in O(nm) time. Our results require a slightly stronger analysis. <ref type="foot">7</ref> For completeness, we summarize this tighter analysis here. The bounds in <ref type="bibr">(Italiano, 1986</ref>) are based on a potential function analysis, where each vertex v has (using the notation of <ref type="bibr">(Italiano, 1986</ref>)) potential (|vis(x) + 3|desc(x)), where vis(x) is the number of descendant edges of x, and desc(x) is the number of descendant vertices of x. They show that their amortized cost (the cost plus the change in potential) of an edge insert is O(1), and that the potential of all nodes is nonincreasing.</p><p>We observe that if we only want to maintain the descendants of sampled vertices, we can set the potential of non-sampled nodes to 0; their amortized analysis argument still holds under this change. By Lemma 4.3 and Lemma 4.4, the potential of any node is at least 6&#8984;, so the total cost to maintain the descendants of each sampled vertex is O(&#8984;).</p><p>An essentially-identical analysis shows that the total cost to maintain all ancestors of sampled nodes is O(&#8984;). Since there are n/&#8999; expected sampled nodes, we obtain a total expected cost of O(n&#8984;/&#8999; ).</p><p>Now, the second term of Equation <ref type="formula">1</ref>. In <ref type="bibr">(Bhattacharya &amp; Kulkarni, 2020, Lemma 2.3)</ref>, it is shown that the total time in "phase II" is e O(n 2 /&#8999; ). In short, they show that the cost for a vertex v is e O(A S (v) + D S (v)), where A S (v) and D S (v) are the number of sampled ancestor and descendant vertices of v respectively. Since a vertex is sampled with probability &#8677;(log n/&#8999; ), they obtain expected cost e O(n/&#8999; ) per vertex. A vertex in H has only O(&#8984;) ancestor or descendant edges, and therefore only O(&#8984;) ancestor or descendant vertices, and therefore expected cost e O(log n 0 &#8984;/&#8999; ). Summing over all n 0 vertices of H we obtain the desired second term.</p><p>The third and fourth term of Equation 1 remain unchanged; thus the running time of BK on H is given by Equation <ref type="formula">1</ref>.</p><p>Substituting &#8999; = n 01/3 &#8984;2/3 /m 01/3 , we obtain running time m&#8984; 1/3 . Note that BK samples vertices with probability &#8677;(log n/&#8999; ), so we need that &#8999; = &#8998;(log n). This is satisfied for large n 0 due to m 0 &lt; &#8984;2 n 0 log 2 n 0 . We note that if BK was to sample vertices with a fixed probability C 1 log n 0 /&#8999; , we could replace the final log n 0 term in our bound on m 0 with C 1 .</p><p>Proof of Theorem 4.7. We bound the cost of updating the levels first; then we bound the total cost of all subgraphs.</p><p>First, we consider the cost of updating levels after the ith edge is inserted. We only traverse an edge (u, v) while updating levels if the level of u is updated.</p><p>First, consider an update when &#8984; does not increase; thus each vertex has one of its possible levels after the update. Each vertex has four possible levels, so each vertex can have its levels updated once per value of &#8984;; thus, each edge can only be traversed once per value of &#8984;. This leads to e O(m log &#8984;m ) time. Now, the other case: if &#8984; increases, the cost of the scan is at most O(m); since &#8984; increases log 2 &#8984; times, this gives an additional e O(m log &#8984;m ) time.</p><p>Now, the cost of inserting all edges into their corresponding subgraphs. Let us begin with some observations about the cost of a single subgraph H i,j with n 0 vertices and (after all insertions are complete) m 0 edges, for a fixed &#8984;. If m 0 &lt; &#8984;2/3 n 0 / log 2 n, then by Lemma 4.6 (note that m 0 &lt; &#8984;2/3 n 0 / log 2 n implies m 0 &lt; &#8984;2 n 0 / log 2 n 0 ), all edge insertions into H i,j cost m 0 &#8984;1/3 . If m 0 &#8984;2/3 n 0 / log 2 n 0 , then the first &#8984;2/3 n 0 / log 2 n 0 insertions into H i,j have cost e O(&#8984;n 0 ) by Lemma 4.6. All remaining insertions (including reinserting the first &#8984;2/3 n 0 / log 2 n 0 edges during REBUILD) have cost O(n 0 &#8984;) by Lemma 4.5, for O(n 0 &#8984;) total time. Overall, all edge insertions into H i,j take O(min{n 0 &#8984;, m 0 &#8984;1/3 }) time. Now, we sum over all subgraphs and over all values of &#8984; to achieve the final running time. Let `&#8984; = log 2 &#8984;; thus when &#8984; doubles `&#8984; is incremented. Let n i,j,&#8984; and m i,j,&#8984; be respectively the number of vertices and total number of edges in H i,j under a given &#8984;. Then we can bound the total time spent in all subgraphs as:  Substituting, the total running time on all subgraphs is e O(min{n&#8984;, m&#8984; 1/3 }). If at any time &#8984; &gt; n and m&#8984; 1/3 &gt; n 2 we stop the above process and use BFGT. The cost of all edge inserts while &#8984; &#63743; n is e O(n 2 ) by the above; the cost of all remaining inserts is e O(n 2 ) <ref type="bibr">(Bender et al., 2015)</ref>. Thus, the overall total running time is e O(min{n&#8984;, m&#8984; 1/3 , n 2 }).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>B. Additional Experiments</head><p>In this section, we present additional experiments; in particular, we explore how the performance is influenced by the edge density of the graph in synthetic DAGs. We also further describe the experimental setup and the datasets we use.</p><p>Dataset Description. Here we describe the real temporal datasets we use in our experiments.</p><p>&#8226; email-Eu-core<ref type="foot">foot_7</ref>  <ref type="bibr">(Paranjape et al., 2017)</ref>: This network contains the records of the email communications between the members of a large European research institution. A directed edge (u, v, t) means that person u sent an e-mail to person v at time t.</p><p>&#8226; CollegeMsg<ref type="foot">foot_8</ref>  <ref type="bibr">(Panzarasa et al., 2009)</ref>: This dataset includes records about the private messages sent on an online social network at the University of California, Irvine. A timestamped arc (u, v, t) means that user u sent a private message to user v at time t. Discussion. Figure <ref type="figure">2</ref> suggests that our algorithm (without perturbation) outperforms the baselines, even for very dense DAGs (note that the last point in the x-axis corresponds to p = 1, which means that the DAG is complete). However, as the edge density of the DAG increases, the gap between our algorithm and DFS II decreases. Also for high densities and high perturbations, our algorithm still performs reasonably compared to other baselines in terms of cost (which is the main focus of the paper). Another observation is that LDFS is more robust to perturbation on sparse graphs. Finally, Figures <ref type="figure">3</ref>, <ref type="figure">4</ref>, and 5 further support our conclusions in Section 5. </p></div><note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="1" xml:id="foot_0"><p>This is because the running time of the learned algorithm depends on the number of edges traversed.</p></note>
			<note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="2" xml:id="foot_1"><p>For simplicity, we assume throughout our analysis that &#8984; 1; this is to avoid &#8984; + 1 terms throughout our running times.</p></note>
			<note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="3" xml:id="foot_2"><p>Such a topological ordering is also referred to as a weak topological ordering<ref type="bibr">(Bender et al., 2015)</ref> as it does not require a total ordering on the vertices.</p></note>
			<note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="4" xml:id="foot_3"><p>Note that the algorithm also works if we instead receive a prediction of the number of ancestor vertices of v. However, this increases the running time to O(m&#8984; m n ).</p></note>
			<note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="5" xml:id="foot_4"><p>https://snap.stanford.edu/data/email-Eu-core-temporal.html</p></note>
			<note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="6" xml:id="foot_5"><p>In a normal distribution, &#8673; 61% of items are more than half a standard deviation from the mean.</p></note>
			<note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="7" xml:id="foot_6"><p>In fact,<ref type="bibr">(Bhattacharya &amp; Kulkarni, 2020</ref>) also need a stronger analysis, simpler to that presented here, since they only maintain the descendants of sampled vertices.</p></note>
			<note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="8" xml:id="foot_7"><p>https://snap.stanford.edu/data/email-Eu-core-temporal.html</p></note>
			<note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="9" xml:id="foot_8"><p>https://snap.stanford.edu/data/CollegeMsg.html</p></note>
		</body>
		</text>
</TEI>
