Data Structures & AlgorithmsHardInfosys · Wipro pattern
Kruskal's algorithm runs on edges (weight): A–B 4, A–C 3, B–C 2, B–D 5, C–D 7, C–E 8, D–E 6, D–F 9, E–F 4. What is the total weight of the MST?
- A. 20
- B. 19
- C. 22
- D. 24
Correct answer: A. 20
Sorted edges: B–C 2 ✓, A–C 3 ✓, A–B 4 ✗ (cycle), E–F 4 ✓, B–D 5 ✓, D–E 6 ✓ (joins {A,B,C,D} with {E,F}); 5 edges for 6 vertices – done. 2 + 3 + 4 + 5 + 6 = 20. Accepting A–B instead of skipping it inflates the total; picking C–D 7 instead of D–E gives a non-spanning result.
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
- 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…
- 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?…