Dependency Graphs Examples in Math

Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Dependency Graphs.

This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in Math.

Concept Recap

A dependency graph is a directed graph where nodes are variables and arrows show which variables directly influence which others.

Like a flowchart: A affects B, B affects C. Arrows show dependencies.

Read the full concept explanation โ†’

How to Use These Examples

  • Read the first worked example with the solution open so the structure is clear.
  • Try the practice problems before revealing each solution.
  • Use the related concepts and background knowledge badges if you feel stuck.

What to Focus On

Core idea: A dependency graph draws each variable as a node with arrows showing which variables directly drive which others.

Common stuck point: The procedure for dependency graphs is the easy part; the trap is drawing the arrow toward the variable that's known first. Asking "Are you mapping which variables directly influence which others with directed arrows?" first is what keeps a correct-looking calculation from being attached to the wrong concept.

Sense of Study hint: Ask: Are you mapping which variables directly influence which others with directed arrows?

Worked Examples

Example 1

easy
Three tasks have the following dependencies: Task B depends on Task A, and Task C depends on Task B. Draw the dependency graph and determine a valid execution order.

Answer

Aโ†’Bโ†’CA \to B \to C

First step

1
Identify the dependencies: Aโ†’BA \to B (B depends on A) and Bโ†’CB \to C (C depends on B).

Full solution

  1. 2
    Draw the directed graph: Aโ†’Bโ†’CA \to B \to C. An arrow from XX to YY means XX must be completed before YY.
  2. 3
    Perform a topological sort: start with the node that has no incoming edges (A), then B, then C.
  3. 4
    The valid execution order is A,B,CA, B, C.
A dependency graph is a directed acyclic graph (DAG) where edges represent prerequisite relationships. A topological sort gives a valid ordering that respects all dependencies, ensuring no task is started before its prerequisites are complete.

Example 2

medium
Given the dependencies: DD depends on AA and BB; EE depends on BB and CC; FF depends on DD and EE. Find all valid topological orderings.

Example 3

medium
Tasks Aโ†’BA \to B, Aโ†’CA \to C, Bโ†’DB \to D, Cโ†’DC \to D. What is the minimum number of stages to complete all tasks if independent tasks can run in parallel?

Example 4

medium
Given Aโ†’BA \to B, Aโ†’CA \to C, Bโ†’DB \to D, Cโ†’DC \to D, Dโ†’ED \to E, list one valid topological order.

Example 5

medium
In the DAG with edges Aโ†’BA \to B, Aโ†’CA \to C, Bโ†’DB \to D, Cโ†’DC \to D, Dโ†’ED \to E, what is the longest path length (in edges) from AA to EE?

Example 6

medium
How many distinct topological orderings does the DAG Aโ†’BA \to B, Aโ†’CA \to C have? (No other edges.)

Example 7

medium
Tasks A,B,C,D,E,FA, B, C, D, E, F with dependencies Aโ†’CA \to C, Bโ†’CB \to C, Cโ†’DC \to D, Cโ†’EC \to E, Dโ†’FD \to F, Eโ†’FE \to F. What is the minimum number of parallel stages needed?

Example 8

hard
Given the DAG with edges Aโ†’BA \to B, Aโ†’CA \to C, Bโ†’DB \to D, Cโ†’DC \to D, count all distinct topological orderings.

Example 9

hard
Add the edge Dโ†’AD \to A to the DAG with edges Aโ†’BA \to B, Bโ†’CB \to C, Cโ†’DC \to D. Does a topological order still exist?

Example 10

hard
A dependency graph has nn nodes arranged as a chain v1โ†’v2โ†’โ‹ฏโ†’vnv_1 \to v_2 \to \cdots \to v_n. How many distinct topological orderings are there?

Example 11

challenge
In the DAG Aโ†’BA \to B, Aโ†’CA \to C, Bโ†’DB \to D, Cโ†’DC \to D, Aโ†’EA \to E, Dโ†’ED \to E, count all distinct topological orderings.

Practice Problems

Try these problems on your own first, then open the solution to compare your method.

Example 1

medium
A project has tasks with dependencies: BB depends on AA; CC depends on AA; DD depends on BB and CC. What is the minimum number of time steps needed if independent tasks can run in parallel?

Example 2

hard
Given the dependency graph with edges Aโ†’CA \to C, Aโ†’DA \to D, Bโ†’DB \to D, Bโ†’EB \to E, Cโ†’FC \to F, Dโ†’FD \to F, Eโ†’FE \to F, determine whether adding the edge Fโ†’AF \to A would create a problem, and explain why.

Example 3

easy
In a dependency graph, an arrow goes from AA to BB. Which variable depends on which?

Example 4

easy
In the chain Aโ†’Bโ†’CA \to B \to C, does changing AA affect CC?

