# 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.

## Definition

Given a set of objects $S$ and a transitive relation $R\subseteq S\times S$ with $(a,b)\in R$ modeling a dependency "a needs b evaluated first", the dependency graph is a graph $G=(S,T)$ with $T\subseteq 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\}$ and $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.

## Recognizing impossible evaluations

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.

## Deriving an evaluation order

A correct evaluation order is a numbering $n:S\rightarrow \mathbb {N}$ of the objects that form the nodes of the dependency graph so that the following equation holds: $n(a) with $a,b\in S$ . This means, if the numbering orders two elements $a$ and $b$ so that $a$ will be evaluated before $b$ , then $a$ must not depend on $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.

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.

## Examples

Dependency graphs are used in:

• Automated software installers. They walk the graph looking for software packages that are required but not yet installed. The dependency is given by the coupling of the packages.
• Software build scripts such as Unix Make, Node npm install, php composer, Twitter bower install, or Apache Ant. They need to know what files have changed so only the correct files need to be recompiled.
• In Compiler technology and formal language implementation:
• Instruction Scheduling. Dependency graphs are computed for the operands of assembly or intermediate instructions and used to determine an optimal order for the instructions.
• Dead code elimination. If no side effected operation depends on a variable, this variable is considered dead and can be removed.
• Dynamic Graph Analytics: GraphBolt and KickStarter capture value dependencies for incremental computing when graph structure changes.
• Spreadsheet calculators. They need to derive a correct calculation order similar to that one in the example used in this article.
• Web Forms standards such as XForms to know what visual elements to update if data in the model changes.

Dependency graphs are one aspect of:
{"ft_lang_label":"__label__en","ft_lang_prob":0.8755394,"math_prob":0.9908018,"size":5042,"snap":"2019-26-2019-30","text_gpt3_token_len":1080,"char_repetition_ratio":0.139738,"word_repetition_ratio":0.012771392,"special_character_ratio":0.21717572,"punctuation_ratio":0.13621622,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9990336,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32],"im_url_duplicate_count":[null,null,null,9,null,null,null,8,null,8,null,8,null,8,null,8,null,8,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-07-19T10:26:49Z\",\"WARC-Record-ID\":\"<urn:uuid:57166fb7-7c64-4cd1-951d-44bfe5bffced>\",\"Content-Length\":\"54667\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:49db3c24-985a-4b69-81e6-195fa438f986>\",\"WARC-Concurrent-To\":\"<urn:uuid:aca1095c-1ed1-41a6-b27b-1e59941db0f0>\",\"WARC-IP-Address\":\"208.80.154.224\",\"WARC-Target-URI\":\"https://en.wikipedia.org/wiki/Dependency_graph\",\"WARC-Payload-Digest\":\"sha1:RGCJ23KVHUVUOGET7RCWUYJDHB4PJ3JJ\",\"WARC-Block-Digest\":\"sha1:6IV5S4EX722T6YVEAG2CZJ4MCQGG5SX4\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-30/CC-MAIN-2019-30_segments_1563195526210.32_warc_CC-MAIN-20190719095313-20190719121313-00114.warc.gz\"}"}