GATE Computer ScienceHardGATE CS (PYQ pattern)

A grid (S start, T target, # blocked, . free) is searched by BFS with 4-directional moves: S.#..... .##.###. ....#... .##.#.#. ...#..#T What is the length of the shortest path from S to T, and how many cells (including S) are ever enqueued by the BFS (it explores the whole reachable region before stopping)?

  1. A. 17 and 27
  2. B. 15 and 27
  3. C. 15 and 24
  4. D. 13 and 29

Correct answer: B. 15 and 27

BFS distances grow layer by layer; T is at distance 15, and 27 free cells are reachable in total.

More Programming and Data Structures (GATE) questions

Exams that ask this topic