Data Structures & AlgorithmsVery hardICPC regional · data structures
Problem: Union-find with path compression and union by rank performs m operations on n elements in what amortised time per operation?
- A. O(alpha(n)), the inverse Ackermann function, which is at most 4 for any practical n
- B. O(log n), because the tree height is logarithmic
- C. O(1) exactly, with no amortisation needed
- D. O(sqrt n), from the block decomposition
Correct answer: A. O(alpha(n)), the inverse Ackermann function, which is at most 4 for any practical n
Path compression plus union by rank gives the inverse Ackermann bound. The naive version without rank can degrade to O(n) per find, and that is the trap.
More Coding Interview Problems questions
- Problem: What is the largest rectangle area that can be formed in a histogram of heights [2, 1, 5, 6, 2, 3]? Use the stack code. python h…
- Problem: What is the minimum number of operations to sort the array [4, 3, 2, 1] using only swaps of adjacent elements? Run the code…
- Problem: Consider a graph where you must find the minimum 'maximum edge' on a path from s to t (a bottleneck path). Which algorithm…
- Problem: For a segment tree with n leaves supporting range-sum queries and point updates, what is the total space needed in terms of n?
- Problem: Find the number of inversions in [5, 4, 3, 2, 1] that a merge-sort based counter would report. Run the code. python def count(a)…
- Problem: Which claim about the Knuth-Morris-Pratt algorithm is correct?