Data Structures & AlgorithmsHardProduct-company placement
Prim's algorithm starts at G on the weighted undirected graph A–B (19), A–F (12), A–G (21), B–C (13), B–D (23), B–E (6), B–G (29), D–E (11), D–F (27), D–G (3), F–G (2). In what order are the vertices added to the tree?
- A. G F D A E B C
- B. F G D B E A C
- C. G F D E B A C
- D. G A B D F C E
Correct answer: C. G F D E B A C
Prim always adds the cheapest edge leaving the current tree (not the vertex closest to G, which is Dijkstra's rule): edges G–F (2), G–D (3), D–E (11), E–B (6), F–A (12), B–C (13), total 47.
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
- The weighted undirected graph A–B (1), A–C (6), A–D (3), A–E (4), B–C (4), B–D (3), C–D (5) has repeated weights. How many different…
- A simple undirected graph has 9 vertices and exactly 4 connected components. What is the maximum possible number of edges?
- With 3 identical eggs and at most 6 drops, what is the largest number of floors for which you can always determine the critical floor (the…
- A 4 × 4 grid has rows 1 3 8 3 / 7 6 6 2 / 4 9 8 9 / 9 8 4 5. Moving only right or down from the top-left to the bottom-right cell, what is…
- Keys 85, 36, 65, 27, 34, 80, 17, 66, 97, 68 are inserted in order into an empty AVL tree. Counting a double rotation as two single…
- A rooted tree has 2 nodes with 1 child, 6 nodes with 2 children, 5 nodes with 3 children, and every other node is a leaf. How many leaves…