language-icon Old Web
English
Sign In

Dependency graph

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. 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. Given a set of objects S {displaystyle S} and a transitive relation R ⊆ S × S {displaystyle Rsubseteq S imes S} with ( a , b ) ∈ R {displaystyle (a,b)in R} modeling a dependency 'a needs b evaluated first', the dependency graph is a graph G = ( S , T ) {displaystyle G=(S,T)} with T ⊆ R {displaystyle Tsubseteq R} and T being the transitive reduction of R. For example, assume a simple calculator. This calculator supports assignment of constant values to variables and assigning the sum of exactly 2 variables to a third variable. Given several equations like 'A = B+C; B = 5+D; C=4; D=2;', then S = { A , B , C , D } {displaystyle S={A,B,C,D}} and R = { ( A , B ) , ( A , C ) , ( B , D ) } {displaystyle R={(A,B),(A,C),(B,D)}} . 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. Thus, B must be calculated before A can be calculated. However, the values of C and D are known immediately, because they are number literals. In a dependency graph, the 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. The equation system 'A=B; B=D+C; C=D+A; D=12;' contains a circular dependency formed by A, B and C, as B must be evaluated before A, C must be evaluated before B and A must be evaluated before C. A correct evaluation order is a numbering n : S → N {displaystyle n:S ightarrow mathbb {N} } of the objects that form the nodes of the dependency graph so that the following equation holds: n ( a ) < n ( b ) ⇒ ( a , b ) ∉ R {displaystyle n(a)<n(b)Rightarrow (a,b) otin R} with a , b ∈ S {displaystyle a,bin S} . This means, if the numbering orders two elements a {displaystyle a} and b {displaystyle b} so that a {displaystyle a} will be evaluated before b {displaystyle b} , then a {displaystyle a} must not depend on b {displaystyle b} . 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.

[ "Graph", "Graph (abstract data type)", "Dependency inversion principle" ]
Parent Topic
Child Topic
    No Parent Topic