Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
Undirected weighted graph on letters A to E with edges: B–C (1), A–E (20), A–C (26), A–B (39), D–E (31), A–D (8), B–E (7), C–E (24). Starting from A, Prim's algorithm repeatedly adds the cheapest edge that leaves the tree together with its new vertex. In what order are the vertices added, starting with A?
- A. A B C E D
- B. A E C B D
- C. A D E B C
- D. E B C A D
Correct answer: C. A D E B C
Choosing the lightest crossing edge each time gives A D E B C. Choosing the heaviest crossing edge gives A B C E D, and a BFS sweep gives A E C B D; both are common slips.
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
- Undirected weighted graph on letters A to E with edges: C–D (29), D–E (38), A–D (34), A–C (14), C–E (37), B–E (5), B–C (23), A–E (19), B–D…
- Undirected weighted graph on letters A to F with edges: B–D (31), A–B (18), B–E (23), B–F (14), C–F (15), E–F (30), A–D (6), B–C (33), C–D…
- Undirected weighted graph on letters A to E with edges: A–E (4), C–E (28), C–D (35), A–D (21), B–D (15), B–C (20), A–C (2), A–B (7)…
- Undirected weighted graph on letters A to E with edges: D–E (17), A–B (4), B–C (38), A–D (34), C–E (18), B–E (16), A–E (21), A–C (2), B–D…
- Undirected weighted graph on letters A to F with edges: A–B (31), C–F (5), B–E (36), A–C (22), E–F (35), B–D (2), A–F (20), C–D (13), A–E…
- Connected undirected simple graph on vertices 0 to 6 with edges: 5–6, 0–1, 0–3, 0–6, 3–6, 1–4, 1–2, 1–5. What is the maximum number of…