Computer Science 331
Computation of Minimum-Cost Spanning Trees — Prim’s Algorithm Mike Jacobson
Department of Computer Science University of Calgary
Lecture #35
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 1 / 20
Computer Science 331 Computation of Minimum-Cost Spanning Trees - - PowerPoint PPT Presentation
Computer Science 331 Computation of Minimum-Cost Spanning Trees Prims Algorithm Mike Jacobson Department of Computer Science University of Calgary Lecture #35 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 1 /
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 1 / 20
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 2 / 20
Introduction
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 3 / 20
Min-Cost Spanning Trees
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 4 / 20
Min-Cost Spanning Trees
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 5 / 20
Min-Cost Spanning Trees
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 6 / 20
Min-Cost Spanning Trees
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 7 / 20
Min-Cost Spanning Trees
1 G1 is a spanning tree of G. 2 w(G1) ≤ w(G2) for every spanning tree G2 of G.
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 8 / 20
Algorithm General Construction
1 Start with
2 Repeatedly add vertices (if necessary) and edges — ensuring that
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 9 / 20
Algorithm General Construction
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 10 / 20
Algorithm Problem and Algorithm
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 11 / 20
Algorithm Problem and Algorithm
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 12 / 20
Algorithm Problem and Algorithm
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 13 / 20
Algorithm Problem and Algorithm
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 14 / 20
Algorithm Problem and Algorithm
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 15 / 20
Example
a c b d e f g 2 5 1 2 4 1 1 3 3 2 2 1
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
a c b d e f g 2 5 1 2 4 1 1 3 3 2 2 1
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
a c b d e f g 2 5 1 2 4 1 1 3 3 2 2 1
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
a c b d e f g 2 5 1 2 4 1 1 3 3 2 2 1
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
c b d e f g 2 5 1 2 4 1 1 3 3 2 2 1 a
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
c b d e f g 2 5 1 2 4 1 1 3 3 2 2 1 a
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
c d e f g 2 5 1 2 4 1 1 3 3 2 2 1 b a
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
c d e f g 2 5 1 2 4 1 1 3 3 2 2 1 b a
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
c d e f g 2 5 1 2 4 1 1 3 3 2 2 1 b a
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
c d e f g 2 5 1 2 4 1 1 3 3 2 2 1 b a
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
c d e f g 2 5 1 2 4 1 1 3 3 2 2 1 b a
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
d e f g 2 5 1 2 4 1 1 3 3 2 2 1 b a c
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
d e f g 2 5 1 2 4 1 1 3 3 2 2 1 b a c
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
d e f g 2 5 1 2 4 1 1 3 3 2 2 1 b a c
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
d e f g 2 5 1 2 4 1 1 3 3 2 2 1 b a c
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
d e f g 2 5 1 2 4 1 1 3 3 2 2 1 a c b
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
d e f g 2 5 1 2 4 1 1 3 3 2 2 1 a c b
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
d e f g 2 5 1 2 4 1 1 3 3 2 2 1 a c b
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
d e f g 2 5 1 2 4 1 1 3 3 2 2 1 a c b
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
e f g 2 5 1 2 4 1 1 3 3 2 2 1 a c b d
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
e f g 2 5 1 2 4 1 1 3 3 2 2 1 a c b d
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
e f g 2 5 1 2 4 1 1 3 3 2 2 1 a c b d
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
e f g 2 5 1 2 4 1 1 3 3 2 2 1 a c b d
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
e g 2 5 1 2 4 1 1 3 3 2 2 1 a c b d f
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
e g 2 5 1 2 4 1 1 3 3 2 2 1 a c b d f
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
e g 2 5 1 2 4 1 1 3 3 2 2 1 a c b d f
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
g 2 5 1 2 4 1 1 3 3 2 2 1 a c b d f e
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
g 2 5 1 2 4 1 1 3 3 2 2 1 a c b d f e
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
2 5 1 2 4 1 1 3 3 2 2 1 a c b d f e g
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Example
1 1 1 2 2 1 a c b d f e g
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 16 / 20
Termination and Efficiency
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 17 / 20
Termination and Efficiency
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 18 / 20
Additional Comments and References
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 19 / 20
Additional Comments and References
Mike Jacobson (University of Calgary) Computer Science 331 Lecture #35 20 / 20