Example 5

easy
A formula computes C=A+BC = A + B. Draw the dependency arrows.

Example 6

easy
If AA depends on BB and BB depends on AA, what kind of structure is this?

Example 7

easy
In Aโ†’CA \to C and Bโ†’CB \to C, how many variables directly affect CC?

Example 8

easy
Two variables AA and BB are correlated but neither causes the other; both depend on CC. Draw the arrows.

Example 9

easy
Does correlation between AA and BB guarantee that one depends on the other? Answer yes or no.

Example 10

easy
In a dependency graph, what does it mean if a node has no incoming arrows?

Example 11

medium
Given D=A+BD = A + B and E=Dโ‹…CE = D \cdot C, list every variable that EE depends on, directly or indirectly.

Example 12

medium
In a spreadsheet, cell C1=A1+B1C1 = A1 + B1 and D1=C1โ‹…2D1 = C1 \cdot 2. If A1A1 changes, which cells must be recomputed?

Example 13

medium
A graph has arrows Aโ†’BA \to B, Bโ†’CB \to C, Cโ†’AC \to A. Can the variables be evaluated in a fixed order? Explain.

Example 14

medium
Find a valid evaluation order for C=A+BC = A + B, E=C+DE = C + D, where A,B,DA, B, D are inputs.

Example 15

medium
In the graph Aโ†’BA \to B, Aโ†’CA \to C, Bโ†’DB \to D, Cโ†’DC \to D, what is the in-degree of DD?

Example 16

medium
Variables: rainfall โ†’\to soil moisture โ†’\to crop yield, and temperature โ†’\to crop yield. If only temperature changes, does soil moisture change?

Example 17

medium
Why is reading an arrow backwards a serious error in a dependency graph?

Example 18

medium
In the graph Aโ†’BA \to B, Aโ†’CA \to C, Bโ†’DB \to D, Cโ†’DC \to D, what is the out-degree of AA?

Example 19

medium
Given C=Aโ‹…BC = A \cdot B and E=C+AE = C + A, which inputs does EE depend on?

Example 20

challenge
A system has Aโ†’BA \to B, Aโ†’CA \to C, Bโ†’DB \to D, Cโ†’DC \to D, Dโ†’ED \to E. If AA changes, list all affected variables and give one valid recomputation order.

Example 21

challenge
Two researchers see that ice-cream sales and drowning rates rise together. Model this with a dependency graph and explain why neither causes the other.

Example 22

challenge
A graph claims Aโ†’BA \to B, Bโ†’CB \to C, Cโ†’AC \to A is a valid computation pipeline. Identify the flaw and state the condition needed to fix it.

Example 23

easy
In a dependency graph, the edge Xโ†’YX \to Y means which variable directly influences the other?

Example 24

easy
A formula computes V=IRV = IR. Draw the dependency arrows from inputs to output.

Example 25

easy
A graph has edges Aโ†’BA \to B, Aโ†’CA \to C, Bโ†’DB \to D. List the parents of DD.

Example 26

easy
For z=f(x)+g(y)z = f(x) + g(y), draw the dependency graph and identify the leaf node.

Example 27

medium
A spreadsheet has cells B1=A1+2B1 = A1 + 2, C1=B1โ‹…3C1 = B1 \cdot 3, D1=A1+C1D1 = A1 + C1. List the recompute order if A1A1 changes.

Example 28

medium
Tasks: Aโ†’CA \to C, Bโ†’CB \to C, Cโ†’DC \to D, Cโ†’EC \to E. How many tasks have CC as a direct prerequisite?

Example 29

medium
A function machine has u=x+yu = x + y, v=uโ‹…zv = u \cdot z, w=v+uw = v + u. List the edges of its dependency graph.

Example 30

medium
In a dependency graph, can the same variable appear as both an ancestor and a descendant of another? Answer with justification.

Example 31

medium
A model has Xโ†’YX \to Y, Zโ†’YZ \to Y, Yโ†’WY \to W. Which variables does WW depend on (directly or indirectly)?

Example 32

hard
A build system has files with edges src1โ†’obj1\text{src}_1 \to \text{obj}_1, src2โ†’obj2\text{src}_2 \to \text{obj}_2, obj1โ†’exe\text{obj}_1 \to \text{exe}, obj2โ†’exe\text{obj}_2 \to \text{exe}. If src1\text{src}_1 changes, which targets need rebuilding?

Example 33

hard
A research workflow has Xโ†’YX \to Y, Xโ†’ZX \to Z, Yโ†’WY \to W, Zโ†’WZ \to W. If XX and WW are observed but YY and ZZ are hidden, can we still infer the value of WW when XX changes?

Related Concepts

Background Knowledge

These ideas may be useful before you work through the harder examples.

functional dependency