0

I recently got into a discussion about Priority Queues when the requirements allow for "best effort" removal (i.e. the removed key may not always be THE very highest priority, but it is relatively close).

After thinking about it a bit I stated "I could probably make it $O(1)$ by using buckets" and approximating the minimum (to bucket size precision). I was politely told that I was wrong. Not taking no for an answer, I later went to Google and found the ample literature on the subject, which seemed to confirm I was wrong :-|

Note that the closely related question, Unique integer priority queue with both $O(1)$ insert and extract-min?, does not allow for approximation, so the answers don't apply to my question.

I was told the standard solution to this problem is to use a queue where keys are appended to the end in $O(1)$ and read from the head in $O(1)$ and which is then periodically sorted in $O(\log N)$ or whatever sorting algorithm you can find.

Assuming 64-bit integers as keys, and a precision of $ \pm 127$ (a 56-bit bucket)... Can't you just hold the buckets in a sparse array (so as not to require $2^{56}$ words of memory)... problem solved?

Blanco
  • 643
  • 3
  • 17
Alex R
  • 101
  • 1

1 Answers1

1

Your proposed data structure is simply a hash table with some rounding to reduce the number of buckets. Effectively, all this does is divide the problem complexity by some constant factor (128 in your example).

You have no hierarchy in your design, so there is no way to have O(1) access to the smallest/largest non-empty bucket. To achieve this feature efficiently, you're already pretty much bound to some type of priority queue. This class of data structures is well studied, and has various implementations with typically very low bounds on complexity.

Arthelais
  • 248
  • 1
  • 6