This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Discrete Mathematics, Spring 2004 Homework 8 Sample Solutions 6.4 #5. Find the length of a shortest path and a shortest path between the vertices h and d in the following graph: 2 7 6 5 4 4 6 3 5 6 2 a c d b z f e 5 2 7 4 7 4 3 h i j g 5 2 4 3 Solution . The shortest path is h , f , c , d , with total length 10. To see this, we use Dijkstras algorithm, modified as shown in Example 6.4.4 in the text. Let V ( j ) denote the vertex chosen in the beginning of the j th iteration of the while loop, let L ( j ) denote the weight of the least weight path from h to V ( j ), and let P ( j ) denote the vertex from which V ( j ) was labeled. The table below indicates the order of selection; the last column of the table indicates the vertices which have not yet been made permanent at the end of the j th iteration (but have weight < ). j V ( j ) L ( j ) P ( j ) Temporary ( V,L,P ) 1 h ( a, 4 ,h ) , ( e, 7 ,h ) , ( f, 5 ,h ) , ( i, 2 ,h ) 2 i 2 h ( a, 4 ,h ) , ( e, 7 ,h ) , ( f, 5 ,h ) , ( j, 8 ,i ) 3 a 4 h ( e, 7 ,h ) , ( f, 5 ,h ) , ( j, 8 ,i ) , ( b, 7 ,a ) 4 f 5 h ( e, 7 ,h ) , ( j, 8 ,i ) , ( b, 7 ,a ) , ( c, 7 ,f ) , ( g, 9 ,f ) 5 b 7 a ( e, 7 ,h ) , ( j, 8 ,i ) , ( c, 7 ,f ) , ( g, 9 ,f ) 6 c 7 f ( e, 7 ,h ) , ( j, 8 ,i ) , ( g, 9 ,f ) , ( d, 10 ,c ) 7 e 7 h ( j, 8 ,i ) , ( g, 9 ,f ) , ( d, 10 ,c ) 8 j 8 i ( g, 9 ,f ) , ( d, 10 ,c ) , ( z, 13 ,j ) 9 g 9 f ( d, 10 ,c ) , ( z, 13 ,j ) 10 d 10 c done 1 6.4 #8. Write an algorithm that finds the lengths of the shortest paths between all vertex pairs in a simple, connected, weighted graph having n vertices in time O ( n 3 ). Solution . Probably the easiest approach is to take Dijkstras algorithm as shown in the text, and then make a few minor modifications. The input to our algorithm will now simply be the n n matrix w of edge weights of a simple connected graph G whose vertices are labeled 1 to n . (For convenience, we assume that w ( i,j ) = if i and j are not adjacent.) The output will be the n n matrix L...
View
Full
Document
 Spring '08
 WOUTERS
 Math, Algebra

Click to edit the document details