Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band
Directed weighted graph on vertices A, B, C, D with edges C→B (-4); C→A (-1); A→C (1); D→A (-4); A→D (-2); C→D (0). 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. 6
- B. 2
- C. 3
- D. 4
Correct answer: C. 3
After n−1 passes 3 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
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–E (1), B–D (1), B–E (1), C–H (1), D–G (1), D–H (1), E–F (1)…
- Array [12, 23, 8, 18, 15, 14, 26, 13] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the…
- Coins of denominations [11, 9, 8, 3] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 28?…
- Distinct words ['caab', 'ac', 'aa', 'c', 'baab', 'bbb', 'bbca'] are inserted into an empty trie (one node per character, shared prefixes…
- On an 6 × 6 chessboard with rows and columns numbered 0 to 5, a knight starts at (2, 5) and must reach (0, 0) (as (row, column)). A knight…
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…