Recall & Review
beginner
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.
Click to reveal answer
beginner
Which data structure is commonly used to detect cycles in a directed graph using DFS?
A recursion stack (or call stack) is used to keep track of vertices in the current path during DFS to detect cycles.
Click to reveal answer
intermediate
What does it mean if a node is found in the recursion stack during DFS?
It means a cycle is detected because the node is already in the current path of traversal.
Click to reveal answer
intermediate
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; only tracking nodes in the current path (recursion stack) can detect cycles.
Click to reveal answer
intermediate
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, because each vertex and edge is visited once.
Click to reveal answer
What indicates a cycle during DFS in a directed graph?
✗ Incorrect
A cycle is detected if a node is found in the recursion stack, meaning it is part of the current path.
Which of these is NOT used in cycle detection in directed graphs?
✗ Incorrect
Cycle detection in directed graphs commonly uses DFS with recursion stack and visited set, not BFS queue.
What is the purpose of the visited set in cycle detection?
✗ Incorrect
The visited set marks nodes that have been fully processed to avoid reprocessing.
If no cycle is found, what does the DFS finish with?
✗ Incorrect
If DFS finishes visiting all nodes without finding a node in recursion stack twice, no cycle exists.
What is the main difference between cycle detection in directed and undirected graphs?
✗ Incorrect
Directed graphs detect cycles using recursion stack; undirected graphs detect cycles by checking visited nodes excluding the parent.
Explain how DFS with recursion stack helps detect cycles in a directed graph.
Think about how the current path is remembered during DFS.
You got /4 concepts.
Describe the difference between visited set and recursion stack in cycle detection.
Consider what each set tracks during DFS.
You got /4 concepts.