Data Structures & AlgorithmsHardGATE CS
In the grid 11111 / 11112 / 11121 / 11111 (rows top to bottom; 2 = rotten, 1 = fresh, 0 = empty), every minute each rotten orange rots its fresh 4-neighbours. After how many minutes are no fresh oranges left?
- A. 6
- B. 4
- C. 5
- D. 7
Correct answer: C. 5
This is a multi-source BFS: put ALL rotten cells in the queue at time 0; the answer is the largest BFS distance to a fresh cell, 5. Running BFS from one rotten orange only overstates it.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A B-tree has minimum degree t = 3 (every non-root node has between 2 and 5 keys) and height 2 (a root-only tree has height 0). What are…
- In the grid 11111 / 11210 / 21111 / 00111 (rows top to bottom; 2 = rotten, 1 = fresh, 0 = empty), every minute each rotten orange rots its…
- What is the edit distance (insert, delete, substitute; each cost 1) between RECESSION and HEAPSORT?
- Symbols occur with frequencies 3, 4, 13, 27, 35. How many bits does an optimal (Huffman) prefix code need for the whole message, and how…
- Keys 12, 16, 26, 38, 48 are searched with frequencies 10, 1, 8, 8, 11 respectively (only successful searches). The cost of a BST is Σ…
- A min-heap holds 31 distinct keys in a 0-indexed array (a full tree with 5 levels). At how many different indices can the 3rd-smallest key…