Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Directed weighted graph on vertices A, B, C, D, E with edges listed in this exact order: D→A (3); B→A (2); E→A (-3); A→B (3); D→E (4); A→D (6); E→C (2). Bellman–Ford from A makes passes over the edge list in that order, relaxing in place (each edge is tried once per pass). Counting the passes from the first, how many passes change at least one distance?
- A. 3
- B. 4
- C. 2
- D. 7
Correct answer: C. 2
The distances settle after 2 passes that change something; one more pass is needed only to confirm nothing changes, and that final pass is not counted.
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
- Keys are inserted in the order 32 20 62 89 57 42 59 into an empty binary search tree. Then the key 32 (which has two children) is deleted…
- Array A = [31, 12, 22, 25, 21, 10, 0, 20, 9]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 25? (A trie with subtree counts answers…
- A binary trie of 6-bit numbers stores the set S = [63, 33, 9, 22, 26, 2, 29]. For the query x = 24, what is the maximum value of x XOR s…
- Bipartite graph with left side {A, B, C, D}, right side {E, F, G, H} and edges A–G, B–E, B–H, D–E, D–F, D–G, D–H. What is the size of a…
- Connected undirected graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–F (1), B–F (1), B–G (1), C–F (1), D–F (1), E–F (1), F–G…
- Array A = [3, 8, 11, 5, 4, 7, 7]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the…