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?
- A. O(E log E) for sorting the edges, dominating the near-linear Union-Find operations
- B. O(E) only, since Union-Find is O(1) per operation
- C. O(V^2) always, regardless of E
- 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
- Problem: Topological sort is only defined for which kind of graph, and what happens if Kahn's algorithm is run on a graph that violates…
- Problem: Which best explains why merge sort is preferred over quicksort for sorting linked lists (as opposed to arrays)?
- Problem: Which best explains the time complexity difference between recursive (top-down with memoization) and iterative (bottom-up…
- Problem: What is the time complexity of building a trie from n words with total character count L, and what is the space complexity?
- Problem: A problem is solved via binary search on the answer (not on an array index) -- e.g. 'minimum capacity to ship packages within D…
- Problem: Which of these is the correct worst-case time complexity of building a max-heap from an array of n unsorted elements using the…