- The relation contains R.
- The relation possesses the property.
- The relation has the fewest number of ordered pairs that satisfies both criteria listed above.
The reflexive closure of R is given by R∪{(x,x):xϵA}.
The symmetric closure of R is given by R∪{(y,x):(x,y)ϵA}.
Finding transitive closure is not as simple. Consider the relation R={(1,2),(3,1),(1,4),(4,3)}. We may be tempted to think that the transitive closure is given by R{(3,2),(3,4),(1,3),(4,1)}. This new relation satisfies property 1 above but does it satisfy 2? No, it is missing (1,1), (3,3) and so on.
One method to find the transitive closure is to use Warshall's algorithm. Given a relation R on set A (which has n members), Warshall's algorithm takes as input the n x n 0-1 matrix representing R, MR, and outputs a matrix representing the transitive closure of R, MR∗.
Warshall's Algorithm:
for k=1 to n
for i=1 to n
for j=1 to n
wij=wij∨(wik∧wkj)
Examining the innermost loop we note that only j (which represents our columns in our matrix) is changing. The counters i and k remain constant.
If wik is 0 then the row remains unchanged since wik∧wkj evaluates to 0.
If wik is 1 then wij takes the value of wij∨wkj. If wij is 1 it stays as 1. If wkj is 1 then wij is updated to 1. In other words we replace the ith row with the result of boolean addition of the ith and kth rows.
Let's look at an example. Let's find the transitive closure of R={(1,1), (1,3), (2,1), (3,2)} using Warshall's algorithm.
MR=[101100010]
k=1:W1=[101101010]
k=2:W2=[101101111]
k=3:W3=[111101111]
So, MR∗ = {(1,1), (1,2), (1,3), (2,1), (2,3), (3,1), (3,2), (3,3)}