|
-
November 3rd, 2014, 01:06 PM
#1
arrays of bits
hi i have the following problem:
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]
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 operations in
the following time bounds. (We want a dierent data structure for each set of time bounds, not
one data structure that satises all bounds simultaneously!)
(a) The worst-case time for both BLACKEN and NEXTWHITE is O(log n).
(b) The amortized time for both BLACKEN and NEXTWHITE is O(log n). In addition, the
worst-case time for BLACKEN is O(1).
(c) The amortized time for BLACKEN is O(log n), and the worst-case time for NEXTWHITE
is O(1).
(d) The worst-case time for BLACKEN is O(1), and the amortized time for NEXTWHITE is
O((n). [Hint: There is no WHITEN.]
I am thinking of using union find data structure but im not sure on how to proceed. Any help?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|