Data Structures & AlgorithmsModerateIBM · Deloitte pattern

With the edges sorted first, what is the time complexity of Kruskal's algorithm using a union-find structure, for a graph with V vertices and E edges?

  1. A. O(E + V)
  2. B. O(V²)
  3. C. O(E log E)
  4. D. O(VE)

Correct answer: C. O(E log E)

Sorting the edges costs O(E log E) (= O(E log V)), and the union-find operations with path compression and union by rank are almost O(1) each, so sorting dominates. O(V²) is Prim's algorithm with an adjacency matrix.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic