minimum spanning trees

71
1 Minimum Spanning Trees GHS Algorithm

Upload: olwen

Post on 15-Jan-2016

20 views

Category:

Documents


0 download

DESCRIPTION

Minimum Spanning Trees. GHS Algorithm. Weighted Graph. (MST). Minimum weight spanning tree. The sum of the weights is minimized. For MST :. is minimized. Spanning tree fragment:. Any sub-tree of a MST. Minimum weight outgoing edge. (MWOE). - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Minimum Spanning Trees

1

Minimum Spanning Trees

GHS Algorithm

Page 2: Minimum Spanning Trees

2

Weighted Graph

1

92

14

8

6

310 115

7

164

15

13

12

6)( ew

17

Page 3: Minimum Spanning Trees

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

Page 4: Minimum Spanning Trees

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

Page 5: Minimum Spanning Trees

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

Page 6: Minimum Spanning Trees

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

Page 7: Minimum Spanning Trees

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

Page 8: Minimum Spanning Trees

8

e)()( xwew

MWOE

Fragment

Spanning tree

If then is fragment

F

T

Te }{eF

Page 9: Minimum Spanning Trees

9

eMWOE

Fragment

Spanning tree

If then is fragment

}{eFF

T

Te }{eF

Page 10: Minimum Spanning Trees

10

ex )()( xwew

MWOE

Fragment

F

TSpanning tree

If Te then add to e Tand delete x

Page 11: Minimum Spanning Trees

11

ex )()( xwew

MWOE

Fragment

F

TSpanning tree

If Te then add to e Tand delete x

Page 12: Minimum Spanning Trees

12

ex )()( xwew

MWOE

Fragment

F

T Spanning tree

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

Page 13: Minimum Spanning Trees

13

e)()( xwew

MWOE

Fragment

Spanning tree

thus is fragment

}{eFF

T

}{eF END OF PROOF

Page 14: Minimum Spanning Trees

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!

Page 15: Minimum Spanning Trees

15

Suppose there are two MST

Page 16: Minimum Spanning Trees

16

Take the smallest weight edge not in intersection

e

Page 17: Minimum Spanning Trees

17

e

Cycle in RED MST

Page 18: Minimum Spanning Trees

18

e

Cycle in RED MST

e

Not in BLUE MST

(since blue tree is acyclic)

)()( ewew

Page 19: Minimum Spanning Trees

19

e

Cycle in RED MST

e

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

(the weight of is the smallest)e

Page 20: Minimum Spanning Trees

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

Page 21: Minimum Spanning Trees

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)

Page 22: Minimum Spanning Trees

22

1

92

14

8

6

310 115

4

15

13

12

Fragment F

17

18

7

16

Page 23: Minimum Spanning Trees

23

1

92

14

8

6

310 115

4

15

13

12

Fragment F

MWOE

17

18

7

16

Page 24: Minimum Spanning Trees

24

1

92

14

8

6

310 115

4

15

13

12

Fragment F

MWOE

18

7

16

Page 25: Minimum Spanning Trees

25

1

92

14

8

6

310 115

4

15

13

12

Fragment F

17

MWOE

18

7

16

Page 26: Minimum Spanning Trees

26

Fragment F

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

Page 27: Minimum Spanning Trees

27

Theorem: Prim’s algorithm gives an MST

Proof: Use Property 1 repeatedly

END OF PROOF

Page 28: Minimum Spanning Trees

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)

Page 29: Minimum Spanning Trees

29

1

92

14

8

6

310 115

4

15

13

12

17

Initially, every node is a fragment

18

7

16

Page 30: Minimum Spanning Trees

30

1

92

14

8

6

310 115

4

15

13

12

17

Find the smallest MWOE

18

7

16

Page 31: Minimum Spanning Trees

31

1

92

14

8

6

310 115

4

15

13

12

17

Merge the two fragments

18

7

16

Page 32: Minimum Spanning Trees

32

1

92

14

8

6

310 115

4

15

13

12

17

Find the smallest MWOE

18

7

16

Page 33: Minimum Spanning Trees

33

1

92

14

