Question
Let be a weighted undirected graph and let be a Minimum Spanning Tree (MST) of maintained using adjacency lists. Suppose a new weighted edge is added to . The worst case time complexity of determining if is still an MST of the resultant graph is
Official answer and solution
- Official answer
- D
- From
- Official GATE 2020 answer key
Solution
Use the Cycle Property of Minimum Spanning Trees to analyze the complexity of checking the new edge.
MST Cycle Property:
- Adding a new edge with weight to an existing MST creates exactly one simple cycle , formed by edge together with the unique tree path between and in .
- remains an MST of if and only if is greater than or equal to the weight of every edge on the tree path between and in (i.e., is a maximum-weight edge on cycle ).
Time complexity to test this condition:
- contains vertices and edges.
- Traversing from to via Breadth-First Search (BFS) or Depth-First Search (DFS) visits at most vertices and edges, taking time.
- During the traversal, tracking the maximum edge weight along the path takes per edge visited.
- Comparing this maximum with takes time.
- Hence, the worst case time complexity is .
Final answer
D
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2020 Computer Science and Information Technology (CS)
- Question
- 41 of 65, printed as CS Q.31
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.