← 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?
- A.BFS uses less memory
- B.BFS visits cells in order of their distance from the start
- C.DFS cannot move in 4 directions
- 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 →