0
0
DSA Typescriptprogramming~5 mins

Cycle Detection in Directed Graph in DSA Typescript - 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 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?
AFinding a node with no outgoing edges
BFinding a node already in the recursion stack
CFinding a node never visited before
DFinding a node with no incoming edges
Which of these is NOT used in cycle detection in directed graphs?
ARecursion stack
BVisited set
CQueue for BFS
DAdjacency list
What is the purpose of the visited set in cycle detection?
ATo store all edges
BTo mark nodes currently in the path
CTo store the cycle nodes
DTo mark nodes that are fully processed
If no cycle is found, what does the DFS finish with?
AAll nodes visited and no node found in recursion stack twice
BSome nodes unvisited
CRecursion stack never emptied
DCycle nodes stored
What is the main difference between cycle detection in directed and undirected graphs?
ADirected graphs use recursion stack; undirected graphs use parent tracking
BDirected graphs use BFS; undirected graphs use DFS
CDirected graphs have no cycles
DUndirected graphs do not need visited sets
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.