1 / 23

Incremental topological ordering with Bernhard Haeupler, Sid Sen

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 ). Incremental topological ordering.

baker-york
Download Presentation

Incremental topological ordering with Bernhard Haeupler, Sid Sen

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. Incremental topological orderingwith 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) 3 5 1 2 4

  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. move c after f a, b, c, d, e, f, g, h 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)

  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 v w 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(m2)) • 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? v w ? 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. v w z  U x v w z x

  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  k2/4 new related arc pairs (out of ) k ≤ m1/2  O(m1/2) time per arc addition k > m1/2  (km1/2)/4 new pairs  k = O(m3/2)  O(m1/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{m3/2 logn, m3/2 + n2 logn}) • Liu, Chao 2007 O(m3/2 + mn1/2 logn) • Kavitha, Mathew 2007 O(m3/2 + nm1/2 logn) • Improvable, but… All bounds for m arc additions

  15. Avoid heaps? • Can we eliminate the heap altogether? Get O(m1/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(m1/2) amortized time per arc addition

  17. forward vertex unreached vertex scanned vertex backward vertex (v,w) a w b c d e v f l,s l s h A = {w}, B = {}, D = {}, C = {v}

  18. forward vertex unreached vertex scanned vertex backward vertex a w b c d e v f l s s l,s l h A = {}, B = {b,d}, D = {}, C = {c,e}

  19. forward vertex unreached vertex scanned vertex backward vertex a w b c d e v f l s s h,s h h A = {}, B = {d}, D = {c}, C = {}

  20. forward vertex unreached vertex scanned vertex backward vertex a w b c d e v f s l s h A = {}, B = {}, D = {c}, C = {} Set s = h and we are done

  21. forward vertex unreached vertex scanned vertex backward vertex a w b c s e v f X Y

  22. forward vertex unreached vertex scanned vertex backward vertex a c e v w b s f

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

More Related