Download presentation
Presentation is loading. Please wait.
Published byEthelbert Ramsey Modified over 9 years ago
1
A dynamic algorithm for topologically sorting directed acyclic graphs David J. Pearce and Paul H.J. Kelly Imperial College, London, UK d.pearce@doc.ic.ac.uk www.doc.ic.ac.uk/~djp1/
2
S Introduction Topologically sorting a directed acyclic graph G=(V,E) Sort nodes so X before Y, if X Y E Well-known algorithms taking (v + e) time > E.g. using depth-first search Y U X T W S Z TVWZYUX V
3
S Introduction Topologically sorting a directed acyclic graph G=(V,E) Sort nodes so X before Y, if X Y E Well-known algorithms taking (v + e) time > E.g. using depth-first search Y U X T W S Z TVWZYUX V
4
S How to update topological sort after edge insertion? Problem Definition Y U X T W S Z TVWZYUX V Invalidating or non-invalidating? >Adding Y V does not invalidate sort, but X Y does How to deal with invalidating edge insertions? >Re-sorting entire graph takes (v+e) time again
5
S How to update topological sort after edge insertion? Problem Definition Y U X T W S Z TVWZYUX V Invalidating or non-invalidating? >Adding Y V does not invalidate sort, but X Y does How to deal with invalidating edge insertions? >Re-sorting entire graph takes (v+e) time again
6
How to update topological sort after edge insertion? Problem Definition Y U X T W S Z TVWZYUXS V Invalidating or non-invalidating? >Adding Y V does not invalidate sort, but X Y does How to deal with invalidating edge insertions? >Re-sorting entire graph takes (v+e) time again
7
Performing less work How to avoid re-sorting entire graph after edge insertion? Affected region Y U X T W S Z TVWZ V USYX Affected region is all nodes between Y and X >We denote this set as AR XY Only AR XY needs reordering to obtain valid sort >Can eliminate many nodes from consideration >Proof by Marchetti-Spaccamela et al. [MNR96]
8
SU How to re-sort affected region? Performing less work (continued) Could just move Y to right of X! > But, V now incorrectly prioritised with respect to Y > Problem, cannot move Y past nodes it reaches in affected region Y U X T W S Z TVWZYX V SUTVWZYX Before After
9
Algorithm MNR due to Marchetti-Spaccamela et al. [MNR96] Algorithm MNR SU Y U X T W S Z TVWZYX V SUTVWZYX Before After Depth-First Search from Y identifies reachable set > Only visits those in affected region Shift other nodes to the left > Every node in affected region moved – so at least O(AR XY ) time
10
Algorithm PK - main contribution of this work Algorithm PK SU Y U X T W S Z TVWZYX V SUTVZY Before After Key insight: can avoid resorting entire affected region > {Z,T} remain untouched, saving work compared with MNR > Only set xy AR XY needs re-sorting (i.e. nodes in grey) WX
11
Define XY = R F R B Algorithm PK – what is XY ? SU Y U X T W S Z TVWZYX V Observation : nodes in R B must come before those in R F > R B = all nodes reaching X (including X) > R F = all nodes reachable from Y (including Y) VWYX RBRB RFRF
12
Begins with two Depth-First Searches to identify R F and R B Algorithm PK – How does it work? SU Y U X T W S Z TVWZYX V Before Use forward and backward Depth-First Search Forward search to determine R F (same as MNR) Backward search to determine R B Forward DFS Backward DFS
13
Next, re-sort members of XY Algorithm PK – how does it work? Y U X T W S Z V Place R B and R F into slots previously held by R B R F > R B goes into leftmost slots, R F into rightmost slots VWYX RBRB RFRF SUT?Z???
14
PK needs at most ~O( XY + E( XY )) per edge insertion > In contrast, MNR needs O(AR XY + E( XY )) time > Thus, PK should win when XY much smaller than AR XY Algorithm AHRSZ due to Alpern et al. [AHRSZ90] > Worst-case time complexity ~O(K min + E(K min )) > Where parameter K min XY is the minimal cover > So, tighter bound than algorithm PK – but is it practical? - Employs Dietz and Sleator ordered list structure [DS87] - Permits new priorities values to be created in O(1) time - But, this complex to implement and has relatively high overheads Algorithm PK – Complexity ? Definition : E(K) = { X Y E | X K Y K }
15
Experimental Study – Part I Experiment >Measure cost per insertion over 5000 insertions into random DAG >Invalidating and non-invalidating included to reflect actual performance
16
Experimental Study – Part II Experiment >Measure cost per insertion over 5000 insertions into random DAG >Invalidating and non-invalidating included to reflect actual performance
17
Conclusion Algorithm PK >Theoretical complexity marginally inferior to AHRSZ algorithm >But, simplicity of PK yields more efficient algorithm in practice Algorithm MNR >Worst theoretical complexity overall >However, outperforms the others on dense graphs Other Work … >Extended algorithms to incremental strongly connected components problem – see [PKH03a,Pea04] >Developed batch variant of MNR – see [Pea04] -Obtains O(b + v + e) bound on time to insert batch of b edges -In contrast, MNR/PK/AHRSZ need O(b(v+e)) worst-case time
18
References [MNR96] – A. Marchetti-Spaccamela, U. Nanni and H. Rohnert, “Maintaining a topological order under edge insertions”. Information Processing Letters, 1996. [AHRSZ90] - B. Alpern, R. Hoover, B.K. Rosen, P.F. Sweeny and F.K. Zadec, “Incremental evaluation of computational circuits”, In Proc. ACM Symposium on Discrete Algorithms, 1990. [PKH03a] – D. J. Pearce, P. H.J. Kelly and Chris Hankin, “Online Cycle Detection and Difference Propagation for Pointer Analysis”, In Proc. IEEE Workshop on Source Code Analysis and Manipulation, 2003. [Pea04] – D. J. Pearce, “Some directed graph algorithms and their application to pointer analysis”, PhD Thesis, Imperial College. www.doc.ic.ac.uk/~djp1, d.pearce@doc.ic.ac.uk
19
Q) Is XY minimal ? Y U X W The answer is no. For example: XWUY YXUW Key point : U not repositioned > But, under PK it would be since U XY (because it reaches X) > Scope for an even better algorithm ?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.