A dynamic algorithm for topologically sorting directed acyclic graphs David J. Pearce and Paul H.J. Kelly Imperial College, London, UK

Slides:



Advertisements
Similar presentations
Single Source Shortest Paths
Advertisements

Lecture 7 March 1, 11 discuss HW 2, Problem 3
Efficient Field-Sensitive Pointer Analysis for C David J. Pearce, Paul H.J. Kelly and Chris Hankin Imperial College, London, UK
Greedy Algorithms Greed is good. (Some of the time)
GRAIL: Scalable Reachability Index for Large Graphs VLDB2010 Vineet Chaoji Mohammed J. Zaki.
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Online Topological Ordering Siddhartha Sen, COS /20/2007.
Theory of Computing Lecture 6 MAS 714 Hartmut Klauck.
ICCV 2007 tutorial Part III Message-passing algorithms for energy minimization Vladimir Kolmogorov University College London.
A Batch Algorithm for Maintaining a Topological Order David J. Pearce and Paul H.J. Kelly Victoria University of Wellington, New Zealand & Imperial College,
1 Chapter 22: Elementary Graph Algorithms IV. 2 About this lecture Review of Strongly Connected Components (SCC) in a directed graph Finding all SCC (i.e.,
Graphs – Depth First Search ORD DFW SFO LAX
Chapter 5 Decrease and Conquer. Homework 7 hw7 (due 3/17) hw7 (due 3/17) –page 127 question 5 –page 132 questions 5 and 6 –page 137 questions 5 and 6.
Applications of graph traversals
16a-Graphs-More (More) Graphs Fonts: MTExtra:  (comment) Symbol:  Wingdings: Fonts: MTExtra:  (comment) Symbol:  Wingdings:
Lectures on Network Flows
The Ant and The Grasshopper Fast and Accurate Pointer Analysis for Millions of Lines of Code Ben Hardekopf and Calvin Lin PLDI 2007 (Best Paper & Best.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Makeup Lecture Chapter 23: Graph Algorithms Depth-First SearchBreadth-First.
Testing for Connectedness and Cycles
Shortest Path Problems
1 Data Structures DFS, Topological Sort Dana Shapira.
Lecture 10 Topics Application of DFS Topological Sort
Incremental topological ordering with Bernhard Haeupler, Sid Sen Two problems on digraphs: Cycle detection Topological ordering: a total order O such that.
CSE 780 Algorithms Advanced Algorithms Graph Alg. DFS Topological sort.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
An almost linear fully dynamic reachability algorithm.
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Applications of Depth-First Search
מבנה המחשב – מבוא למחשבים ספרתיים Foundations of Combinational Circuits תרגול מספר 3.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.
 Last lesson  Graphs  Today  Graphs (Implementation, Traversal)
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
Testing for Connectedness & Cycles Connectedness of an Undirected Graph Implementation of Connectedness detection Algorithm. Implementation of Strong Connectedness.
Testing for Connectedness and Cycles Connectedness of an Undirected Graph Implementation of Connectedness detection Algorithm. Implementation of Strong.
Review of Graphs A graph is composed of edges E and vertices V that link the nodes together. A graph G is often denoted G=(V,E) where V is the set of vertices.
COSC 3101NJ. Elder Assignment 2 Remarking Assignment 2 Marks y = 0.995x R 2 = Old Mark New Mark.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
MA/CSSE 473 Day 12 Insertion Sort quick review DFS, BFS Topological Sort.
Discussion #32 1/13 Discussion #32 Properties and Applications of Depth-First Search Trees.
Graphs.
Lecture 13 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Union-find Algorithm Presented by Michael Cassarino.
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Jan Topological Order and SCC Edge classification Topological order Recognition of strongly connected components.
Topological Sort (an application of DFS) CSC263 Tutorial 9.
1 Chapter 22 Elementary Graph Algorithms. 2 Introduction G=(V, E) –V = vertex set –E = edge set Graph representation –Adjacency list –Adjacency matrix.
Chapter 22: Elementary Graph Algorithms
Properties and Applications of Depth-First Search Trees and Forests
Adversarial Search 2 (Game Playing)
Sorting Algorithms Written by J.J. Shepherd. Sorting Review For each one of these sorting problems we are assuming ascending order so smallest to largest.
 2004 SDU 1 Lecture5-Strongly Connected Components.
MA/CSSE 473 Day 14 Strassen's Algorithm: Matrix Multiplication Decrease and Conquer DFS.
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
Chapter 22: Elementary Graph Algorithms Overview: Definition of a graph Representation of graphs adjacency list matrix Elementary search algorithms breadth-first.
Graph Algorithms – 2. graphs Parenthesis Theorem Theorem 22.7 For all u, v, exactly one of the following holds: 1. d[u] < f [u] < d[v] < f [v] or.
Online Cycle Detection and Difference Propagation for Pointer Analysis David J. Pearce, Paul H.J. Kelly and Chris Hankin Imperial College, London
Tirgul 12 Solving T4 Q. 3,4 Rehearsal about MST and Union-Find
Data Structures and Algorithm Analysis Lecture 5
Breadth-First Search (BFS)
Main algorithm with recursion: We’ll have a function DFS that initializes, and then calls DFS-Visit, which is a recursive function and does the depth first.
Introduction to Algorithms
Dynamic Coverage In Wireless Ed-Hoc Sensor Networks
Topological Sort (an application of DFS)
SINGLE-SOURCE SHORTEST PATHS
Lectures on Graph Algorithms: searching, testing and sorting
Algorithms and Data Structures Lecture XIII
Topological Sort (an application of DFS)
Presentation transcript:

A dynamic algorithm for topologically sorting directed acyclic graphs David J. Pearce and Paul H.J. Kelly Imperial College, London, UK

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

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

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

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

 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

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]

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

 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

 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

 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

 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

 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???

 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 }

Experimental Study – Part I  Experiment >Measure cost per insertion over 5000 insertions into random DAG >Invalidating and non-invalidating included to reflect actual performance

Experimental Study – Part II  Experiment >Measure cost per insertion over 5000 insertions into random DAG >Invalidating and non-invalidating included to reflect actual performance

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

References  [MNR96] – A. Marchetti-Spaccamela, U. Nanni and H. Rohnert, “Maintaining a topological order under edge insertions”. Information Processing Letters,  [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,  [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,  [Pea04] – D. J. Pearce, “Some directed graph algorithms and their application to pointer analysis”, PhD Thesis, Imperial College.

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 ?