1 minimum spanning trees ghs algorithm. 2 weighted graph

71
1 Minimum Spanning Trees GHS Algorithm

Upload: colin-shaw

Post on 17-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

1

Minimum Spanning Trees

GHS Algorithm

2

Weighted Graph

1

92

14

8

6

310 115

7

164

15

13

12

6)( ew

17

3

1

92

14

8

6

310 115

4

15

13

12

Minimum weight spanning tree

The sum of the weights is minimized

17

(MST)

For MST :T

Te

ewTw )()( is minimized

18

7

16

4

Spanning tree fragment:

Any sub-tree of a MST

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

5

Minimum weight outgoing edge(MWOE)

The adjacent edge to the fragment with the smallest weight that does not create a cycle

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

6

Property 1:The union of a fragment and the MWOE is a fragment

Property 2:If the weights are uniquethen the MST is unique

Two important properties for building MST

7

Property 1:The union of a fragment and the MWOE is a fragment

Proof: Basic idea

Examine if the new fragmentis part of a MST

8

e)()( xwew

MWOE

Fragment

Spanning tree

If then is fragment

F

T

Te }{eF

9

eMWOE

Fragment

Spanning tree

If then is fragment

}{eFF

T

Te }{eF

10

ex )()( xwew

MWOE

Fragment

F

TSpanning tree

If Te then add to e Tand delete x

11

ex )()( xwew

MWOE

Fragment

F

TSpanning tree

If Te then add to e Tand delete x

12

ex )()( xwew

MWOE

Fragment

F

T Spanning tree

)()( TwTw Since otherwise,Twouldn’t be MST

13

e)()( xwew

MWOE

Fragment

Spanning tree

thus is fragment

}{eFF

T

}{eF END OF PROOF

14

Property 2:If the weights are uniquethen the MST is unique

Proof: Basic Idea:

Suppose there are two MST

Then there is another MST of smaller weight

Contradiction!

15

Suppose there are two MST

16

Take the smallest weight edge not in intersection

e

17

e

Cycle in RED MST

18

e

Cycle in RED MST

e

Not in BLUE MST

(since blue tree is acyclic)

)()( ewew

19

e

Cycle in RED MST

e

)()( ewew Since is not in intersection,e

(the weight of is the smallest)e

20

e

Cycle in RED MST

e

)()( ewew

Delete and add in RED MST e e

We obtain a new tree with smaller weight

Contradiction! END OF PROOF

21

Prim’s Algorithm

Start with a node as an initial fragment

Augment fragment with the MWOE

Repeat

F

F

Until no other edge can be added to F

(Assume unique IDs)

22

1

92

14

8

6

310 115

4

15

13

12

Fragment F

17

18

7

16

23

1

92

14

8

6

310 115

4

15

13

12

Fragment F

MWOE

17

18

7

16

24

1

92

14

8

6

310 115

4

15

13

12

Fragment F

MWOE

18

7

16

25

1

92

14

8

6

310 115

4

15

13

12

Fragment F

17

MWOE

18

7

16

26

Fragment F

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

27

Theorem: Prim’s algorithm gives an MST

Proof: Use Property 1 repeatedly

END OF PROOF

28

Kruskal’s Algorithm

Initially, each node is a fragment

Find the smallest MWOE of all fragments

Merge the two fragments adjacent to

e

e

Repeat

Until there is one fragment

(Assume unique IDs)

29

1

92

14

8

6

310 115

4

15

13

12

17

Initially, every node is a fragment

18

7

16

30

1

92

14

8

6

310 115

4

15

13

12

17

Find the smallest MWOE

18

7

16

31

1

92

14

8

6

310 115

4

15

13

12

17

Merge the two fragments

18

7

16

32

1

92

14

8

6

310 115

4

15

13

12

17

Find the smallest MWOE

18

7

16

33

1

92

14

8

6

310 115

4

15

13

12

17

Merge the two fragments

18

7

16

34

Resulting MST

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

35

Theorem: Kruskal’s algorithm gives an MST

Proof: Use Properties 1 and 2 repeatedly

END OF PROOF

Property 2 guarantees that the merged trees are fragments

36

GHS Algorithm

Distributed version of Kruskal’s Algorithm

Initially, each node is a fragment

Each fragment finds its MWOE

Merge fragments adjacent to MWOE’s

Repeat in parallel:

Until there is one fragment

(A Synchronous Phase)

37

Phase 0: Initially, every node is a fragment

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

Every node is a root of a fragment

38

1

92

14

8

6

310 115

4

15

13

12

17

Phase 1: Find the MWOE for each fragment

18

7

16

39

1

92

14

8

6

310 115

4

15

13

12

17

Phase 1: Merge the fragments

18

Root

RootRoot

Root

Asymmetric MWOE

symmetric MWOE

The new root is adjacent to a symmetric MWOE

40

1

92

14

8

6

310 115

4

15

13

12

17

Phase 1: New fragments

18

41

1

92

14

8

6

310 115

4

15

13

12

17

18

Phase 2: Find the MWOE for each fragment

7

16

42

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

Phase 2: Merge the fragments

Root

Root

43

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

Phase 2: New fragments

44

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

Phase 3: Find the MWOE for each fragment

45

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

Phase 3: Merge the fragments

Root

46

Phase 3: New fragment

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

FINAL MST

47

Rules for selecting a Root in fragment

Fragment 1Fragment 2

root

rootMWOE

48

Merged Fragment

root

Higher ID Node on MWOE

Rules for selecting a Root in fragment

49

Rules for selecting a Root in fragment

Merging more than 2 fragments

1F2F

3F

5F

4F 6F

7Frootroot

root

root

root root

root

50

Rules for selecting a Root in fragment

Higher ID Node on symmetric MWOE

Merged Fragment

Root

asymmetric

51

In merged fragments there is exactly one symmetric MWOE

Remark:

Impossible Impossible

1F2F

4F3F

5F

6F

Creates a fragment with two MWOE

zero two

Creates a fragmentwith no MWOE

1F2F

4F3F

5F

6F

7F

8F

52

The new root broadcasts to the new fragment

e

)(ew

e is the symmetric MWOE of the merged fragments

)(ew

)(ew)(ew

)(ew )(ew)(ew

)(ew

)(ew is the identity of the new fragment

)(ew

)(ew

)(ew )(ew

)(ew)(ew)(ew

)(ew

53

At the end of a phase each fragmenthas its own unique identity.

1

92

14

8

6

310 115

4

15

13

12

17

18

Root Root

Root

Root

4

End of phase 1

5

1

2

7

16

4

4

1 1

2

2

2

2

2

5

5

54

At the end of a phase each fragmenthas its own unique identity.

End of phase 2

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16 Root

Root7

97 77

79

9

9 9

9

9

9

55

At the beginning of each phase each node in fragment finds its MWOE

MWOEMWOE

MWOE

MWOE

10

3

15

4

7

25

35 19 22

12

56

Then each node reports its MWOEto the fragment root with convergecast (the global minimum survives in propagation)

MWOEMWOE

MWOE

MWOE

10

3

15

4

7

25

35 19 22

12

193 22

73

103

3

57

The root selects the minimum MWOE

MWOE

10

3

15

4

7

25

35 19 22

12

3

58

10

15

3

To discover its own MWOE, each node broadcasts its identity to neighbors

59

10

15

3

Then it knows which edges are outgoing,And selects the MWOE among them

outgoing

outgoing

MWOE

60

Smallest Fragment size (#nodes)Phase

0 1

1 2

3 4

i i2

Complexity

61

Maximum phase: ni 2log

Maximum possible fragment size ni 2

Number ofnodes

62

Time to convergecast MWOE to root:

)(nO

)(nO

Time to connect new fragments: )1(O(Each fragment sends one message on its MWOE)

Time of root to broadcast identity:

Time of a phase:

(maximum fragment size is ))(nO

Total phase time: )(nO

63

Total time = Phase time X #phases =nlog)(nO

)log( nnO

Lower bound:

nn

log

Algorithm Time

64

Messages to broadcast identity:

Messages to convergecast to root:

)(nO

)(nO

Messages to connect new fragments: )(nO(Each fragment sends one message on its MWOE)

Messages in a phase:

(maximum fragment size is ))(nO

Total phase messages: |)|( EnO

Messages for nodes to find MWOE: |)(|EO(on each edge 2 messages)

65

Total messages = Phase messages X #phasesnlog|)|( EnO

)log|)|(( nEnO

Can be improved to

|)|log( EnnO

Algorithm messages

66

Asynchronous Version of GHS Algorithm

Simulates the synchronous version

Every fragment has a levelF )(FL

67

FragmentFragment

1F 2FMWOE

If then merges to )()( 21 FLFL 1F 2F

(cost of merging proportional to )1F

68

New fragment

1F 2FMWOE

)()( 21 FLFL

The combined level is )()( 2FLFL

69

MWOE

FragmentFragment

1F 2F

If then merges with )()( 21 FLFL 1F 2F

(cost of merging proportional to )1F

70

New fragment

1F 2FMWOE

The combined level is 1)()( 2 FLFL

)()( 21 FLFL

71

Fragment Fragment

1F 2FMWOE

If then waits until previousRules apply

)()( 21 FLFL 1F

(cost of merging would be proportional to for every small fragment, inefficient!!)

1F