🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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:

  1. A.white (unvisited)
  2. B.black (finished)
  3. C.a leaf
  4. 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 →