Question: Suppose we want to maintain an array X[1, , n] of bits, which are all initially zero, subject to the following operations. LOOKUP(i): Given an
Suppose we want to maintain an array X[1, , n] of bits, which are all initially zero, subject to the following operations. LOOKUP(i): Given an index i, return X[i]. BLACKEN(i): Given an index i < n, set X[i] 1. NEXTWHITE(i): Given an index i, return the smallest index j i such that X[j] = 0. (Because we never change X[n], such an index always exists.) If we use the array X[1, , n] itself as the only data structure, it is trivial to implement LOOKUP and BLACKEN in O(1) time and NEXTWHITE in O(n) time. But you can do better! Describe data structures that support LOOKUP in O(1) worst-case time and the other two in the following time bounds. (a) The amortized time for BLACKEN is O(log n), and the worst-case time for NEXTWHITE is O(1). (b) The worst-case time for BLACKEN is O(log n), and the amortized time for NEXTWHITE is O(log n). (c) [Bonus Question] BLACKEN in O(1) worst-case, and NEXTWHITE in O(log n) amortized.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
