Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Directed weighted graph on vertices A, B, C, D, E with edges E→C (-3); A→D (-4); A→B (-2); D→B (0); B→C (-2); A→E (-1); E→D (0); B→E (-4). Source A. Run Bellman–Ford for exactly n−1 = 4 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. 2
- B. 8
- C. 6
- D. 1
Correct answer: D. 1
After n−1 passes 1 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 = [5, 6, 5, 4, 3, 8, 4, 6] (indices 0 to 7). Count the non-empty subsets of positions (each position used at most once, subsets…
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 2 4 / 1 5 3. Goal board: 1 2 3 / 4 5 . A move slides a…
- Connected undirected graph on vertices A, B, C, D, E, F with edges A–C (1), A–F (1), B–D (1), C–D (1), C–F (1), D–E (1), D–F (1) (weights…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (2), A–C (1), A–D (3), A–E (1), B–C (2), B–D (2), C–D (2). An edge is…
- Strings a = "baabbc" and b = "accca". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Points A(5,7), B(2,4), C(3,8), D(5,0), E(1,1), F(9,8) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| +…