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 structures are commonly used to detect cycles in a directed graph?
Depth-First Search (DFS) with recursion stack or colors (white, gray, black) is commonly used to detect cycles in directed graphs.
Click to reveal answer
intermediate
What does the recursion stack represent in DFS cycle detection?
The recursion stack keeps track of vertices currently in the path of DFS. If a vertex is revisited while still in the recursion stack, a cycle exists.
Click to reveal answer
intermediate
Explain the color method for cycle detection in directed graphs.
Vertices are colored white (unvisited), gray (visited but not finished), or black (finished). Encountering a gray vertex during DFS means a cycle is detected.
Click to reveal answer
intermediate
Why can't we use simple visited arrays alone to detect cycles in directed graphs?
Because revisiting a vertex that is already visited but not in the current DFS path does not mean a cycle. We need to track the current path (recursion stack or colors) to detect cycles.
Click to reveal answer
What indicates a cycle during DFS in a directed graph?
✗ Incorrect
A cycle is detected if DFS visits a vertex that is still in the recursion stack (current path).
Which color represents a vertex that is currently being explored in the color method?
✗ Incorrect
Gray means the vertex is visited but DFS has not finished exploring all its descendants.
What is the time complexity of cycle detection using DFS in a directed graph with V vertices and E edges?
✗ Incorrect
DFS visits each vertex and edge once, so the time complexity is O(V + E).
If no cycle is found in a directed graph, what does that imply about the graph?
✗ Incorrect
No cycle means the graph is acyclic, also called a Directed Acyclic Graph (DAG).
Which of the following is NOT a valid method to detect cycles in a directed graph?
✗ Incorrect
BFS alone cannot detect cycles in directed graphs without additional mechanisms.
Describe how DFS can be used to detect a cycle in a directed graph.
Think about how to know if a vertex is revisited in the current path.
You got /4 concepts.
Explain the difference between visited array and recursion stack in cycle detection.
Focus on why just knowing if a vertex was visited before is not enough.
You got /4 concepts.