In mathematics, computer science and digital electronics, a dependency graph is a directed graph representing dependencies of several objects towards each other.
It is possible to derive an evaluation order or the absence of an evaluation order that respects the given dependencies from the dependency graph.
the transitive reduction of R. For example, assume a simple calculator.
You can derive this relation directly: A depends on B and C, because you can add two variables if and only if you know the values of both variables.
Since B depends on D to be calculated, A must also depend on D to be calculated before it (hence the transitive property stated above).
On the other hand, the values of C and D are known immediately, because they are number literals.
In a dependency graph, cycles of dependencies (also called circular dependencies) lead to a situation in which no valid evaluation order exists, because none of the objects in the cycle may be evaluated first.
If a dependency graph does not have any circular dependencies, it forms a directed acyclic graph, and an evaluation order may be found by topological sorting.
Most topological sorting algorithms are also capable of detecting cycles in their inputs; however, it may be desirable to perform cycle detection separately from topological sorting in order to provide appropriate handling for the detected cycles.
Assume the simple calculator from before.
of the objects that form the nodes of the dependency graph so that the following equation holds:
This means, if the numbering orders two elements
There can be more than one correct evaluation order.
In fact, a correct numbering is a topological order, and any topological order is a correct numbering.
Thus, any algorithm that derives a correct topological order derives a correct evaluation order.
Assume the simple calculator from above once more.
Given the equation system "A = B+C; B = 5+D; C=4; D=2;", a correct evaluation order would be (D, C, B, A).
However, (C, D, B, A) is a correct evaluation order as well.
An acyclic dependency graph corresponds to a trace of a trace monoid as follows:[1]: 12 Then the string consisting of the vertex labels ordered by a correct evaluation order corresponds to a string of a trace.
takes the disjoint union
of two graphs' vertex sets, preserves the existing edges in each graph, and draws new edges from the first to the second where the dependency relation allows,[1]: 14 The identity is the empty graph.