Collection
zero Useful+1
zero

Transitive closure

Mathematical terminology
Transitive closure, that is, in mathematics Binary relation The transitive closure of R is the smallest on X containing R Transitive relationship For example, if X is a collection of people (living or dead) and R is the relationship "father and son", the transitive closure of R is the relationship "x is the ancestor of y". For another example, if X is a collection of airports and the relation xRy is "there is direct flight from airport x to airport y", the transfer closure of R is "it may fly from x to y through one or more flights".
Chinese name
Transitive closure
Foreign name
Transitive closure
Discipline
mathematics
Object
Set X
Definition
Smallest on X containing R Transitive relationship
Type
Mathematical terminology

Existence and description

Announce
edit

definition

For any relation R, the transitive closure of R always exists. Transitive relationship Of any family intersection It is also transmitted. Furthermore, there is at least one transitive relationship including R, that is, the trivial: X × X. The R transitive closure is derived from the intersection of all transitive relationships containing R. [1]
We can use more specific terms to describe R's transitive closure as follows. A relation T defined on X is called xTy if and only if there are finite elements(
)Sequence, so that
also
,
, …,
and

It is formally written as

It is easy to check that the relation T is passed and contains R. Furthermore, any R containing Transitive relationship It also contains T, so T is the transitive closure of R.

Relevant concepts

The transitive reduction of relation R is the smallest relation with R as its transitive closure. Generally speaking, it is not unique.

Prove that T is the minimum transitive relation including R

Announce
edit

prove

Let A be a set of any elements.
Assumption: GA transfer relation RAGA TAGA. So (a, b) GA (a, b) TA. So, specific (a, b) RA.
Now, through the definition of T, we know n (a, b) RnA. Then, i, in eiA. So, there are paths from a to b as follows: aRAe1RA RAe(n-1)RAb。
However, via GA on RA Transitivity , i, in (a, ei) GA, so, (a, e (n-1)) GA (e (n-1), b) GA, so through the transitivity of GA, we get (a, b) GA, which contradicts (a, b) GA.
Therefore, (a, b) AA, (a, b) TA (a, b) GA. This means TG, for any G that contains R for transmission. Therefore, T is the smallest transitive closure containing R.

inference

If R is passed, then R=T.

purpose

Announce
edit
Pay attention to two Transitive relationship The union of does not have to be transitive. To maintain transitivity, you must use transitive closures. For example, this occurs when taking two equivalence relation Or pre ordered merging. In order to obtain a new equivalence relation or preorder, transitive closure must be selected (reflexivity and symmetry - in the case of equivalence relations - are automatic). [2]
The transitive closure of directed acyclic graph (DAG) is the reachability relation of DAG and a strict Partial order

Relationship with complexity

Announce
edit
stay Computational complexity theory Medium, Complexity Class NL strictly corresponds to available First-order logic And a collection of logical sentences expressed by transitive closures. This is because the nature of transitive closure is closely related to the NL complete problem STCON, which finds a directed path in a graph. Similarly, class L is first-order logic with commutative transitive closures. In Second-order logic When passing closures are added, we get PSPACE.

algorithm

Announce
edit
The efficient algorithm for calculating transitive closure of graphs can be seen in here. The simplest technique is Floyd-Warshall algorithm [3]

Floyd-Warshall algorithm

The path of a single edge is not necessarily the best path. Start from any single path. The distance between all two points is the sum of the weight of the edge, (if there is no edge connected between two points, it is infinite). For each pair of vertices u and v, see if there is a vertex w that makes the path from u to w and then to v shorter than the known path. If it is updated. Incredibly, the results can be obtained as long as they are properly arranged// Dist (i, j) is from node The shortest distance from i to node j
For i←1to n do
For j←1to n do
dist(i,j) = weight(i,j)
For k ← 1 to n do//k is "media node" {Be sure to enumerate media nodes}
For i←1to n do
For j←1to n do
If (dist (i, k)+dist (k, j)<dist (i, j)) then//Is it a shorter path?
dist(i,j) = dist(i,k) + dist(k,j)
The efficiency of this algorithm is O( V^3 )。 It needs adjacency matrix To store the diagram.
This algorithm is easy to implement, only a few lines.
Even if the problem is Single source shortest path It is still recommended to use this algorithm if time and space allow (as long as there is space for the lower adjacency matrix to be placed, there is no problem in time).
Calculate the Shortest path Floyd algorithm

Core code

for(k=0; k
{
for(i=0; i
{
for(j=0; j
{
if(distance[i][j]>distance[i][k]+distance[k][j])
{
distance[i][j]=distance[i][k]+distance[k][j];
}
}
}
}