1 / 20

A dynamic algorithm for topologically sorting directed acyclic graphs

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/. Introduction. Topologically sorting a directed acyclic graph G=(V,E). U. W. U. Y. Z. W. V. T. X. S.

garth-west
Download Presentation

A dynamic algorithm for topologically sorting directed acyclic graphs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. Introduction • Topologically sorting a directed acyclic graph G=(V,E) U W U Y Z W V T X S Z Y X T V • Sort nodes so X beforeY if XY E, x,yV • Well-known algorithms taking O(v + e) time • E.g. using depth-first search S

  3. Problem Definition • How to update topological sort after edge insertion? U W U Y Z W V T X S Z Y X T V • Invalidating or non-invalidating? • Adding YV does not invalidate sort, but XY does • How to deal with invalidating edges? • Re-sorting entire graph takes O(v+e) time again S

  4. Problem Definition • How to update topological sort after edge insertion? U W U Y Z W V T X S Z Y X T V • Invalidating or non-invalidating? • Adding YV does not invalidate sort, but XY does • How to deal with invalidating edges? • Re-sorting entire graph takes O(v+e) time again S

  5. Problem Definition • How to update topological sort after edge insertion? U W U Y Z W V T X S Z Y X T V • Invalidating or non-invalidating? • Adding YV does not invalidate sort, but XY does • How to deal with invalidating edges? • Re-sorting entire graph takes O(v+e) time again S

  6. Performing less work • How to avoid resorting entire graph? U W U Y Z W V T X S Z Y X Affected region T V Definition: affected region, ARxy, is set of nodes between X and Y for some edge insertion X  Y S Lemma: only affected region needs reordering to obtain valid sort Proof: by Marchetti-Spaccamela et al. [MNR96]

  7. Performing less work (continued) • How to re-sort affected region? U W U Y Z W V T X S Before Z Y X T V U Z W V T X Y S After S • 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

  8. Algorithm MNR • Algorithm MNR due to Marchetti-Spaccamela et al. [MNR96] U W U Y Z W V T X S Before Z Y X T V U Z W T X Y V S 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(ARXY) time S

  9. Algorithm PK • Algorithm PK - main contribution of this work U W U Y Z W V T X S Before Z Y X T V U W Z X Y T V S After S • Key insight: can avoid resorting entire affected region • Only set xy = {Y,W,V,X} needs resorting • {Z,T} remain untouched • This saves work compared with MNR

  10. Algorithm PK • Algorithm PK – how does it work? U W U Y Z W V T X S Z Y X W X Y V T V RB RF S • Observation: nodes in RB must come before those in RF • RB = all nodes reaching X (including X) • RF = all nodes reachable from Y (including Y)

  11. Algorithm PK • Algorithm PK – how does it work? U W U Y Z W V T X S Before Z Y X Forward DFS T V Backward DFS S • Use forward and backward Depth-First Search • Forward search to determine RF (same as MNR) • Backward search to determine RB

  12. Algorithm PK • Algorithm PK – how does it work? W X Y V U W RB RF Z Y X T V U ? Z ? ? T ? S S • Place RB and RF into slots previously held by RB RF • RB goes into leftmost slots, RF into rightmost slots • Thus, Z and T do not need repositioning

  13. Algorithm PK • Algorithm PK – how does it work? U Y Z W V T X S U W Z Y X W X Y V T V RB RF S U W Z X Y T V S

  14. Algorithm PK – Complexity ? Definition: Let XY = RF RB U W • Here, xy = {Y,V,W,X} Definition: E(K) = { XYE | XK  YK } Z Y X • e.g., E(XY) = { UX, UY, WX, XY, YV } T V Definition: Let ||K|| = |K| + E(K) Conclusion: complexity is ~O(||XY||) time S • MNR actually needs O(|ARXY| + ||XY||) time • Thus, PK has tighter bound than MNR

  15. Is XY minimal ? • The answer is no. For example: U W X Y U W X Y W U X Y • Key point: U not repositioned • But, under PK it would be since U XY • Scope for an even better algorithm ?

  16. Algorithm AHRSZ Definition: A set K is a cover if XK  YK, for every incorrectly ordered pair X,Y. A cover, Kmin, is minimal no smaller cover is possible. • Algorithm AHRSZ due to Alpern et al. [AHRSZ90] • Worst-case time complexity O(||Kmin||log ||Kmin||) • So, tighter bound than algorithm PK – but is it practical? • Issues with algorithm AHRSZ • Employs Deitz and Sleator ordered list structure [DS87] • Permits new priorities values to be created in O(1) time • But, is complex to implement and has relatively high overheads Lemma: For invalidating edge insertion XY it holds that KminXY

  17. Experimental Study • Experiment • Measure cost per insertion over 5000 edges insertions • Invalidating and non-invalidating included to reflect actual performance • Observations • MNR has linear performance in V, but optimal on dense graphs • AHRSZ similar behaviour to PK, but constant factor slower

  18. Conclusion • Stuff • Batch algorithm and Cycles • Links • Work of Irit

More Related