Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
The directed graph A→B (6), A→C (5), A→D (8), A→E (4), C→B (5), C→E (1), D→B (-3), E→B (2) has one negative edge but no negative cycle. Dijkstra's algorithm runs from A, finalising each vertex exactly once (no updates to finalised vertices). For which vertices is the computed distance WRONG?
- A. None – Dijkstra is still correct
- B. B, C
- C. B, D
- D. B
Correct answer: D. B
True distances (Bellman–Ford): A=0, B=5, C=5, D=8, E=4. Dijkstra finalised A E C B D and gets A=0, B=6, C=5, D=8, E=4; a vertex finalised before the negative edge could improve it keeps a stale value, and so do vertices computed from it.
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
- A directed graph on A–H has edges A→H, B→D, B→E, B→H, C→H, D→C, E→A, E→F, F→A, F→D, G→H. How many strongly connected components does it…
- Unit-time jobs (deadline, profit): J1 (3, 34), J2 (3, 62), J3 (3, 67), J4 (4, 10), J5 (3, 27), J6 (3, 79), J7 (3, 89). One job runs at a…
- Floyd–Warshall runs on vertices 1–4 with directed edges 1→2 (4), 2→3 (11), 2→4 (11), 3→1 (7), 3→2 (6), 3→4 (8), 4→3 (11). After the…
- An undirected connected graph has edges A–B, A–E, B–G, C–G, D–E, D–G, D–I, E–G, E–I, F–H, H–I. How many articulation points (cut vertices)…
- What is the length of the longest common subsequence of MARTIAN and GRAPHICAL, and how many DISTINCT longest common subsequences (as…
- What is the length of the shortest string that has BOTH PLACEMENT and KNAPSACK as subsequences (shortest common supersequence)?