Data Structures & AlgorithmsVery hardGATE CS
Floyd–Warshall runs on vertices 1–4 with directed edges 1→2 (4), 2→3 (11), 2→4 (11), 3→1 (7), 3→2 (6), 3→4 (8), 4→3 (11). After the outer-loop iterations k = 1 and k = 2 only (paths may use only 1 and 2 as intermediates), what are D[1][3] and D[4][2]?
- A. ∞ and ∞
- B. 15 and 17
- C. ∞ and 17
- D. 15 and ∞
Correct answer: D. 15 and ∞
After phase k, D[i][j] is the shortest path using only vertices 1..k as intermediates. With 1 and 2 allowed, D[1][3] = 15 and D[4][2] = ∞; the final all-pairs values can be smaller still.
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 connected graph has edges A–B, A–E, B–G, C–G, D–E, D–G, D–I, E–G, E–I, F–H, H–I. How many articulation points (cut vertices)…
- What is the length of the longest common subsequence of MARTIAN and GRAPHICAL, and how many DISTINCT longest common subsequences (as…
- What is the length of the shortest string that has BOTH PLACEMENT and KNAPSACK as subsequences (shortest common supersequence)?
- Keys 28, 36, 45, 51, 56 are searched with frequencies 2, 3, 8, 7, 8 respectively (only successful searches). The cost of a BST is Σ…
- The weighted undirected graph A–B (1), A–D (6), A–E (4), B–C (6), B–D (4), C–D (1), C–E (4) has repeated weights. How many different…
- A 4-ary max-heap is stored in a 0-indexed array (children of i at 4i + 1 … 4i + 4): [56, 50, 20, 30, 4, 3, 9, 27, 5, 1]. After inserting…