← Quiz: Topological Sort: all 15 questions
Quiz: Topological Sort · Question 6 of 15
In DFS-based cycle detection with three colours, a cycle is found when DFS reaches a node that is:
In DFS-based cycle detection with three colours, a cycle is found when DFS reaches a node that is:
- A.white (unvisited)
- B.black (finished)
- C.a leaf
- D.gray (still on the current DFS path)
Answer & explanation
Correct answer: gray (still on the current DFS path)
A gray node is an ancestor on the current path, so the edge back to it closes a cycle. Black nodes are already finished.
Can you get the rest right without peeking?
Take the timed Quiz: Topological Sort quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →