15.082 and 6.855j spanning tree algorithms. 2 the greedy algorithm in action 1 2 3 4 5 6 7 35 10 30...

32
1 15.082 and 6.855J Spanning Tree Algorithms

Upload: anthony-dillon

Post on 27-Mar-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

1

15.082 and 6.855J

Spanning Tree Algorithms

Page 2: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

2

The Greedy Algorithm in Action

1

2

3

4

5

6

7

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 3: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

3

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 4: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

4

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 5: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

5

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 6: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

6

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 7: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

7

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 8: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

8

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 9: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

9

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 10: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

10

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 11: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

11

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 12: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

12

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 13: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

13

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 14: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

14

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

Page 15: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

Node 1 2 3 4 5 6 7

First 1 2 3 4 5 4 7

35

10

30

15

25

40

20 17

8

15

11

211

2

3 5 7

root node

4 66

15

Page 16: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

Node 1 2 3 4 5 6 7

First 1 4 3 4 5 4 7

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

7

2

16

Page 17: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

Node 1 2 3 4 5 6 7

First 1 4 3 4 5 4 5

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

77

17

Page 18: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

Node 1 2 3 4 5 6 7

First 1 4 5 4 5 4 5

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

773

18

Page 19: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

Node 1 2 3 4 5 6 7

First 1 4 4 4 4 4 4

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

75 73 5 73

19

Page 20: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

The Greedy Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

Node 1 2 3 4 5 6 7

First 4 4 4 4 4 4 4

35

10

30

15

25

40

20 17

8

15

11

211

2

3

4

5

6

75 73

1

20

Page 21: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

21

Prim’s Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

1121

4

5

6

7

1

2

3

The minimum cost arc from yellow nodes to green nodes can be found by placing arc values in a priority queue.

Page 22: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

22

Prim’s Algorithm in Action

1

3

354

5

30

15

25

40

20

6

7

17

8

15

1121

4

5

6

7

1

3522

10

25

102

3

Page 23: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

23

20

Prim’s Algorithm in Action

1

3

354

515

25

40

6

7

17

15

11

1

3522

10

25

102 4

10 8

2130

8

20 3021

5

6

73

4

Page 24: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

24

20

Prim’s Algorithm in Action

1

3

354

515

25

40

6

7

17

15

11

1

3522

10

25

102 4

10 8

2130

8

20 3021

68

17

15

5 73

64

Page 25: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

25

20

Prim’s Algorithm in Action

1

3

354

515

25

40

6

7

17

15

11

1

3522

10

25

102 4

10 8

2130

8

20 3021

68

17

1564

15

515

1173 5

Page 26: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

26

20

Prim’s Algorithm in Action

1

3

354

515

25

40

6

7

17

15

11

1

3522

10

25

102 4

10 8

2130

8

20 3021

68

17

1564

15

515

1173 5

Page 27: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

27

20

Prim’s Algorithm in Action

1

3

354

515

25

40

6

7

17

15

11

1

3522

10

25

102 4

10 8

2130

8

20 3021

68

17

1564

15

515

113 75

117

Page 28: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

28

20

Prim’s Algorithm in Action

1

3

354

515

25

40

6

7

17

15

11

1

3522

10

25

102 4

10 8

2130

8

20 3021

68

17

1564

15

515

117

1173 5153

Page 29: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

29

20

Prim’s Algorithm in Action

1

3

354

515

25

40

6

7

17

15

11

1

3522

10

25

102 4

10 8

2130

8

20 3021

68

17

1564

15

515

117

1173 5153

Page 30: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

30

20

Prim’s Algorithm in Action

1

3

354

515

25

40

6

7

17

15

11

1

3522

10

25

102 4

10 8

2130

8

20 3021

68

17

1564

15

515

117

1173 5153

Page 31: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

31

Sollin’s Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

11

21

Treat all nodes as singleton components, and then select the min cost arc leaving the component.

4

5

6

7

1

2

3

4

5

6

7

1

2

3

Page 32: 15.082 and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action 1 2 3 4 5 6 7 35 10 30 15 25 40 20 17 8 15 11 21 1 2 3 4 5 6 7

32

Sollin’s Algorithm in Action

1

2

3

35

104

5

30

15

25

40

20

6

7

17

8

15

11

21

Find the min cost edge out of each component

4

5

6

7

1

2

3 73 5

6