Data Structures & AlgorithmsVery hardTCS NQT Digital · Product Company SDE
Problem: What is the time complexity of detecting a cycle in an undirected graph using Union-Find, processing E edges?
- A. O(E log E)
- B. O(E^2)
- C. O(V^3)
- D. O(E * alpha(V)), nearly O(E), where alpha is the inverse Ackermann function
Correct answer: D. O(E * alpha(V)), nearly O(E), where alpha is the inverse Ackermann function
With path compression and union by rank, each Union-Find operation runs in amortized O(alpha(V)) time (an extremely slow-growing function), so processing all E edges for cycle detection takes nearly-linear O(E * alpha(V)) time.
More Coding Interview Problems questions
- Problem: A recursive solution explores every possible way to partition a string into palindromic substrings (palindrome partitioning)…
- Problem: Which best describes the relationship between the number of valid Binary Search Trees on n distinct keys and the Catalan numbers?
- Problem: What is the time complexity of the standard iterative binary search, and what precondition must hold for it to work correctly?
- Problem: Which best describes why DFS-based topological sort (using finish times, pushing to a stack) correctly produces a topological…
- Problem: A problem requires finding all pairs in an array that sum to a target, allowing duplicate pairs to be counted once. Which is the…
- Problem: Which statement about the time complexity of building a suffix array naively (sorting all n suffixes with standard string…