Recall & Review
beginner
What is the main idea behind Topological Sort using DFS?
It visits each node and explores all its descendants before adding the node to the order. This ensures that all dependencies come before the node itself.
Click to reveal answer
beginner
In Topological Sort using DFS, when do we add a node to the result list?
We add the node after visiting all its neighbors (children), meaning after the recursive DFS calls for its neighbors finish.
Click to reveal answer
intermediate
Why can Topological Sort only be applied to Directed Acyclic Graphs (DAGs)?
Because cycles create circular dependencies, making it impossible to order nodes linearly without conflicts.
Click to reveal answer
beginner
What data structure is commonly used to store the final topological order in DFS approach?
A stack or a list where nodes are pushed after visiting all their descendants, then reversed to get the correct order.
Click to reveal answer
intermediate
How does DFS help detect cycles during Topological Sort?
By keeping track of nodes currently in the recursion stack; if we revisit a node in this stack, a cycle exists.
Click to reveal answer
What type of graph is required for Topological Sort to work?
✗ Incorrect
Topological Sort requires a Directed Acyclic Graph to ensure a valid linear ordering.
In DFS-based Topological Sort, when is a node added to the output list?
✗ Incorrect
Nodes are added after all their neighbors are visited to respect dependencies.
What does a cycle in the graph indicate during Topological Sort?
✗ Incorrect
Cycles mean circular dependencies, so no valid topological order exists.
Which data structure is typically used to store nodes during DFS Topological Sort?
✗ Incorrect
A stack stores nodes after visiting descendants, helping reverse the order for final output.
How can DFS detect a cycle in the graph during Topological Sort?
✗ Incorrect
If a node is found again in the current recursion path, it means a cycle exists.
Explain step-by-step how DFS is used to perform Topological Sort on a graph.
Think about visiting nodes and when to add them to the result.
You got /5 concepts.
Describe why Topological Sort cannot be done on graphs with cycles and how DFS helps identify such cycles.
Focus on the role of recursion stack in DFS.
You got /5 concepts.