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?
- A. 6
- B. 10
- C. 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
- Problem: How many integers from 1 to 10^6 have exactly one set bit (power of two)? Run the code. python print(sum(1 for x in range(1, 10 6…
- Problem: What is the maximum number of points on a line among (0,0), (1,1), (2,2), (3,5), (4,4) (collinear with the diagonal)? Run the…
- Problem: What is the time complexity of the Hopcroft-Karp algorithm for maximum matching on V vertices and E edges?
- Problem: Which technique gives the answer to 'minimum number of platforms' by sorting events?
- Problem: Which of these is the standard O(n log n) algorithm for the longest increasing subsequence?
- Problem: What is the standard complexity of computing all pairs of shortest paths in a graph with V vertices using repeated squaring of…