Data Structures & AlgorithmsHardProduct-company placement
Prim's algorithm starts at F on the weighted undirected graph A–C (28), A–D (6), A–F (3), A–G (7), B–C (14), B–F (26), C–D (21), C–E (19), C–F (8), D–G (5), F–G (23). In what order are the vertices added to the tree?
- A. F A C D G B E
- B. A F D G C B E
- C. F A B C G D E
- D. F A D G C B E
Correct answer: D. F A D G C B E
Prim always adds the cheapest edge leaving the current tree (not the vertex closest to F, which is Dijkstra's rule): edges F–A (3), A–D (6), D–G (5), F–C (8), C–B (14), C–E (19), total 55.
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
- How many topological orderings does the DAG on vertices A–F with edges C→F, D→A, D→F, E→A, F→A, F→B, F→E have?
- A tree on vertices 1–10 has edges 2–1, 3–1, 4–2, 5–2, 6–4, 7–6, 8–3, 9–7, 10–8. What is the size of a minimum DOMINATING set (every vertex…
- What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [13, 15…
- Unit-time jobs (deadline, profit): J1 (2, 63), J2 (1, 38), J3 (2, 38), J4 (4, 52), J5 (2, 86), J6 (1, 75), J7 (1, 40). One job runs at a…
- A rooted tree has 7 nodes with 1 child, 2 nodes with 2 children, 4 nodes with 3 children, 8 nodes with 4 children, and every other node is…
- In how many ways can a convex polygon with 7 vertices be divided into triangles by non-crossing diagonals?