Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Dynamic graph connectivity Holm, Lichtenberg, Thorup (98) (based on Henzinger & King (95))

Similar presentations


Presentation on theme: "1 Dynamic graph connectivity Holm, Lichtenberg, Thorup (98) (based on Henzinger & King (95))"— Presentation transcript:

1 1 Dynamic graph connectivity Holm, Lichtenberg, Thorup (98) (based on Henzinger & King (95))

2 2 connected(v,w)

3 3

4 4

5 5 insert(v,w)

6 6

7 7 delete(v,w)

8 8

9 9

10 10 delete(v,w)

11 11 Without delete a Union-Find data structure would do Lets reduce the problem to a problem on trees Observations

12 12 We maintain a spanning forest of the graph We will have to link trees, cut trees, and determine whether two vertices are in the same tree

13 13 Operations we need to do on the forest link(v,w) : assume v and w are in different trees cut(v,w) : assume v and w are adjacent in a tree findtree(v)

14 14 But even if we know how to do that we still have a problem deleting a tree edge

15 15

16 16

17 17 How do we find out if there is a “replacement” edges for the forest or it really got disconnected ?

18 18 We will traverse one of the trees but we need to accumulate information as we do that

19 19 Each edge has a level 1 1 1 Increase the level of the edges of the smaller tree 1 1 1 1

20 20 Each edge has a level 1 1 1 Increase the level of the edges of the smaller tree 1 1 1 1 and of any edge discovered not to be a “replacement” 1 1

21 21 1 1 1 1 1 1 1 1 1

22 22 1 1 1 1 1 1 1 1 1

23 23 1 1 1 1 1 1 1 1 1

24 24 1 1 1 1 1 1 1 1 1 1 No need to look at non tree edges with label 1

25 25 1 1 1 1 1 1 1 1 1 1

26 26 1 1 1 1 1 1 1 1 1 1

27 27 1 1 1 1 1 1 1 1 1 1

28 28 1 1 1 1 1 1 1 1 1

29 29 2 2 1 1 1 1 1 1 1

30 30 2 2 1 1 1 1 1 2 1

31 31 2 2 1 1 1 1 1 2 1

32 32 2 2 1 1 1 1 1 2 1

33 33 What is going on exactly ? The forest is a maximum spanning forest with respect to the levels of the edges  If we delete an edge at level ℓ then a replacement edge is of level ≤ ℓ Let F i be the subforest of edges of level ≥ i, then each tree in F i is of size no larger than n/2 i  No more than log n levels Invariants

34 34 Suppose we delete a tree edge of level ℓ. Then it belongs to some tree T of F ℓ If there is a replacement at level ℓ then it is incident to one of the pieces of T ≥ ℓ v w Let T v and T w be the pieces of T in F ℓ containing v and w respectively after deleting (v,w) Assume | T v | ≤ | T w | then we increase the level of edges of level ℓ in T v to be ℓ+1 ≥ ℓ = ℓ

35 35 ℓ > ℓ ≥ ℓ v w ℓ ℓ

36 36 ℓ+1 > ℓ ≥ ℓ v w ℓ ℓ

37 37 Then we traverse all level ℓ non-tree edges incident to T v to find a level-ℓ replacement edge. ℓ+1 > ℓ ≥ ℓ v w If a traversed edge is not a replacement we increase its level to ℓ+1 ℓ ℓ

38 38 Then we traverse all level ℓ non-tree edges incident to T v to find a level-ℓ replacement edge. ℓ+1 > ℓ ≥ ℓ v w If a traversed edge is not a replacement we increase its level to ℓ+1 ℓ+1 ℓ

39 39 Then we traverse all level ℓ non-tree edges incident to T v to find a level-ℓ replacement edge. ℓ+1 > ℓ ≥ ℓ v w If a traversed edge is not a replacement we increase its level to ℓ+1 ℓ+1 ℓ

40 40 If there is no replacement edge of level ℓ we look for replacement edges of level ℓ - 1 ℓ+1 > ℓ ≥ ℓ v w ℓ+1 ℓ -1 Let T v and T w be the trees in F ℓ-1 after deleting (v w) containing v and w respectively Assume | T v | ≤ | T w | then we increase the level of edges of level ℓ-1 in T v to be ℓ and we start traversing the non-tree edges of level ℓ-1 incident to T v ℓ -1 ℓ

41 41 We keep going down like that level by level and either we find a replacement edge or we conclude that none exists As we go we keep our invariants

42 42 Why do we keep the second invariant ? v w TFℓTFℓ F ℓ+1 = ℓ F ℓ+1 = ℓ |T| ≤ n/2 ℓ  |T v | ≤ n/2 ℓ+1 The replacement edge stays at level ℓ

43 43 Precise implementation We keep each forest F 0  F 1  F 2  separately The non-tree edges of level ℓ are kept with the nodes of F ℓ

44 44 Complete definition of the operations insert(v,w) : If v and w are in different trees of F 0 add the edge to F 0 (At level 0). Otherwise just add a non-tree edge of level 0 to v and w. connected(v,w) : Check if v and w are in the same tree of F 0 Delete(v,w): Let ℓ be the level of (v,w). If (v,w) is a non-tree edge of level ℓ then simply delete it from v and w in F ℓ. Otherwise delete it from the trees containing it in F ℓ, F ℓ-1, …, F 0 and find a replacement edge as we described. If a replacement edge is found at level k ≤ ℓ then add it to F k, F k-1, …, F 0

45 45 Operations we need to do on the forests link(v,w) : assume v and w are in different trees cut(v,w) : assume v and w are adjacent in a tree findtree(v) Find an edge of level ℓ in T  F ℓ Find a non-tree edge of level ℓ incident with T  F ℓ Add/delete a non-tree edge of level ℓ incident with some v  T  F ℓ Suppose we can do it in O(log n) time per operation

46 46 Analysis Insert takes O(log n) time + the time to increase the level of the edge. Each increase costs O(log n) so it O(log 2 n) total. Query takes O(log n) Delete takes O(log 2 n)


Download ppt "1 Dynamic graph connectivity Holm, Lichtenberg, Thorup (98) (based on Henzinger & King (95))"

Similar presentations


Ads by Google