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?
- A. O(E + V)
- B. O(V²)
- C. O(E log E)
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Which single-source shortest path algorithm can detect a negative-weight cycle reachable from the source?
- A topological ordering of a directed graph exists if and only if the graph is:
- A heap is stored in a 0-indexed array. What is the index of the parent of the element at index 10, and of its left child?
- Using the master theorem, what is the solution of T(n) = 2T(n/2) + n?
- In the activity selection problem (choose the most non-overlapping intervals), which greedy rule always gives an optimal answer?
- Why does the greedy method (best value-per-weight first) solve the fractional knapsack problem but not the 0/1 knapsack problem?