R = \{(1,4), (2,2), (3,4), (3,5), (4,1), (5,2), (5,5)\} R = {( 1 , 4 ) , ( 2 , 2 ) , ( 3 , 4 ) , ( 3 , 5 ) , ( 4 , 1 ) , ( 5 , 2 ) , ( 5 , 5 )}
Here are the steps of the Warshall’s algorithm:
Step 1. Assign initial values W=M_R, k=0 W = M R , k = 0 .
Step 2. Execute k:=k+1. k := k + 1.
Step 3. For all i\ne k i = k such that w_{ik}=1 w ik = 1 , and for all j j execute the operation w_{ij}=w_{ij}\lor w_{kj}. w ij = w ij ∨ w kj .
Step 4. If k=n k = n , then stop: we have the solution W=M_{R^*} W = M R ∗ , else go to the step 2.
n=|A|=5. n = ∣ A ∣ = 5.
W^{(0)}=M_R=\left(\begin{array} {cccccc} 0 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 1 \\ 1 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 1 \end{array}\right) W ( 0 ) = M R = ⎝ ⎛ 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 1 ⎠ ⎞
W^{(1)}=\left(\begin{array} {cccccc} 0 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 1 \\ 1 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 1 \end{array}\right) W ( 1 ) = ⎝ ⎛ 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 1 ⎠ ⎞
W^{(2)}=\left(\begin{array} {cccccc} 0 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 1 \\ 1 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 1 \end{array}\right) W ( 2 ) = ⎝ ⎛ 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 1 ⎠ ⎞
W^{(3)}=\left(\begin{array} {cccccc} 0 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 1 \\ 1 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 1 \end{array}\right) W ( 3 ) = ⎝ ⎛ 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 1 ⎠ ⎞
W^{(4)}=\left(\begin{array} {cccccc} 1 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 1 & 0 & 0 & 1 & 1 \\ 1 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 1 \end{array}\right) W ( 4 ) = ⎝ ⎛ 1 0 1 1 0 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 1 ⎠ ⎞
Thus, the matrix of transitive closure of R R is the following:
M_{R^*}=W^{(5)}=\left(\begin{array} {cccccc} 1 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 1 & 1 & 0 & 1 & 1 \\ 1 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 1 \end{array}\right) M R ∗ = W ( 5 ) = ⎝ ⎛ 1 0 1 1 0 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 0 0 1 0 1 ⎠ ⎞
Therefore, the transitive closure of R R is the following:
R^* = \{(1,1),(1,4), (2,2),(3,1),(3,2), (3,4), (3,5), (4,1),(4,4), (5,2), (5,5)\} R ∗ = {( 1 , 1 ) , ( 1 , 4 ) , ( 2 , 2 ) , ( 3 , 1 ) , ( 3 , 2 ) , ( 3 , 4 ) , ( 3 , 5 ) , ( 4 , 1 ) , ( 4 , 4 ) , ( 5 , 2 ) , ( 5 , 5 )}