Incremental topological ordering with Bernhard Haeupler, Sid Sen

23
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)

description

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. - PowerPoint PPT Presentation

Transcript of Incremental topological ordering with Bernhard Haeupler, Sid Sen

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)

Incremental topological ordering

• A digraph is acyclic if it has at least one topological ordering

• Static: O(n + m) time, n = # vertices, m = # arcsAssume m ≥ n (simplicity)

1

2 4

3

5

Dynamic: on-line, incremental

• Start with vertex set, no arcs• Add one arc at a time

Maintain a topological orderReport a cycle as soon as one is created

How to maintain ordering?

• 1-1 mapping: V {1,2,…,n}via 1 or 2 arrays (inverse?)

• Dynamic ordered listquery: 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

Adding an arc

• Given an existing order, how to handle a new arc v w?

If v < w: do nothingIf 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

Adding an arc

• Search forward from w, but not from vertices > v

• Vertex states during search:U = unlabeledL = labeled, initially {w}S = scanned

w v

x

Adding an arc

• scan(x):for x yif 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)

Adding an arc

• Running time?Count related pairs: some paths contain more than one type

vertex, vertex pairs – arc, vertex pairs – nmarc, 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

2

n

2

m

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

?

?

Two-way (bidirectional) search

• Stop when x with:no forward labeled vertices < xno backward labeled vertices > x

• Reorder:Move forward scanned vertices (≠ x) after xMove backward scanned vertices (≠ x) before x

w v

xz U

v w

xz

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 additionk > m1/2 (km1/2)/4 new pairs

k = O(m3/2) O(m1/2) amortized per arc addition

2

m

How to implement?• Ordered search:

Scan smallest forward labeled vertex or largest backward labeled vertexStop 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 verticesR = backward labeled vertices

• Logarithmic (?) overhead

History of two-way search method• Idea: Alpern, Hoover, Rosen, Sweeney, Zadeck

1990Incremental bound (per arc addition)

• Katriel, Bodlaender 2005O(min{m3/2 logn, m3/2 + n2 logn})

• Liu, Chao 2007O(m3/2 + mn1/2 logn)

• Kavitha, Mathew 2007O(m3/2 + nm1/2 logn)

• Improvable, but…

All bounds for m arc additions

Avoid heaps?

• Can we eliminate the heap altogether?Get O(m1/2) per arc amortized time?

• Balanced safe searchSplit: F = A ∪ B

R = C ∪ DChoose x A, u CIf x < u, traverse x y, z uIf x > u, bypass x (move to B) or u (move to D)

• Which? What if A or C is empty?

bypassed (temporarily)

Soft threshold

• Maintain a tentative threshold t, initially w or vIf 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

forward vertex

backward vertex

vw

unreached vertex

l,s h

scanned vertex

(v,w)

A = {w}, B = {}, D = {}, C = {v}

a b c d e f

sl

s

vw

l hs

A = {}, B = {b,d}, D = {}, C = {c,e}

a b c d e f

forward vertex

backward vertex

unreached vertex

scanned vertex

l,sl

vw

hl s

A = {}, B = {d}, D = {c}, C = {}

a b c d e f

forward vertex

backward vertex

unreached vertex

scanned vertex

h,shs

vw

hl s

A = {}, B = {}, D = {c}, C = {}

a b c d e f

forward vertex

backward vertex

unreached vertex

scanned vertex

s

vw s

YX

a b c e f

forward vertex

backward vertex

unreached vertex

scanned vertex

v w sa fbc e

forward vertex

backward vertex

unreached vertex

scanned vertex

• Lower bounds(n logn) vertex reorderings for any algorithm

Ramalingam and Reps 1994(n2) vertex reorderings if

order = 1-1 mappingreordering only within affected region

(nm) vertex reorderings ifreordering only within affected region

• Dense caseO(n2.75) Ajwani, Friedrich, Meyer 2006Õ(n2.5) Liu, Chao 2007O(n2.5) Kavitha, Mathew 2007