0
0
DSA Cprogramming~5 mins

Cycle Detection in Directed Graph in DSA C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AVisiting a vertex with only one incoming edge
BVisiting a vertex that is currently in the recursion stack
CVisiting a vertex with no outgoing edges
DVisiting a vertex that was visited in a previous DFS call
Which color represents a vertex that is currently being explored in the color method?
AGray
BWhite
CBlack
DBlue
What is the time complexity of cycle detection using DFS in a directed graph with V vertices and E edges?
AO(V + E)
BO(V^2)
CO(E^2)
DO(V * E)
If no cycle is found in a directed graph, what does that imply about the graph?
AThe graph is a tree
BThe graph is disconnected
CThe graph has no edges
DThe graph is acyclic
Which of the following is NOT a valid method to detect cycles in a directed graph?
ADFS with recursion stack
BColor method with white, gray, black
CBreadth-First Search (BFS) with queue only
DTopological sort failure detection
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.