Data Structures & AlgorithmsModerateInfosys · Cognizant pattern
A graph has 9 vertices and 3 connected components. How many edges does a minimum spanning FOREST (an MST of every component) contain?
- A. 8
- B. 9
- C. 6
- D. 3
Correct answer: C. 6
A spanning tree of a component with nᵢ vertices has nᵢ − 1 edges; summing over the 3 components gives 9 − 3 = 6. '8' (V − 1) applies only to a connected graph; Kruskal on this graph would stop after accepting 6 edges.
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
- Kahn's algorithm uses a MIN-heap (smallest available vertex first) on the DAG with edges 3→1, 3→4, 2→4, 4→0, 1→0, 5→2. What topological…
- The words bat, bath, bad, ban, band are inserted into an empty trie (one node per character, plus the root). How many nodes does the trie…
- Keys 50, 30, 70, 20, 40, 60, 80, 35, 65, 10 are inserted into an empty BST. How many nodes have EXACTLY one child?
- A climber can take 1 or 3 steps at a time. In how many different ordered ways can a staircase of 7 steps be climbed? (ways(n) = ways(n −…
- Keys 50, 40, 30, 45, 47 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?
- Kruskal's algorithm runs on edges (weight): A–B 4, A–C 3, B–C 2, B–D 5, C–D 7, C–E 8, D–E 6, D–F 9, E–F 4. What is the total weight of the…