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

Quiz: Matrix Traversal · Question 6 of 13

Why does BFS (not DFS) find the shortest path in an unweighted grid?

Why does BFS (not DFS) find the shortest path in an unweighted grid?

  1. A.BFS uses less memory
  2. B.BFS visits cells in order of their distance from the start
  3. C.DFS cannot move in 4 directions
  4. D.BFS only works on square grids
Answer & explanation

Correct answer: BFS visits cells in order of their distance from the start

The queue processes all cells at distance d before any at distance d + 1, so the first time a cell is reached is by a shortest path.

Can you get the rest right without peeking?

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

Start the quiz →