Subjects discrete mathematics

Warshall Transitive Closure

Step-by-step solutions with LaTeX - clean, fast, and student-friendly.

Search Solutions

Warshall Transitive Closure


1. We start with the relation $R = \{(1,2), (1,3), (2,4), (3,2), (4,3)\}$ on the set $A = \{1, 2, 3, 4\}$. We represent it as an adjacency matrix $M$, where rows and columns correspond to elements of $A$ in order $1,2,3,4$. 2. Initialize $M$ with $M[i,j] = 1$ if $(i,j) \in R$, else 0: $$ M = \begin{bmatrix} 0 & 1 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix} $$ 3. For Warshall's algorithm, we add $1$s on the diagonal for reflexive closure: $$ M^{(0)} = \begin{bmatrix} 1 & 1 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 0 & 1 & 1 & 0 \\ 0 & 0 & 1 & 1 \end{bmatrix} $$ 4. Iteratively, for each $k = 1$ to $4$, update $M^{(k)}$ by setting $M^{(k)}[i,j] = M^{(k-1)}[i,j] \lor (M^{(k-1)}[i,k] \land M^{(k-1)}[k,j])$ for all $i,j$. 5. For $k=1$ (consider paths through vertex 1): No new paths are added, matrix remains the same. 6. For $k=2$ (paths through vertex 2): Add a path from 1 to 4 because 1 to 2 and 2 to 4 exist. Similarly for 3 to 4 because 3 to 2 and 2 to 4 exist. Updated matrix: $$ M^{(2)} = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 0 & 1 & 0 & 1 \\ 0 & 1 & 1 & 1 \\ 0 & 0 & 1 & 1 \end{bmatrix} $$ 7. For $k=3$ (paths through vertex 3): Add path from 1 to 2 via 3, already present. Add path from 4 to 2 via 3 since 4 to 3 and 3 to 2 exist. Updated matrix: $$ M^{(3)} = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 0 & 1 & 0 & 1 \\ 0 & 1 & 1 & 1 \\ 0 & 1 & 1 & 1 \end{bmatrix} $$ 8. For $k=4$ (paths through vertex 4): Add path from 3 to 3 via 4 since 3 to 4 and 4 to 3 exist. Add path from 2 to 3 via 4, already exists. Updated matrix: $$ M^{(4)} = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 0 & 1 & 1 & 1 \\ 0 & 1 & 1 & 1 \\ 0 & 1 & 1 & 1 \end{bmatrix} $$ 9. The transitive closure $R^*$ contains all pairs $(i,j)$ where $M^{(4)}[i,j] = 1$: $$ R^* = \{(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,2), (3,3), (3,4), (4,2), (4,3), (4,4)\} $$ Final answer: the transitive closure includes all these pairs reflecting reachability within $A$ under $R$.