Presentation is loading. Please wait.

Presentation is loading. Please wait.

Incremental topological ordering with Bernhard Haeupler, Sid Sen Two problems on digraphs: Cycle detection Topological ordering: a total order O such that.

Similar presentations


Presentation on theme: "Incremental topological ordering with Bernhard Haeupler, Sid Sen Two problems on digraphs: Cycle detection Topological ordering: a total order O such that."— Presentation transcript:

1 Incremental topological ordering with Bernhard Haeupler, Sid Sen Two problems on digraphs: Cycle detection Topological ordering: a total order O such that v  w  O(v) < O(w)

2 Incremental topological ordering A digraph is acyclic if it has at least one topological ordering Static: O(n + m) time, n = # vertices, m = # arcs Assume m ≥ n (simplicity) 1 24 3 5

3 Dynamic: on-line, incremental Start with vertex set, no arcs Add one arc at a time Maintain a topological order Report a cycle as soon as one is created

4 How to maintain ordering? 1-1 mapping: V  {1,2,…,n} via 1 or 2 arrays (inverse?) Dynamic ordered list query: v < w ? update:delete v insert v (before or after) w O(1) time per operation (Dietz, Sleator 1987; Bender, Cole, Demaine, Farach-Colton, Zito 2002) a, b, c, d, e, f, g, h move c after f

5 Adding an arc Given an existing order, how to handle a new arc v  w? If v < w: do nothing If w < v: search for a cycle or a set of vertices to reorder to restore topological order Affected region: all vertices x : w ≤ x ≤ v

6 Adding an arc Search forward from w, but not from vertices > v Vertex states during search: U = unlabeled L = labeled, initially {w} S = scanned w v x

7 Adding an arc scan(x): for x  y if y = v stop (cycle) if y < v and y  U add y to L while L ≠ Ø: delete some x from L, scan(x), add x to S reorder: move S after v (in order)

8 Adding an arc Running time? Count related pairs: some paths contain more than one type vertex, vertex pairs – arc, vertex pairs – nm arc, arc pairs – One-way search: x  y traversed  v, x  y newly related  O(m) amortized time per arc addition; O(nm) total (vs. O(m 2 )) Marchetti-Spaccamela, Nanni, Rohnert 1996

9 Two-way (bidirectional) search Forward from w, backward from v concurrently When to stop searching? When to pay for a search step? w v w v ? ?

10 Two-way (bidirectional) search Stop when  x with: no forward labeled vertices < x no backward labeled vertices > x Reorder: Move forward scanned vertices (≠ x) after x Move backward scanned vertices (≠ x) before x

11 w v x z  U vw x z

12 How to pay? Traverse arcs in pairs: x  y forward, z  u backward allowed if x < u Adding v  w relates x  y, z  u (unless cycle) Search time = O(1) per arc traversal + overhead k traversal steps  k 2 /4 new related arc pairs (out of ) k ≤ m 1/2  O(m 1/2 ) time per arc addition k > m 1/2  (km 1/2 )/4 new pairs   k = O(m 3/2 )  O(m 1/2 ) amortized per arc addition

13 How to implement? Ordered search: Scan smallest forward labeled vertex or largest backward labeled vertex Stop when next forward vertex > next backward vertex  All forward traversed arcs form pairs with all backward traversed arcs But: need a heap (priority queue) for: F = forward labeled vertices R = backward labeled vertices Logarithmic (?) overhead

14 History of two-way search method Idea: Alpern, Hoover, Rosen, Sweeney, Zadeck 1990 Incremental bound (per arc addition) Katriel, Bodlaender 2005 O(min{m 3/2 logn, m 3/2 + n 2 logn}) Liu, Chao 2007 O(m 3/2 + mn 1/2 logn) Kavitha, Mathew 2007 O(m 3/2 + nm 1/2 logn) Improvable, but… All bounds for m arc additions

15 Avoid heaps? Can we eliminate the heap altogether? Get O(m 1/2 ) per arc amortized time? Balanced safe search Split:F = A ∪ B R = C ∪ D Choose x  A, u  C If x < u, traverse x  y, z  u If x > u, bypass x (move to B) or u (move to D) Which? What if A or C is empty? bypassed (temporarily)

16 Soft threshold Maintain a tentative threshold t, initially w or v If x > u, bypass x if x > t, u if u < t (if both, choose one) if A is empty, replace A by B, choose new t uniformly at random from A (or median) Similarly if C is empty  Amortized O(1) bypassed vertices per search step (expected or worst-case)  O(1) overhead per search step  O(m 1/2 ) amortized time per arc addition

17 forward vertex backward vertex vw unreached vertex l,sl,s h scanned vertex (v,w)(v,w) A = {w}, B = {}, D = {}, C = {v} abcdef sl

18 s vw l h s A = {}, B = {b,d}, D = {}, C = {c,e} abcdef forward vertex backward vertex unreached vertex scanned vertex l,sl,sl

19 vw h ls A = {}, B = {d}, D = {c}, C = {} abcdef forward vertex backward vertex unreached vertex scanned vertex h,s h s

20 vw h ls A = {}, B = {}, D = {c}, C = {} abcdef forward vertex backward vertex unreached vertex scanned vertex s

21 vws YX abcef forward vertex backward vertex unreached vertex scanned vertex

22 vwsafbce forward vertex backward vertex unreached vertex scanned vertex

23 Lower bounds  (n logn) vertex reorderings for any algorithm Ramalingam and Reps 1994  (n 2 ) vertex reorderings if order = 1-1 mapping reordering only within affected region  (nm) vertex reorderings if reordering only within affected region Dense case O(n 2.75 ) Ajwani, Friedrich, Meyer 2006 Õ(n 2.5 ) Liu, Chao 2007 O(n 2.5 ) Kavitha, Mathew 2007


Download ppt "Incremental topological ordering with Bernhard Haeupler, Sid Sen Two problems on digraphs: Cycle detection Topological ordering: a total order O such that."

Similar presentations


Ads by Google