Data Structures & AlgorithmsHardProduct-company MCQ pattern
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 spanning trees does it have?
- A. 3
- B. 4
- C. 8
- D. 1
Correct answer: B. 4
Any MST uses three weight-1 edges (total 3) and never the diagonal. Choosing 3 of the 4 cycle edges can be done in 4 ways, and none of them forms a cycle, so 4 MSTs. 'The MST is unique' holds only when all edge weights are distinct.
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
- 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…
- How many of the 7! insertion orders of the keys 1–7 produce the perfectly balanced BST with root 4, children 2 and 6, and leaves 1, 3, 5, 7?