Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Directed weighted graph on vertices A, B, C, D with edges A→C (-2); B→A (3); D→C (0); B→D (5); A→D (2); D→B (-4); C→B (-3). Source A. Run Bellman–Ford for exactly n−1 = 3 passes (each pass tries every edge once). Then, using the distances after those passes and no further updates, how many edges (u→v, w) still satisfy dist[u] + w < dist[v] (with dist[u] finite)?
- A. 3
- B. 2
- C. 1
- D. 7
Correct answer: B. 2
After n−1 passes 2 edges still improve, which means a negative cycle is reachable from the source. Checking one pass early, or counting only negative edges, gives different numbers.
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
- Array A = [3, 4, 4, 1, 4, 3, 1]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- Directed weighted graph on vertices A, B, C, D, E with edges E→C (-3); D→C (-2); D→E (-2); C→B (2); A→D (-2); C→A (2); B→E (-1). Source A…
- Directed weighted graph on vertices C, F, E, D, A (source C, target A) with edges: C→F (5); C→E (7); E→F (-4); F→A (1); E→A (1); C→A (7)…
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 2 5 / 1 3 4. Goal board: 1 2 3 / 4 5 . A move slides a…
- Array [10, 28, 18, 27, 13, 14] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element…
- Array A = [3, 31, 23, 2, 8, 19, 7] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?