Data Structures & AlgorithmsVery hardProduct-company placement
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 (9), B→C (5), C→D (-3), A→E (-2), E→D (9), A→D (1). It stops early after the first pass that changes nothing. How many passes change at least one distance, and what is the final distance to F?
- A. 5 passes, dist -2
- B. 3 passes, dist -2
- C. 2 passes, dist -2
- D. 1 pass, dist -2
Correct answer: C. 2 passes, dist -2
Simulate pass by pass in the given edge order: a change can travel along several edges in one pass when they appear in path order, so only 2 passes change something (then one pass confirms nothing changes). Final distances: A=0, B=0, C=5, D=1, E=-2, F=-2.
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
- 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…
- A tree on vertices 1–11 has edges 2–1, 3–2, 4–3, 5–2, 6–3, 7–5, 8–7, 9–6, 10–9, 11–9. What is the size of a maximum independent set (no…
- Edit distance between BINARY and GRAPHICAL where insert and delete cost 1 each but a substitution costs 2: what is the minimum total cost?
- Keys 37, 84, 56, 34, 79, 18, 83, 69, 74 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?
- All suffixes of the string 'abab' are inserted into a character trie (a suffix trie). How many nodes does it have, including the root?