Dependency Graphs Examples: 44 Problems with Answers

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→C

First step

1
Identify the dependencies: A→B (B depends on A) and B→C (C depends on B).

Full solution

  1. 2
    Draw the directed graph: A→B→C. An arrow from X to Y means X must be completed before Y.
  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,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: D depends on A and B; E depends on B and C; F depends on D and E. Find all valid topological orderings.

Example 3

medium
Tasks A→B, A→C, B→D, C→D. What is the minimum number of stages to complete all tasks if independent tasks can run in parallel?

Example 4

medium
Given A→B, A→C, B→D, C→D, D→E, list one valid topological order.

Example 5

medium
In the DAG with edges A→B, A→C, B→D, C→D, D→E, what is the longest path length (in edges) from A to E?

Example 6

medium
How many distinct topological orderings does the DAG A→B, A→C have? (No other edges.)

Example 7

medium
Tasks A,B,C,D,E,F with dependencies A→C, B→C, C→D, C→E, D→F, E→F. What is the minimum number of parallel stages needed?

Example 8

hard
Given the DAG with edges A→B, A→C, B→D, C→D, count all distinct topological orderings.

Example 9

hard
Add the edge D→A to the DAG with edges A→B, B→C, C→D. Does a topological order still exist?

Example 10

hard
A dependency graph has n nodes arranged as a chain v1→v2→⋯→vn. How many distinct topological orderings are there?

Example 11

challenge
In the DAG A→B, A→C, B→D, C→D, A→E, D→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: B depends on A; C depends on A; D depends on B and C. 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→C, A→D, B→D, B→E, C→F, D→F, E→F, determine whether adding the edge F→A would create a problem, and explain why.

Example 3

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

Example 4

easy
In the chain A→B→C, does changing A affect C?

Example 5

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

Example 6

easy
If A depends on B and B depends on A, what kind of structure is this?

Example 7

easy
In A→C and B→C, how many variables directly affect C?

Example 8

easy
Two variables A and B are correlated but neither causes the other; both depend on C. Draw the arrows.

Example 9

easy
Does correlation between A and B 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+B and E=D⋅C, list every variable that E depends on, directly or indirectly.

Example 12

medium
In a spreadsheet, cell C1=A1+B1 and D1=C1⋅2. If A1 changes, which cells must be recomputed?

Example 13

medium
A graph has arrows A→B, B→C, C→A. Can the variables be evaluated in a fixed order? Explain.

Example 14

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

Example 15

medium
In the graph A→B, A→C, B→D, C→D, what is the in-degree of D?

Example 16

medium
Variables: rainfall → soil moisture → crop yield, and temperature → 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→B, A→C, B→D, C→D, what is the out-degree of A?

Example 19

medium
Given C=A⋅B and E=C+A, which inputs does E depend on?

Example 20

challenge
A system has A→B, A→C, B→D, C→D, D→E. If A 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→B, B→C, C→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→Y means which variable directly influences the other?

Example 24

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

Example 25

easy
A graph has edges A→B, A→C, B→D. List the parents of D.

Example 26

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

Example 27

medium
A spreadsheet has cells B1=A1+2, C1=B1⋅3, D1=A1+C1. List the recompute order if A1 changes.

Example 28

medium
Tasks: A→C, B→C, C→D, C→E. How many tasks have C as a direct prerequisite?

Example 29

medium
A function machine has u=x+y, v=u⋅z, w=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→Y, Z→Y, Y→W. Which variables does W depend on (directly or indirectly)?

Example 32

hard
A build system has files with edges src1→obj1, src2→obj2, obj1→exe, obj2→exe. If src1 changes, which targets need rebuilding?

Example 33

hard
A research workflow has X→Y, X→Z, Y→W, Z→W. If X and W are observed but Y and Z are hidden, can we still infer the value of W when X changes?

Related Concepts

Background Knowledge

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

functional dependency