Questions: Cycle Detection in Directed and Undirected Graphs

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

During DFS on a directed graph, you are exploring node A (currently gray) and discover an edge to node B, which is black (fully explored). What does this tell you?

AThere is a cycle involving A and B
BB is a forward or cross edge destination — no cycle is indicated
CThe algorithm must backtrack and try a different path
DThis situation cannot occur in a directed graph
Question 2 Multiple Choice

In an undirected graph, DFS visits A, then B (from A), then C (from B). From C, DFS finds that A is already visited. Is there a cycle?

ANo — A is C's grandparent in the DFS tree, which is normal
BYes — A is visited and is not C's direct parent, so the edge C→A is a back edge revealing a cycle
COnly if A is also connected to D
DNo — in undirected graphs, revisiting any node during DFS is expected and harmless
Question 3 True / False

In a directed graph, any edge leading from a gray node to a previously visited node is evidence of a cycle.

TTrue
FFalse
Question 4 True / False

The two-state (visited/unvisited) DFS approach sufficient for undirected cycle detection works equally well for directed graphs.

TTrue
FFalse
Question 5 Short Answer

Why does directed cycle detection require three vertex states (white, gray, black) rather than the two states (visited/unvisited) that suffice for undirected graphs?

Think about your answer, then reveal below.