Transitive closure, that is, in mathematicsBinary relationThe transitive closure of R is the smallest on X containing RTransitive 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".
For any relation R, the transitive closure of R always exists.Transitive relationshipOf any familyintersectionIt 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 containingTransitive relationshipIt 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: aRAe1RARAe(n-1)RAb。
However, via GA on RATransitivity, 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 twoTransitive relationshipThe union of does not have to be transitive.To maintain transitivity, you must use transitive closures.For example, this occurs when taking twoequivalence 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 strictPartial order。
Relationship with complexity
Announce
edit
stayComputational complexity theoryMedium,ComplexityClass NL strictly corresponds to availableFirst-order logicAnd 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.InSecond-order logicWhen 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 isFloyd-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 fromnodeThe 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 adjacencymatrixTo store the diagram.
This algorithm is easy to implement, only a few lines.
Even if the problem isSingle source shortest pathIt 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).