Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B
A connected undirected graph has the vertices E, F, I, Q, S, Z and weighted edges (weights in brackets): E–I (3), F–E (8), Z–S (12), S–I (7), F–I (13), Q–E (17), Z–F (4), Q–I (20), F–Q (18). What is the total weight of a minimum spanning tree?
- A. 39
- B. 34
- C. 45
- D. 40
Correct answer: A. 39
Kruskal's algorithm (take the cheapest edge that does not form a cycle) gives 39. A heaviest-first spanning tree gives 74, and a shortest-path tree rooted at Z gives 45.
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 weighted graph has the arcs u→v (weight): Z→G (12), G→Z (1), G→T (11), G→A (3), G→S (7), T→Z (11), T→M (1), A→Z (13), A→T (11)…
- 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…
- An undirected connected graph on the vertices B, M, Q, R, U has the edges B–U, M–R, Q–R, M–Q, B–R, B–M, Q–U, B–Q. How many spanning trees…
- Each cell of a grid with 3 rows and 3 columns has an arrow: R = right, L = left, U = up, D = down. LUL LRD RUU From a cell you may move to…
- A directed graph has the vertices B, D, E, M, Y and the arcs B→M, B→E, B→D, B→Y, M→B, M→E, M→D, E→B, E→Y, D→B, D→M, D→E, D→Y, Y→M. Count…
- An undirected graph has the vertices C, P, T, X and the edges T–P, C–P, C–X, P–X. In how many ways can each vertex be given one of 3…