Question

Let G=(V,E)G = (V, E) be a weighted undirected graph and let TT be a Minimum Spanning Tree (MST) of GG maintained using adjacency lists. Suppose a new weighted edge (u,v)∈V×V(u, v) \in V \times V is added to GG. The worst case time complexity of determining if TT is still an MST of the resultant graph is

Choose one option
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 e=(u,v)e = (u, v) with weight w(e)w(e) to an existing MST TT creates exactly one simple cycle CC, formed by edge ee together with the unique tree path between uu and vv in TT.
  • TT remains an MST of G∪{e}G \cup \{e\} if and only if w(e)w(e) is greater than or equal to the weight of every edge on the tree path between uu and vv in TT (i.e., ee is a maximum-weight edge on cycle CC).

Time complexity to test this condition:

  • TT contains ∣V∣|V| vertices and ∣V∣−1|V| - 1 edges.
  • Traversing TT from uu to vv via Breadth-First Search (BFS) or Depth-First Search (DFS) visits at most ∣V∣|V| vertices and ∣V∣−1|V| - 1 edges, taking Θ(∣V∣)\Theta(|V|) time.
  • During the traversal, tracking the maximum edge weight along the path takes O(1)O(1) per edge visited.
  • Comparing this maximum with w(e)w(e) takes O(1)O(1) time.
  • Hence, the worst case time complexity is Θ(∣V∣)\Theta(|V|).
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.