Given that is a relation on a set . The transitive closure of is the smallest transitive relation on $A$ containing $R$. We denote the transitive closure of $R$ by $\boxed {R^*}$.
If is already transitive, then .
For example, given the following definition of , we find :
digraph A {
label="R"
x->y
y->z
z->w
x->z
}
digraph B {
label="R*"
x->y
y->z
z->w
x->z
x->w
y->w
}Given , we can define the transitive closure, , recursively: ?
- Basis step: The pairs in are all in .
- Recursive step: If and then . We add the missing pairs step by step.
Warshall’s algorithm
Warshall's algorithm
Algorithm
An algorithm is a finite sequence of precise step-by-step instructions.
Link to originalWarshall’s algorithm computes the matrix of the transitive closure of . ?
Link to original
- Given a relation on a set with elements, we begin with its matrix.
- There are rounds. For each, we mutate the matrix. is the matrix of the transitive closure of .
- 1st rule: never change to
- 2nd rule: for the round, we select the th row and the th column, we look at all of the values not in this row or column. From the position of the value we are looking at, we check to see if the corresponding cells in the th row and column are , if they are, we change to otherwise we don’t do anything.
Example
Let be a relation on .
We first construct our starting matrix.
Round 1.
Round 2.
Round 3.
Round 4.
Hence this is our final relation.
digraph A {
label = "R"
a->d
b->a
b->c
c->a
c->d
d->c
}
digraph B {
label = "R*"
a->a
a->c
a->d
b->a
b->c
b->d
c->a
c->c
c->d
d->a
d->c
d->d
}