These examples are designed to step through the logical process of applying DAG and SCC concepts.
Example 1: Topological Sort (DFS)
❓ Problem: DAG: A→B, A→C, B→D, C→D. Give a valid topological order using DFS.
💡 Solution: DFS from A: Visit B→D (D finishes, B finishes), Visit C (C finishes), A
finishes. Order by decreasing finish: A, C, B, D (or A, B, C, D also valid).
❓ Problem: Does every DAG have a source (in-degree 0)?
💡 Solution: Yes. If no source existed, following backward edges would eventually
revisit a node, creating a cycle—contradicting the DAG property.
Example 6: Uniqueness of Topological Sort
❓ Problem: Is the topological sort of a DAG unique?
💡 Solution: No. If two nodes have no dependency between them, their order can be
swapped. Example: nodes A, B with no edges—both A,B and B,A are valid.