Data Structures & AlgorithmsVery hardProduct-company placement
The directed graph A→C (5), A→E (7), B→A (5), C→B (5), D→A (5), D→B (-6), E→C (9), E→D (7) 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, D
- C. B, E
- D. B
Correct answer: D. B
True distances (Bellman–Ford): A=0, B=8, C=5, D=14, E=7. Dijkstra finalised A C E B D and gets A=0, B=10, C=5, D=14, E=7; 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
- Kruskal's algorithm runs on the weighted undirected graph A–C (29), A–F (19), A–G (2), B–D (8), B–G (25), C–G (14), D–F (1), E–F (11), E–G…
- How many structurally different binary trees with 5 nodes have height EXACTLY 3 (height = edges on the longest root-to-leaf path)?
- A BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 45?
- Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: E→B (2), E→C (9), D→F (-3), F→A…
- The POSTORDER traversal of a BST with distinct keys is 11, 32, 67, 77, 91, 95, 94, 92, 80, 52. What are the height of the tree (edges on…
- The POSTORDER traversal of a BST with distinct keys is 16, 27, 31, 56, 95, 79, 58, 51, 45, 32. What are the height of the tree (edges on…