🎙 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 8 of 8

In BFS, when should a node be marked visited to avoid adding it to the queue many times?

In BFS, when should a node be marked visited to avoid adding it to the queue many times?

  1. A.When it is pushed onto the queue
  2. B.When it is popped from the queue
  3. C.After the whole BFS finishes
  4. D.It never needs marking
Answer & explanation

Correct answer: When it is pushed onto the queue

Marking on push ensures each node is enqueued once.

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 →