Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
The directed graph A→C (4), A→E (5), B→A (6), C→B (8), D→C (1), E→B (9), E→C (-6), E→D (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, E
- C. C
- D. B, C
Correct answer: D. B, C
True distances (Bellman–Ford): A=0, B=7, C=-1, D=7, E=5. Dijkstra finalised A C E D B and gets A=0, B=12, C=4, D=7, E=5; 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
- Prim's algorithm starts at F on the weighted undirected graph A–C (28), A–D (6), A–F (3), A–G (7), B–C (14), B–F (26), C–D (21), C–E (19)…
- How many topological orderings does the DAG on vertices A–F with edges C→F, D→A, D→F, E→A, F→A, F→B, F→E have?
- A tree on vertices 1–10 has edges 2–1, 3–1, 4–2, 5–2, 6–4, 7–6, 8–3, 9–7, 10–8. What is the size of a minimum DOMINATING set (every vertex…
- What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [13, 15…
- Unit-time jobs (deadline, profit): J1 (2, 63), J2 (1, 38), J3 (2, 38), J4 (4, 52), J5 (2, 86), J6 (1, 75), J7 (1, 40). One job runs at a…
- A rooted tree has 7 nodes with 1 child, 2 nodes with 2 children, 4 nodes with 3 children, 8 nodes with 4 children, and every other node is…