Data Structures & AlgorithmsHardGATE CS · Product-company placement
Prim's algorithm starts at D on the weighted undirected graph A–D (23), A–F (5), A–G (28), B–C (17), B–E (15), B–G (2), C–E (21), C–G (18), D–E (1), D–G (3), F–G (22). In what order are the vertices added to the tree?
- A. D E G B C F A
- B. D E G B C A F
- C. D E B G A F C
- D. D A E G F B C
Correct answer: A. D E G B C F A
Prim always adds the cheapest edge leaving the current tree (not the vertex closest to D, which is Dijkstra's rule): edges D–E (1), D–G (3), G–B (2), B–C (17), G–F (22), F–A (5), total 50.
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
- A binary search tree holds exactly the keys 41, 50, 62, 63, 68, 69, 74, 94. Which ONE of the following can be its POSTORDER traversal?
- A 4-ary max-heap is stored in a 0-indexed array (children of i at 4i + 1 … 4i + 4): [58, 57, 54, 33, 11, 34, 22, 42, 30, 19]. After…
- Keys 33, 11, 72, 19, 76, 71, 31, 74, 40, 37, 45 are inserted in that order into an empty BST. Then 33 is deleted and after that 37 is…
- Keys 90, 94, 89, 30, 62, 17, 99, 53 inserted in this order build a BST. How many of the 8! orderings of these same 8 keys, inserted into…
- A binary search tree holds exactly the keys 13, 19, 20, 36, 71, 73, 94, 99. Which ONE of the following sequences can be its PREORDER…
- A BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 44?