I recently took an exam that had question saying: Your friend has come up with a set of algorithms for a priority queue that do the following operations: Insert(S, x)
in O(1)
, Peek-Max(S)
in O(1)
, Remove-Max(S)
in O(1)
, and Increase-Key(S, x, k)
in O(logn)
. How would you prove to your friend that this set of algorithms is impossible?
I've been really stressed because I'm positive I got the wrong answer. I said a priority queue must have the property that for a set of elements [A1, A2, ... An]
it needs to have the relation [A1 >= A2 >=...>= An]
which I now realize isn't true. Only the first element needs to be bigger than the rest (assuming a max-first priority queue). Therefore the insert function can't be in O(1) because for a set of n elements there's no way you can make sure the placed item is in its proper spot in constant time.
Do any of you have any insights as to how one would go about solving this problem? I couldn't get any sleep last night thinking I probably got this question wrong.
Increase-Key
to increase the priority of an element that already exists in the queue? What exactly doesIncrease-Key
do? – kevchoi