Data Structures & AlgorithmsModerateProduct-company MCQ pattern
Prim's algorithm starts at A on the undirected graph with edges A–B (3), A–C (1), B–C (7), B–D (5), C–D (2), C–E (7), D–E (3), D–F (8), E–F (4), B–F (6). If ties are broken in favour of the alphabetically smaller edge, which edge is added THIRD, and what is the MST weight?
- A. A–B (3); total 13
- B. B–D (5); total 15
- C. A–B (3); total 12
- D. D–E (3); total 13
Correct answer: A. A–B (3); total 13
Prim adds A–C (1), then C–D (2); now the cheapest edges leaving {A, C, D} are A–B (3) and D–E (3), and the tie goes to A–B (it is also found first by listing order). Then D–E (3) and E–F (4): 1 + 2 + 3 + 3 + 4 = 13. D–E would be third only with a different tie-break.
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
- An undirected graph on A, B, C, D has edges A–B, B–C, C–D, D–A of weight 1 and a diagonal A–C of weight 2. How many distinct minimum…
- Union-find on elements 0–7 uses union by size (the smaller tree's root points to the larger tree's root; on a tie the second root points…
- Seven distinct keys are stored in a max-heap in a 0-indexed array. Which statement is correct?
- How many of these statements are correct? (i) Building a heap from n elements by bottom-up sift-down takes O(n) time. (ii) Inserting n…
- How many different max-heaps (as arrays) can be formed from 5 distinct keys?
- Keys 50, 30, 70, 20, 40, 60, 80, 65 are inserted into an empty BST, then 50 is deleted by replacing it with its inorder SUCCESSOR. What is…