

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Huang; Class: DATA STRUCTR&ALGORITHMS; Subject: Computer Science & Engineering; University: University of South Carolina - Columbia; Term: Spring 2009;
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


University of South Carolina
04/03/2009 2
 Reading assignment: Chapter 8.2, 8.
 Homework 6 was assigned on Monday and is due on Wednesday, April 8 in class
04/03/2009 3
0 0 1 0 1 0 0 1 0 0 0 0 0 1 0 0
0 0 1 0 1 1 11 1 1 0 0 0 0 11 1 1 11 1
adjacency matrix transitive closure 04/03/2009 4
Main idea: a path exists between two vertices i, j, iff  there is an edge from i to j; or  there is a path from i to j going through vertex 1; or  there is a path from i to j going through vertex 1 and/or 2; or  there is a path from i to j going through vertex 1, 2, and/or 3; or  ...  there is a path from i to j going through any of the other vertices
04/03/2009 5
3
2 4
1
3
2 4
1
3
2 4
1
3
2 4
1
R(0) 0 0 1 0 1 0 0 1 0 0 0 0 0 1 0 0
R(1) 0 0 1 0 1 0 11 1 0 0 0 0 0 1 0 0
R(2) 0 0 1 0 1 0 1 1 0 0 0 0 11 1 1 11 1
R(3) 0 0 1 0 1 0 1 1 0 0 0 0 1 1 1 1
R(4) 0 0 1 0 1 11 1 1 0 0 0 0 1 1 1 1
3
2 4
1
construct solution through series of boolean matricesR(0), âŚ,R (n) using increasing subsets of the vertices allowed as intermediate
04/03/2009 6
In the k th^ stage determine if a path exists between two vertices i, j using just vertices among 1,âŚ, k
R (k-1)[ i,j ] (path using just 1 ,âŚ, k- 1) R (k)[ i,j ] = or ( R (k-1)^ [ i,k ] and R (k-1)[ k,j ]) (path from i to k and from k to i using just 1 ,âŚ, k- 1) i
j
k
k th^ stage
04/03/2009 7
It implies the following rules for generatingR (k)^ fromR (k-1)^ :
Rule 1 If an element in rowi and columnj is 1 inR (k-1)^ , it remains 1 inR (k)
Rule 2 If an element in rowi and columnj is 0 inR (k-1)^ , it has to be changed to 1 inR (k)^ if and only if the element in its rowi and columnk and the element in its columnj and rowk are both 1âs inR (k-1) 04/03/2009 8
04/03/2009 9
3
2 4
04/03/2009 10
Time efficiency: Space efficiency:
Î(n^3 ) Matrices can be written over their predecessors
04/03/2009 11
Problem: In a weighted (di)graph, find shortest paths between every pair of vertices Same idea: construct solution through series of matricesD (0)^ , âŚ, D (n)^ using increasing subsets of the vertices allowed as intermediate Example: 2
2
3 6
7
04/03/2009 12
On the k- th iteration, the algorithm determines shortest paths between every pair of vertices i, j that use only vertices among 1,âŚ, k as intermediate D ( k )[ i,j ] = min { D ( k -1)[ i,j ], D ( k -1)[ i,k ] + D ( k -1)^ [ k,j ]}
i
j
k
DD (( kk -1)-1)^ [[ i,ji,j ]]
DD (( kk - -1)1)^ [[ i,ki,k ]]
D D (( kk - -1)1)^ [[ k,jk,j ]]