Data Structures & AlgorithmsHardGATE CS · ICPC regional · Product Company SDE
A forest has 27 vertices and 2 connected components (trees). How many edges does it have?
- A. 25
- B. 27
- C. 20
- D. 38
Correct answer: A. 25
Each tree has (vertices − 1) edges, so the forest has 27 − 2 = 25.
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 12, 33, 64, 60, 24, 16, 31 are inserted one by one into an empty binary search tree. What is the pre-order traversal?
- Keys 76, 95, 23, 92, 94, 56, 15, 57, 87 are inserted in this order into an empty BST. How many leaf nodes does the tree have?
- An undirected graph has adjacency lists A:BC B:ADE C:ADE D:BC E:BC. Neighbours are always explored in alphabetical order. Which is the DFS…
- How many different spanning trees does the complete graph K7 have (Cayley's formula)?
- Keys 12, 98, 23, 44, 16, 38, 41, 70 are inserted one by one into an empty binary search tree. What is the post-order traversal?
- An undirected graph has edges (u–v: weight) A–B:16, B–C:7, C–D:13, A–E:1, C–F:25, A–C:12, B–F:22, E–D:4. What is the weight of its minimum…