Data Structures & AlgorithmsModerateCognizant · Capgemini pattern
An undirected graph has edges A–B (2), A–C (3), B–C (1), B–D (4), C–D (5), C–E (6), D–E (2). What is the total weight of its minimum spanning tree?
- A. 12
- B. 10
- C. 9
- D. 8
Correct answer: C. 9
Kruskal takes B–C (1), A–B (2), D–E (2), skips A–C (3) because it closes a cycle, then takes B–D (4): 1 + 2 + 2 + 4 = 9. Taking A–C instead of A–B, or forgetting to skip it, gives 10 or 12.
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 DAG has edges A→B, A→C, B→D, C→D, D→E. How many different topological orderings does it have?
- How many structurally different binary search trees can be built from 4 distinct keys?
- Using the master theorem, what is the solution of T(n) = 4T(n/2) + n²?
- What is the solution of T(n) = T(n/3) + T(2n/3) + n?
- What is the length of the longest common subsequence of ALGORITHM and LOGARITHM?
- What is the edit distance (insert, delete, replace, each cost 1) between FLASK and FLOSSY?