MATH 310, FALL 2003 (Combinatorial Problem Solving) Lecture 15, Friday, October 3
4.1. Shortest Paths Homework (MATH 310#5F): Read 4.2 and 5.1. Do Exercise 4.2: 1,3,5,7 Volunteers: ____________ Problem: 1. Challenge (up to 5+5 pts.) Exercise Challenge (up to 5+5 pts.) Exercise
A Network A network is a graph in with a positive integer k(e) assigned to each edge e. This usually represents a “lenght” of an edge. N f i m R h c b d eg j k
Dijkstra’s Algorithm We are looking for a shortest path from vertex a to any other vertex (or to some specific vertx z). At each step of the algorithm the (green) edge e between a labeled vertex p and unlabeled vertex q is selected in such a way, that d(p) + k(e) is minimal. a Labeled vertices Unlabeled vertices p q z e
Example 1 Find the shortest path from N to R. N f i m R h c b d eg j k
Floyd’s Algorithm FOR k à 1 TO n DO FOR i à 1 TO n DO FOR j à 1 TO n DO IF d ik + d kj < d ij THEN d ij à d ik + d kj.
4.2 Minimal Spanning Trees Minimal spanning tree in a network is a spanning tree whose sum of edge lenghts k(e) is as small as possible. Note: Minimal spanning trees are also called minimum cost spanning trees.
Prim’s Algorithm We are looking for a minimal spanning tree startingt at some vertex a. At each step of the algorithm the (green) edge e between a labeled vertex p and unlabeled vertex q is selected in such a way, that k(e) is minimal. a Labeled vertices Unlabeled vertices p q z e
Kruskal’s Algorithm Step 1. Sort the edges: k(e 1 ) · k(e 2 ) ·... · k(e m ). Step 2. FOR i à 1 TO m DO add e i to T if that does not form a circuit.