Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
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 (21). 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 E F C D
- B. A B C F E D
- C. F C D B A E
- D. A F C D B E
Correct answer: D. A F C D B E
Choosing the lightest crossing edge each time gives A F C D B E. Choosing the heaviest crossing edge gives A B E F C D, and a BFS sweep gives A B C F E 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
- 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…
- Connected undirected simple graph on vertices 0 to 6 with edges: 0–4, 2–4, 3–4, 0–6, 1–6, 1–2, 1–5. What is the maximum number of edges in…
- Connected undirected simple graph on vertices 0 to 6 with edges: 3–4, 4–6, 2–4, 1–6, 2–6, 0–1, 1–5, 1–4. What is the maximum number of…
- Connected undirected simple graph on vertices 0 to 6 with edges: 3–5, 4–5, 0–5, 2–4, 2–3, 0–1, 0–2, 0–6, 0–3. What is the maximum number…
- Connected undirected simple graph on vertices 0 to 5 with edges: 2–5, 0–2, 1–5, 3–5, 0–5, 0–4. What is the maximum number of edges in a…
- Connected undirected simple graph on vertices 0 to 6 with edges: 0–1, 2–4, 4–5, 1–6, 1–3, 3–5, 1–4, 2–3. What is the maximum number of…