Presentation is loading. Please wait.

Presentation is loading. Please wait.

Reachability as Transitive Closure Algorithm : Design & Analysis [17]

Similar presentations


Presentation on theme: "Reachability as Transitive Closure Algorithm : Design & Analysis [17]"— Presentation transcript:

1 Reachability as Transitive Closure Algorithm : Design & Analysis [17]

2 In the last class … Undirected and Symmetric Digraph UDF Search Skeleton Biconnected Components Articulation Points and Biconnectedness Biconnected Component Algorithm Analysis of the Algorithm

3 Reachability as Transitive Closure Transitive Closure by DFS Transitive Closure by Shortcuts Washall ’ s Algorithm for Transitive Closure All-Pair Shortest Paths

4 Fundamental Questions For all pair of vertices in a graph, say, u, v: Is there a path from u to v? What is the shortest path from u to v? Reachability as a (reflexive) transitive closure of the adjacency relation, which can be represented as a bit matrix.

5 Computing the Reachability by DFS With each vertex v i, constructing a DFS tree rooted at v i. For each vertex v j encountered, R[i][j] is set to true. At most, m edges are processed. It is possible to set one in more than one row during each DFS. (In fact, if v k is on the path from v i to v j, when v j is encountered, not only R[i][j], but also R[k][j] can be set)

6 Computing Reachability by Condensation Graph Note: the elements of the sub-matrix of R for a strong component are all true. The steps: Find the strong components of G, and get G , the condensation graph of G. (  (n+m)) Computing reachability for G . Expand the reachability for G  to that for G. (O(n 2 ))

7 Transitive Closure by Shortcuts The idea: if there are edges s i s k, s k s j, then an edge s i s j, the “ shortcut ” is inserted Pass one Pass two Note: the triple (1,5,3) is considered more than once

8 Transitive Closure by Shortcuts: the algorithm Input: A, an n  n boolean matrix that represents a binary relation Output: R, the boolean matrix for the transitive closure of A Procedure void simpleTransitiveClosure(boolean[][] A, int n, boolean[][] R) int i,j,k; Copy A to R; Set all main diagonal entries, rii, to true; while (any entry of R changed during one complete pass) for (i=1; i  n; i++) for (j=1; j  n; j++) for (k=1; k  n; k++) r ij =r ij  (r ik  r kj ) The order of (i,j,k) matters

9 Change the order: Washall ’ s Algorithm void simpleTransitiveClosure(boolean[][] A, int n, boolean[][] R) int i,j,k; Copy A to R; Set all main diagonal entries, rii, to true; while (any entry of R changed during one complete pass) for (k=1; k  n; k++) for (i=1; i  n; i++) for (j=1; j  n; j++) r ij =r ij  (r ik  r kj ) k varys in the outmost loop Note: “false to true” can not be reversed

10 Highest-numbered intermediate vertex sksk sisi sjsj A specific order is assumed for all vertices Vertical position of vertices reflect their vertex numbers The highest intermediate vertex in the intervals (s i s k ), (s k s j ) are both less than s k

11 Correctness of Washall ’ s Algorithm Notation: The value of r ij changes during the execution of the body of the “for k…” loop After initializations: r ij (0) After the kth time of execution: r ij (k)

12 Correctness of Washall ’ s Algorithm If there is a simple path from s i to s j (i  j) for which the highest-numbered intermediate vertex is s k, then r ij (k) =true. Proof by induction: Base case: r ij (0) =true if and only if s i s j  E Hypothesis: the conclusion holds for h

13 Correctness of Washall ’ s Algorithm If there is no path from s i to s j, then r ij =false. Proof If r ij =true, then only two cases: r ij is set by initialization, then s i s j  E Otherwise, r ij is set during the kth execution of (for k…) when r ij (k-1) =true, r ij (k-1) =true, which, recursively, leads to the conclusion of the existence of a s i s j -path. (Note: If a s i s j -path exists, there exists a simple s i s j -path)

14 All-pairs Shortest Path Non-negative weighted graph Shortest path property: If a shortest path from x to z consisting of path P from x to y followed by path Q from y to z. Then P is a shortest xz-path, and Q, a shortest zy-path.

15 Computing the Distance Matrix Basic formula: D (0) [i][j]=w ij D (k) [i][j]=min(D (k-1) [i][j], D (k-1) [i][k]+ D (k-1) [i][j]) Basic property: D (k) [i][j]  d ij (k) where d ij (k) is the weight of a shortest path from v i to v j with highest numbered vertex v k.

16 All-Pairs Shortest Paths Floyd algorithm Only slight changes on Washall ’ s algorithm. Routing table


Download ppt "Reachability as Transitive Closure Algorithm : Design & Analysis [17]"

Similar presentations


Ads by Google