Data Structures & AlgorithmsHardProduct-company MCQ pattern
Bellman–Ford from A relaxes the directed edges in the fixed order C→D (2), B→C (3), A→B (4), A→C (9), B→D (7). After the FIRST full pass, what are the distance estimates of C and D?
- A. C = 9, D = ∞
- B. C = 9, D = 11
- C. C = 7, D = 9
- D. C = 7, D = 11
Correct answer: B. C = 9, D = 11
In pass 1, C→D and B→C do nothing (C and B are still ∞); A→B sets B = 4; A→C sets C = 9; B→D sets D = 4 + 7 = 11. The final values C = 7 (via B) and D = 9 appear only after pass 2, which is why V − 1 passes are needed.
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 has edges 1→2, 2→3, 3→1, 3→4, 4→5, 5→6, 6→4, 6→7, 7→8. How many strongly connected components does it have?
- An undirected graph has edges 1–2, 2–3, 3–1, 3–4, 4–5, 5–6, 6–4, 6–7. How many articulation points (vertices whose removal disconnects the…
- What is the time complexity of g(n)? python def g(n): if n <= 1: return for i in range(n): pass # O(1) g(n // 2) g(n // 2) g(n // 2)
- How many of these statements about DFS are correct? (i) In DFS of an undirected graph, every non-tree edge is a back edge (there are no…
- Keys are inserted into an empty BST in the order 45, 15, 79, 90, 10, 55, 12, 20, 50. What is the postorder traversal? python def insert(t…
- For the same kind of BST, what is the height (edges on the longest root-to-leaf path) after inserting 1, 2, 3, 4, 5, 6, 7 in order, versus…