1 / 10

WHY TRANSITIVE CLOSURE IS IMPORTANT?

WHY TRANSITIVE CLOSURE IS IMPORTANT?. APPLICATION IN PAGING NETWORK S + n NODES IN A PAGING NETWORK + WHO CAN REACH WHO – INDICATED BY ARCS + A PATH SHOWS WHO CAN BE REACHED BY A CHAIN OF ACTIONS ( NOT NECESSARILY DIRECT)

ira
Download Presentation

WHY TRANSITIVE CLOSURE IS IMPORTANT?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WHYTRANSITIVE CLOSUREIS IMPORTANT? APPLICATION IN PAGING NETWORKS + n NODES IN A PAGING NETWORK + WHO CAN REACH WHO – INDICATED BY ARCS + A PATH SHOWS WHO CAN BE REACHED BY A CHAIN OF ACTIONS ( NOT NECESSARILY DIRECT) TRANSITIVE CLOSURE SHOWS DIRECTLY WHO CAN REACH WHO ( DIRECTLY OR INDIRECTLY ) HOW TO COMPUTE TRANSITIVE CLOSURE? 1. DEPTH FIRST SEARCH ( Inefficient ) O ( nm ) 2. USING SHORT CUTS ( Better ) O ( n3 ) 3. WARSHALL ALGORITHM ( Best ) O ( n3 / c )

  2. CONSTRUCTING TRANSITIVE CLOSURE DFS FOR TRANSITIVE CLOSURE IDEA: Build a DFS tree from each of the vertices ( n ) IN MATRIX NOTATION: Fill in row by row the new R adjacency matrix . DFS ALGORITHM FOR TC OF G D = { S, A } BUILD D* = { S, R } INPUT D OUTPUT R, Initialized to zero While (i < n) Fill in Row R[i] with the nodes discovered by DFS at this step Return R Efficiency Repeats too many steps and does not make use of discovered dependencies at a previous row search. N iterations, O(m) operations at each.

  3. CONSTRUCTING TRANSITIVE CLOSURE SHORTCUTS FOR TC Say (of length 2) - Example 1 2 3 4 5 6 7 8 If there is edge Sij and also Sjk then we insert Sik BOOLEAN REPRESENTATIONS OF SHORT CUTS We update elements of matrix R rij = rij (rik rkj )  If both rik and rkj are TRUE, then this is TRUE and write 1 into rij otherwise leave rij unchanged. Efficiency : O ( nm )

  4. BOOLEAN ALGEBRA OPERATIONS TRUTH TABLES: OR AT LEAST ONE IS TRUE AND BOTH ARE TRUE

  5. EXAMPLE: X ( Y Z) Y X Z CIRCUIT DIAGRAM

  6. CONSTRUCTING TRANSITIVE CLOSURE Transitive Closure by shortcuts: Input: A and n, where A is an n X n boolean matrix that represents a binary relation. Output: R, the boolean matrix for the transitive closure of A void simpleTransitiveClosure ( boolean[][] A, int n, boolean[][] R) int i,j,k; Copy A into 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++) rij = rij (rik rkj )

  7. CONSTRUCTING TRANSITIVE CLOSURE WARSHALL’S ALGORITHM FOR TC • Uses shortcuts • Orders and calculates them in a more clever way • Puts the internal cycle outside rij = rij (rik rkj ) + We process each i  k  j triple only once (ordered by k ) + Preciously we did twice ( in shortcut ) once for the incoming and also for outgoing arcs.

  8. CONSTRUCTING TRANSITIVE CLOSURE THE BASIC ALGORITHM (WARSHALL) Input: A and n, where A is an n X n matrix that represents a binary relation. Output: R, the n X n matrix for the transitive closure of A void transitiveClosure ( boolean[][] A, int n, boolean[][] R) int i,j,k; Copy A into R Set all main diagonal entries, rii, to true for( k=1; k<=n; k++) for( i=1; i<=n; i++) for( j=1; j<=n; j++) rij = rij (rik rkj ) Complexity : Still O( n3), but with smaller constant O( n3 / c ), where c is the word size in the boolean operation.

  9. Bit String, Bit Matrix, bitwiseOR A bit String of length n is a sequence of n bits occupying contiguous storage, beginning on a computer word boundary, and being padded out to a computer-word boundary at the end, if needed, That is, if a computer holds c bits, then a bit string of n bits is stored in an array of [n/c] computer words. A bit matrix is an array of bit strings, with each bit string representing one row of the matrix. If A is a bit matrix, then A[i] denotes the ith row of A and is a bit string. Also, aij denotes the jth bit of A[i]. The procedure bitwiseOR(a, b, n), where a nad b are bit strings and n is an integer, is defined to compute a V b bitwise for n bits and leave the result in a.

  10. Warshall Algorithm using bit matrices Input:A and n, where A is an n X n bit matrix that represents a binary relation. We assume for the pseudocode that the class BitMetrix has been defined. Output:R, the n X n matrix for the transitive closure of A, also a bit Matrix. Algorithm: void warshallBitMatrices ( bitMatrix A, int n, bitMatrix R). int i,k; Copy A into R; Set all main diagonal entries, rii, to 1; for( k=1; k<=n; k++). for( i=1; i<=n; i++). if (rik == 1). bitwiseOR(R[I], R[k], n);

More Related