Data Structures & AlgorithmsHardGATE CS · ICPC regional
Floyd–Warshall runs on vertices 1 to 4 with these arcs u→v (weight): 1→2 (1), 1→3 (11), 1→4 (12), 2→1 (12), 2→3 (2), 2→4 (8), 3→1 (7), 3→2 (6). dist[i][i] = 0, dist[i][j] is the arc weight, or ∞ when there is no arc. The outer loop runs over k = 1, 2, … in that order. After the iterations for k = 1 through 2 have finished, what is dist[2][3]?
- A. 2
- B. 3
- C. 1
- D. 4
Correct answer: A. 2
Only intermediate vertices 1 to 2 are allowed in the middle of paths at this point, which gives 2. Stopping one iteration earlier gives 2, and the final distance is 2.
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
- Two unmarked jugs hold 6 litres and 8 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- A tree has the vertices B, E, H, I, Q, R, U, V and the edges V–I, I–H, H–R, H–U, R–B, I–E, U–Q. A centroid is a vertex whose removal…
- A tree on the vertices B, C, D, H, J, T, Z has the arcs T→B, Z→T, B→C, B→D, J→D, J→H (each undirected edge is directed as shown). You may…
- A grid has 4 rows and 4 columns with these values (top to bottom): 9446 8699 5398 3165 A path moves between side-adjacent cells (up, down…
- Floyd–Warshall runs on vertices 1 to 5 with these arcs u→v (weight): 1→2 (4), 1→3 (2), 2→1 (11), 3→1 (8), 3→2 (4), 3→4 (7), 3→5 (4), 4→1…