🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Graphs Quiz: all 8 questions

Graphs Quiz · Question 1 of 8

Why do graph traversals need a "visited" set when tree traversals usually don't?

Why do graph traversals need a "visited" set when tree traversals usually don't?

  1. A.Graphs can contain cycles, so without it you could loop forever
  2. B.Graphs always have more nodes
  3. C.Visited sets make BFS faster than DFS
  4. D.Trees can't be traversed with DFS
Answer & explanation

Correct answer: Graphs can contain cycles, so without it you could loop forever

Trees have no cycles; graphs may, so you must remember where you've been.

Can you get the rest right without peeking?

Take the timed Graphs Quiz quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →