GATE Computer ScienceVery hardGATE CSE
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 (1), 1→2 (1), 0→1 (1), 0→5 (10). In how many passes does at least one distance change?
- A. 4
- B. 6
- C. 2
- D. 5
Correct answer: D. 5
The path 0→1→2→3→4→5 is discovered one edge per pass against the edge order, and 0→5 only gives the initial value in pass 1; changes occur in 5 passes.
More Algorithms questions
- 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…
- In how many different ORDERED sequences of coins from {1, 4, 5} can a total of exactly 15 be formed (sequences like 1,4 and 4,1 count…
- How many binary strings of length 12 do not contain three consecutive 1s as a substring?
- Five keys k1<k2<k3<k4<k5 are searched with access frequencies 4, 2, 6, 3, 9. For a binary search tree over these keys, with the root at…