Data Structures & AlgorithmsVery hardProduct-company placement
The directed graph A→B (4), A→C (5), A→E (3), B→D (6), B→E (-3), C→E (7), D→C (1), 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. C, D, E
- C. D, E
- D. B, C, D, E
Correct answer: B. C, D, E
True distances (Bellman–Ford): A=0, B=4, C=4, D=3, E=1. Dijkstra finalised A E B C D and gets A=0, B=4, C=5, D=5, E=3; 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
- Dijkstra's algorithm runs from A on the directed graph A→C (15), A→D (3), B→E (4), B→F (12), C→B (12), C→E (1), D→B (2), D→C (9), E→A…
- Heap sort (ascending) is run on [44, 9, 47, 27, 1, 46, 30, 10]: build a max-heap bottom-up, then repeatedly swap the root with the last…
- A binary search tree holds exactly the keys 17, 22, 27, 39, 40, 92, 97, 98. Which ONE of the following can be its POSTORDER traversal?
- A BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 58?
- What is the length of the longest common subsequence of MATRIX and MARTIAN, and how many DISTINCT longest common subsequences (as strings)…
- Lectures occupy half-open intervals [start, end): [3, 10), [6, 10), [7, 12), [9, 11), [10, 15), [10, 17), [10, 18), [20, 25). A lecture…