Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
A connected undirected graph has the vertices E, H, O, P, V, W, X and weighted edges (weights in brackets): E–P (4), O–W (16), X–H (8), V–P (7), O–H (11), E–H (12), X–W (20), V–H (4), E–V (10), O–P (11), O–V (11). What is the total weight of a minimum spanning tree?
- A. 50
- B. 81
- C. 51
- D. 44
Correct answer: A. 50
Kruskal's algorithm (take the cheapest edge that does not form a cycle) gives 50. A heaviest-first spanning tree gives 81, and a shortest-path tree rooted at O gives 61.
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 acyclic graph has the vertices I, K, O, Q, T, U, X, Z and the directed edges K→Z, U→K, U→Z, T→K, X→I, X→K, O→K, T→I, X→U, X→O…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→D (9), S→A (2), S→B (9), S→T (3), A→D (7), A→T…
- A directed acyclic graph has the vertices C, F, K, Q, S, V, W and the directed edges Q→C, V→W, F→C, K→F, V→Q, S→Q, W→F, K→S, K→C, S→C. How…
- An undirected graph has the vertices H, K, N, T, U, X and the edges X–H, X–U, X–K, H–K, N–T, N–U, N–K, U–K. What is its chromatic number…
- Consider this function: python def g(n): if n < 3: return n if n % 2 == 0: return g(n - 3) + g(n - 3) return g(n - 1) - 1 What value does…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…