Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: Which statement about Kruskal's algorithm's overall time complexity is correct for a graph with V vertices and E edges?

  1. A. O(E log E) for sorting the edges, dominating the near-linear Union-Find operations
  2. B. O(E) only, since Union-Find is O(1) per operation
  3. C. O(V^2) always, regardless of E
  4. D. O(V E), same as Bellman-Ford

Correct answer: A. O(E log E) for sorting the edges, dominating the near-linear Union-Find operations

Sorting all E edges by weight costs O(E log E); afterward, E Union-Find operations with path compression and union by rank cost nearly O(E) (technically O(E alpha(V))), so the sort dominates the overall complexity.

More Coding Interview Problems questions

Exams that ask this topic