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)?
- A. 17 and 27
- B. 15 and 27
- C. 15 and 24
- 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.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- How many 10-bit unsigned values x (0 to 1023) have no two adjacent 1 bits, where bit 9 and bit 0 also count as adjacent (the bits are…
- unsigned g(unsigned n) { return n ^ (n >> 1); } For which 8-bit n is g(n) == 0xB5? Give n in decimal.
- A routine compresses runs in place: each maximal run of a repeated character c of length L becomes c if L = 1, else c followed by the…
- A 4 x 6 matrix (4 rows, 6 columns) holds 1 to 24 in row-major order. Its elements are visited in an anticlockwise spiral that starts at…
- int a[] = {1,1,2,2,2,3,4,4,5,5,5,5,6}; int w = 2; for (int i = 2; i < 13; i++) if (a[i] != a[w - 2]) a[w++] = a[i]; What is w after the…
- int p[10] = {1}; for (int r = 1; r <= 8; r++) for (int j = r; j >= 1; j--) p[j] += p[j - 1]; How many of p[0..8] are odd, and what is p[3]…