Dependency Graphs Math Example 2

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

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.

Solution

  1. 1
    Identify edges: ADA \to D, BDB \to D, BEB \to E, CEC \to E, DFD \to F, EFE \to F.
  2. 2
    Nodes with no incoming edges (sources): AA, BB, CC. These can appear in any order among themselves at the start.
  3. 3
    After removing AA, BB, CC: node DD depends on A,BA, B (done) and EE depends on B,CB, C (done), so DD and EE can appear in either order.
  4. 4
    Finally FF must come last since it depends on both DD and EE.
  5. 5
    Valid orderings include: (A,B,C,D,E,F)(A, B, C, D, E, F), (A,C,B,D,E,F)(A, C, B, D, E, F), (B,A,C,E,D,F)(B, A, C, E, D, F), (C,B,A,E,D,F)(C, B, A, E, D, F), and others where the dependency constraints are satisfied.

Answer

Multiple valid orderings, e.g., A,B,C,D,E,F or C,B,A,E,D,F\text{Multiple valid orderings, e.g., } A, B, C, D, E, F \text{ or } C, B, A, E, D, F
When a dependency graph has multiple sources or independent nodes, several topological orderings are valid. The key constraint is that every node must appear after all of its predecessors in the ordering.

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