Data Structures & AlgorithmsHardProduct company OA
Bellman–Ford from S relaxes the directed edges in this fixed order in every pass: C→D (1), B→C (2), A→B (3), S→A (4). How many passes are needed until a pass makes NO change (count that final quiet pass too)?
- A. 4
- B. 5
- C. 2
- D. 1
Correct answer: B. 5
Edges are listed against the path order, so each pass extends the known path by just one edge: pass 1 sets A, pass 2 B, pass 3 C, pass 4 D, and pass 5 changes nothing. With the order S→A, A→B, B→C, C→D everything would settle in pass 1, and pass 2 would be the quiet one.
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 min-heap of size k = 3 tracks the 3 largest values of the stream 5, 1, 9, 3, 7, 8, 2 (push each value; if the size exceeds 3, pop the…
- An undirected graph has edges 1–2, 2–3, 3–1, 3–4, 4–5, 5–6, 6–4, 6–7, 7–8. How many BRIDGES (edges whose removal disconnects the graph)…
- Keys 20, 8, 22, 4, 12, 10, 14, 25 are inserted into an empty BST. What is the lowest common ancestor of 10 and 14, and of 4 and 14?
- Keys 50, 30, 70, 20, 40, 60, 80, 35, 45, 65 are inserted into an empty BST. A range query counts keys in [33, 62], pruning subtrees that…
- A robot moves only right or down from the top-left to the bottom-right cell of this 4 × 4 grid ('#' is blocked). How many paths are there?…
- DFS-based topological sort on the DAG with adjacency lists a: [b, c], b: [d], c: [d, e], d: [f], e: [f], f: [] starts at a, visits…