GATE Computer ScienceVery hardGATE CSE
Floyd–Warshall is run on a 5-vertex digraph (vertices 0..4) with arc weights 0→1:3, 0→3:7, 1→0:8, 1→2:2, 2→0:5, 2→3:1, 3→0:2, 3→4:4 (no other arcs). The outer loop runs k = 0,1,2,3,4. What is d[1][4] after the iteration k = 2 has completed, and what is its final value?
- A. ∞ after k=2, 7 at the end
- B. 7 after k=2, 7 at the end
- C. ∞ after k=2, 9 at the end
- D. 8 after k=2, 6 at the end
Correct answer: A. ∞ after k=2, 7 at the end
Reaching vertex 4 requires the arc 3→4, so before k=3 is processed d[1][4] is still ∞ (value ∞); finally 1→2→3→4 = 7.
More Algorithms questions
- In how many ways can a longest strictly increasing subsequence be chosen (counting index sets, not distinct value sequences) from the…
- Randomised quicksort picks the pivot uniformly at random from the current sub-array and each partition of m elements uses exactly m−1…
- Bellman–Ford from source 0 on vertices 0..5 relaxes the directed edges (u→v, w) in this fixed order in every pass: 4→5 (1), 3→4 (1), 2→3…
- The recurrence T(n) = 2T(n/2) + n/log₂ n (with T(1) = 1) has the solution
- Top-down merge sort (split at ⌊n/2⌋, standard merge that stops comparing once one list is exhausted) sorts [38, 27, 43, 3, 9, 82, 10, 15…
- A DFS is run on a directed graph with adjacency lists 0:[1,4], 1:[2,5], 2:[0,3], 3:[1], 4:[5,6], 5:[3], 6:[4,5], 7:[3,6]. Vertices are…