Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Each cell of a grid with 5 rows and 3 columns has an arrow: R = right, L = left, U = up, D = down. URU LDU DRL RLD DUU From a cell you may move to any of its four side-adjacent cells. Moving in the direction of the cell's arrow costs 0; moving in any other direction costs 1. What is the minimum total cost from the top-left cell to the bottom-right cell?
- A. 4
- B. 2
- C. 3
- D. 6
Correct answer: C. 3
A 0-1 BFS (cost 0 along the arrow, 1 otherwise) gives 3. Ignoring the arrows and counting moves gives 6, and the number of cells whose arrow is not R or D gives 8.
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
- An undirected graph has the vertices B, C, D, E, I, M, R, S, V and the edges S–B, I–M, I–V, R–M, R–D, R–V, R–C, D–C, V–C, E–B, B–C. What…
- An undirected graph has the vertices C, D, K, M, Q, V and the edges Q–D, Q–M, C–D, K–D, K–V, D–M, D–V. What is the size of a maximum…
- Cities F, M, O, R, S are joined by roads with these travel costs: M–O 11, M–S 20, M–R 7, M–F 16, O–S 16, O–R 14, O–F 8, S–R 11, S–F 8, R–F…
- A tree has the vertices D, F, I, O, Q, R, S, U, X and the edges I–S, I–U, I–O, I–D, D–X, D–F, U–Q, X–R. What is the minimum number of…
- A tree on the vertices E, H, K, S, U, X has the arcs E→S, S→H, H→K, U→H, X→K (each undirected edge is directed as shown). You may reverse…
- A directed graph has the vertices E, G, L, N, U and the arcs N→L, N→E, N→G, L→N, L→E, U→N, U→L, U→E, U→G, E→L, E→U, E→G, G→U, G→E. Count…