Algorithms R OBERT S EDGEWICK | K EVIN W AYNE 4.3 G REEDY MST D EMO - - PowerPoint PPT Presentation

algorithms
SMART_READER_LITE
LIVE PREVIEW

Algorithms R OBERT S EDGEWICK | K EVIN W AYNE 4.3 G REEDY MST D EMO - - PowerPoint PPT Presentation

Algorithms R OBERT S EDGEWICK | K EVIN W AYNE 4.3 G REEDY MST D EMO Algorithms F O U R T H E D I T I O N R OBERT S EDGEWICK | K EVIN W AYNE http://algs4.cs.princeton.edu Greedy MST algorithm demo Start with all edges colored gray.


slide-1
SLIDE 1

ROBERT SEDGEWICK | KEVIN WAYNE

F O U R T H E D I T I O N

Algorithms

http://algs4.cs.princeton.edu

Algorithms

ROBERT SEDGEWICK | KEVIN WAYNE

4.3 GREEDY MST DEMO

slide-2
SLIDE 2

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

2

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 2-7 0.34 4-5 0.35 1-2 0.36 4-7 0.37 0-4 0.38 6-2 0.40 3-6 0.52 6-0 0.58 6-4 0.93 an edge-weighted graph

slide-3
SLIDE 3

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

3

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-2 0.26 1-3 0.29 2-7 0.34 1-2 0.36 6-0 0.58 6-4 0.93

crossing edges (sorted by weight) in MST crossing edge min-weight crossing edge grey vertices form

  • ne side of cut
slide-4
SLIDE 4

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

4

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-2 MST edges

slide-5
SLIDE 5

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

5

Greedy MST algorithm demo

5 4 7 1 3 2 6 5-7 0.28 1-5 0.32 4-5 0.35

crossing edges (sorted by weight) in MST

0-2 MST edges

min-weight crossing edge

slide-6
SLIDE 6

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

6

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-2 5-7 MST edges

slide-7
SLIDE 7

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

7

Greedy MST algorithm demo

5 4 7 1 3 2 6 6-2 0.40 3-6 0.52 6-0 0.58 6-4 0.93

crossing edges (sorted by weight) in MST

0-2 5-7 MST edges

min-weight crossing edge

slide-8
SLIDE 8

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

8

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-2 5-7 6-2 MST edges

slide-9
SLIDE 9

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

9

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-7 0.16 2-3 0.17 2-7 0.34 4-5 0.35 1-2 0.36 4-7 0.37 3-6 0.52

crossing edges (sorted by weight) in MST

0-2 5-7 6-2 MST edges

min-weight crossing edge

slide-10
SLIDE 10

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

10

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-2 5-7 6-2 0-7 MST edges

slide-11
SLIDE 11

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

11

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-2 5-7 6-2 0-7 MST edges

min-weight crossing edge

2-3 0.17 1-7 0.19 1-5 0.32 1-2 0.36

crossing edges (sorted by weight) in MST

slide-12
SLIDE 12

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

12

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-2 5-7 6-2 0-7 2-3 MST edges

slide-13
SLIDE 13

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

13

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-2 5-7 6-2 0-7 2-3 MST edges

min-weight crossing edge

1-7 0.19 1-3 0.29 1-5 0.32 4-5 0.35 1-2 0.36 4-7 0.37 0-4 0.38 6-4 0.93

crossing edges (sorted by weight) in MST

slide-14
SLIDE 14

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

14

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-2 5-7 6-2 0-7 2-3 1-7 MST edges

slide-15
SLIDE 15

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

15

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-2 5-7 6-2 0-7 2-3 1-7 MST edges

min-weight crossing edge

4-5 0.35 4-7 0.37 0-4 0.38 6-4 0.93

crossing edges (sorted by weight) in MST

slide-16
SLIDE 16

・Start with all edges colored gray. ・Find cut with no black crossing edges; color its min-weight edge black. ・Repeat until V - 1 edges are colored black.

16

Greedy MST algorithm demo

5 4 7 1 3 2 6 0-2 5-7 6-2 0-7 2-3 1-7 4-5 MST edges