Data Structures & AlgorithmsHardProduct-company placement
Prim's algorithm starts at E on the weighted undirected graph A–C (13), A–D (1), A–G (11), B–D (16), B–G (6), C–D (14), C–E (18), C–F (28), C–G (9), D–F (19), F–G (4). In what order are the vertices added to the tree?
- A. E C G A F D B
- B. E C G F B A D
- C. A D F G B C E
- D. E C A D F G B
Correct answer: B. E C G F B A D
Prim always adds the cheapest edge leaving the current tree (not the vertex closest to E, which is Dijkstra's rule): edges E–C (18), C–G (9), G–F (4), G–B (6), G–A (11), A–D (1), total 49.
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
- Keys 53, 59, 94, 71, 34, 76, 82, 15, 62, 24 are inserted in order into an empty AVL tree. Counting a double rotation as two single…
- With 2 identical eggs and at most 6 drops, what is the largest number of floors for which you can always determine the critical floor (the…
- How many subsets of {1, 3, 4, 5, 8, 10, 13} have sum exactly 20?
- Five matrices have dimensions 12×5 , 5×12 , 12×10 , 10×3 , 3×5. What is the minimum number of scalar multiplications needed to compute…
- A rod of length 8 can be cut into integer pieces; a piece of length i sells for p(i) with p(1..8) = 2, 8, 10, 13, 21, 22, 25, 28. What is…
- What is the minimum number of cuts needed to split 'abacdcab' into pieces that are all palindromes?