Recall & Review
beginner Click to reveal answer
What is a cycle in a directed graph?
A cycle in a directed graph is a path that starts and ends at the same vertex, following the direction of edges.
intermediate Click to reveal answer
Which data structure is commonly used to detect cycles in a directed graph using DFS?
A recursion stack (or call stack) is used along with a visited set to detect back edges indicating cycles.
intermediate Click to reveal answer
What does a back edge represent in DFS traversal of a directed graph?
A back edge points from a node to one of its ancestors in the DFS tree, indicating a cycle.
advanced Click to reveal answer
Why can't we use a simple visited set alone to detect cycles in directed graphs?
Because a node can be visited multiple times in different paths; we need to track nodes in the current recursion stack to detect cycles.
beginner Click to reveal answer
What is the time complexity of cycle detection in a directed graph using DFS?
The time complexity is O(V + E), where V is vertices and E is edges, since each node and edge is visited once.
What indicates a cycle during DFS in a directed graph?
✗ Incorrect
A back edge to a node in the current recursion stack means a cycle exists.
Which of these is NOT needed for cycle detection in a directed graph using DFS?
✗ Incorrect
Queue for BFS is not used in DFS-based cycle detection.
What does the recursion stack track in cycle detection?
✗ Incorrect
The recursion stack tracks nodes in the current DFS path to detect cycles.
If no back edge is found during DFS, what can we conclude?
✗ Incorrect
No back edge means no cycle in the directed graph.
What is the main difference between cycle detection in directed vs undirected graphs?
✗ Incorrect
Directed graphs need recursion stack tracking to detect cycles; undirected graphs use parent tracking.
Explain how DFS can be used to detect a cycle in a directed graph.
Think about tracking nodes currently in the path and revisiting them.
You got /4 concepts.
Describe why a recursion stack is necessary for cycle detection in directed graphs but not in undirected graphs.
Consider how cycles appear differently in directed vs undirected graphs.
You got /4 concepts.