8

6

310 115

4

15

13

12

17

Merge the two fragments

18

7

16

Page 34: Minimum Spanning Trees

34

Resulting MST

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

Page 35: Minimum Spanning Trees

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

Page 36: Minimum Spanning Trees

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)

Page 37: Minimum Spanning Trees

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

Page 38: Minimum Spanning Trees

38

1

92

14

8

6

310 115

4

15

13

12

17

Phase 1: Find the MWOE for each fragment

18

7

16

Page 39: Minimum Spanning Trees

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

Page 40: Minimum Spanning Trees

40

1

92

14

8

6

310 115

4

15

13

12

17

Phase 1: New fragments

18

Page 41: Minimum Spanning Trees

41

1

92

14

8

6

310 115

4

15

13

12

17

18

Phase 2: Find the MWOE for each fragment

7

16

Page 42: Minimum Spanning Trees

42

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

Phase 2: Merge the fragments

Root

Root

Page 43: Minimum Spanning Trees

43

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

Phase 2: New fragments

Page 44: Minimum Spanning Trees

44

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

Phase 3: Find the MWOE for each fragment

Page 45: Minimum Spanning Trees

45

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

Phase 3: Merge the fragments

Root

Page 46: Minimum Spanning Trees

46

Phase 3: New fragment

1

92

14

8

6

310 115

4

15

13

12

17

18

7

16

FINAL MST

Page 47: Minimum Spanning Trees

47

Rules for selecting a Root in fragment

Fragment 1Fragment 2

root

rootMWOE

Page 48: Minimum Spanning Trees

48

Merged Fragment

root

Higher ID Node on MWOE

Rules for selecting a Root in fragment

Page 49: Minimum Spanning Trees

49

Rules for selecting a Root in fragment

Merging more than 2 fragments

1F2F

3F

5F

4F 6F

7Frootroot

root

root

root root

root

Page 50: Minimum Spanning Trees

50

Rules for selecting a Root in fragment

Higher ID Node on symmetric MWOE

Merged Fragment

Root

asymmetric

Page 51: Minimum Spanning Trees

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

Page 52: Minimum Spanning Trees

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

Page 53: Minimum Spanning Trees

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

Page 54: Minimum Spanning Trees

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

Page 55: Minimum Spanning Trees

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

Page 56: Minimum Spanning Trees

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

Page 57: Minimum Spanning Trees

57

The root selects the minimum MWOE

MWOE

10

3

15

4

7

25

35 19 22

12

3

Page 58: Minimum Spanning Trees

58

10

15

3

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

Page 59: Minimum Spanning Trees

59

10

15

3

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

outgoing

outgoing

MWOE

Page 60: Minimum Spanning Trees

60

Smallest Fragment size (#nodes)Phase

0 1

1 2

3 4

i i2

Complexity

Page 61: Minimum Spanning Trees

61

Maximum phase: ni 2log

Maximum possible fragment size ni 2

Number ofnodes

Page 62: Minimum Spanning Trees

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

Page 63: Minimum Spanning Trees

63

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

)log( nnO

Lower bound:

nn

log

Algorithm Time

Page 64: Minimum Spanning Trees

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)

Page 65: Minimum Spanning Trees

65

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

)log|)|(( nEnO

Can be improved to

|)|log( EnnO

Algorithm messages

Page 66: Minimum Spanning Trees

66

Asynchronous Version of GHS Algorithm

Simulates the synchronous version

Every fragment has a levelF )(FL

Page 67: Minimum Spanning Trees

67

FragmentFragment

1F 2FMWOE

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

(cost of merging proportional to )1F

Page 68: Minimum Spanning Trees

68

New fragment

1F 2FMWOE

)()( 21 FLFL

The combined level is )()( 2FLFL

Page 69: Minimum Spanning Trees

69

MWOE

FragmentFragment

1F 2F

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

(cost of merging proportional to )1F

Page 70: Minimum Spanning Trees

70

New fragment

1F 2FMWOE

The combined level is 1)()( 2 FLFL

)()( 21 FLFL

Page 71: Minimum Spanning Trees

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