Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the minimum number of edges to remove from a 5-vertex complete graph to leave a spanning tree? Run the code (answer = E - (V - 1)).

Problem: What is the minimum number of edges to remove from a 5-vertex complete graph to leave a spanning tree? Run the code (answer = E - (V - 1)).
V = 5
E = V * (V - 1) // 2
print(E - (V - 1))
What is printed?
  1. A. 6
  2. B. 10
  3. C. 4
  4. D. 125

Correct answer: A. 6

K5 has 10 edges and a spanning tree keeps V − 1 = 4, so 6 must go. 10 is the edge count, 4 is the tree size, and 5³ = 125 (Cayley) counts the spanning trees.

More Coding Interview Problems questions

Exams that ask this topic