Warshall’s algorithm

Sample Solution

     

1. Warshall's Algorithm for Reflexive-Transitive Closure

Initial Matrix (Including Reflexive Closure):

[1 1 0 0 0]
[0 1 0 1 0]
[0 0 1 1 0]
[0 0 0 1 1]
[0 0 1 0 1]

Explanation:

The diagonal elements (1s) are added to represent the reflexive property (a relation with itself).

Iterations of Warshall's Algorithm:

Iteration k=1:

[1 1 0 0 0]  (No changes, all-zeros row remains unchanged)
[0 1 1 1 0]  (b -> d added)
[0 0 1 1 0]
[0 0 0 1 1]
[0 0 1 0 1]
 

Full Answer Section

     

Iteration k=2:

[1 1 1 0 0]  (a -> d added)
[0 1 1 1 0]
[0 0 1 1 1]  (c -> e added)
[0 0 0 1 1]
[0 0 1 0 1]

Iteration k=3:

[1 1 1 1 1]  (a -> e added)
[0 1 1 1 0]
[0 0 1 1 1]
[0 0 0 1 1]
[0 0 1 0 1]

Final Matrix (Transitive Closure):

The final matrix represents the transitive closure, where all reachable pairs have a value of 1.

2. Floyd's Algorithm for Path Lengths

Using the same initial matrix as problem 1, Floyd's algorithm would also result in the same final matrix as the transitive closure:

[1 1 1 1 1]
[0 1 1 1 0]
[0 0 1 1 1]
[0 0 0 1 1]
[0 0 1 0 1]

However, Floyd's algorithm additionally provides the shortest path lengths between all pairs of vertices. To determine these, a separate calculation is needed that involves analyzing the intermediate matrices generated during the algorithm.

3. Graph, Condensation Graph, Topological Order, and Adjacency Matrix

Graph:

     a -> b
      \
       c -> d -> e

Condensation Graph (Renaming Vertices):

   1 (a, b)
    \
     2 (c, d, e)

Topological Order:

Since there are no directed cycles in the condensation graph, any order where 1 precedes 2 is a topological order. We can choose 1, 2.

Adjacency Matrix (Topological Order):

[0 1]  (1 does not have outgoing edges)
[0 0]  (2 does not have outgoing edges)

Reflexive-Transitive Closure of Adjacency Matrix:

The adjacency matrix already represents the transitive closure, as there are no directed cycles. Therefore, the reflexive-transitive closure remains the same.

[0 1]
[0 0]

Characteristic of Total Order:

The characteristic indicating a total order in this adjacency matrix is that it has only 0s and 1s, and for any two vertices i and j, either matrix[i][j] = 1 or matrix[j][i] = 1, but not both. This implies an irreflexive (no self-loops) and transitive relationship between vertices.

4. Floyd's Algorithm with Distance Matrix

Initial Matrix:

[0 ∞ 4 -2]
[∞ 2 3 6]
[-3 2 0 ∞]
[4 ∞ 5 0]

Iterations of Floyd's Algorithm (Intermediate Matrices Omitted for Brevity):

The intermediate matrices would show the shortest path lengths discovered at each iteration. Floyd's algorithm would ultimately produce the following final distance matrix:

[0 3 1 -1]
[∞ 2 0 4]
[-2 5 -

IS IT YOUR FIRST TIME HERE? WELCOME

USE COUPON "11OFF" AND GET 11% OFF YOUR ORDERS