Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2
Directed weighted graph on vertices A, B, C, D, E, F with edges listed in this exact order: E→D (1); F→D (5); F→C (1); B→E (5); F→A (4); D→B (2); E→C (-1); E→B (-1); A→D (0); C→A (-1). 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. 4
- B. 3
- C. 5
- D. 10
Correct answer: B. 3
The distances settle after 3 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
- Coins of denominations [12, 9, 8, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 18?…
- Array A = [9, 3, 3, 8, 2, 4, 3] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not…
- Rooted tree with root 0 and vertices 0 to 9; the edges are 0–1, 1–2, 1–3, 0–4, 2–5, 5–6, 1–7, 2–8, 6–9 (parent–child). Every edge has…
- A binary tree with distinct letters has preorder ABEDCF and inorder ECDFBA. What is its postorder traversal (left, right, root), written…
- Directed acyclic graph on vertices A, B, C, D, E, F (every edge goes from a smaller to a larger letter) with weighted edges A→D (9), A→E…
- Points A(3,7), B(3,5), C(9,0), D(8,2), E(5,4), F(5,6) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| +…