Dependency Graphs Math Example 3

Follow the full solution, then compare it with the other examples linked below.

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?

Solution

  1. 1
    Draw the dependency graph: AA has no prerequisites; BB and CC both depend on AA; DD depends on both BB and CC.
  2. 2
    Determine stages by levels: Stage 1: AA (no dependencies). Stage 2: BB and CC (both depend only on AA, so they run in parallel). Stage 3: DD (depends on BB and CC, both completed in Stage 2).
  3. 3
    The critical path is A→B→DA \to B \to D (or A→C→DA \to C \to D), each of length 3. So the minimum number of stages is 33.

Answer

3Β stages3 \text{ stages}
The minimum number of stages equals the length of the longest path (critical path) in the dependency graph. Even though there are 4 tasks, BB and CC can execute in parallel during Stage 2, reducing the total from 4 sequential steps to 3 stages.

About Dependency Graphs

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

Learn more about Dependency Graphs β†’

More Dependency Graphs Examples