OperationQueue dequeue and remove operations performance improvement

Hi Nevin,

I thought about implementing Priority Queue, but following are the reasons I decided to go with linked list based approach,

  • Priority queue do insert and delete-next-prioritized-item in O(log N) time.
  • We need random access to the elements in queue, not just the first element. Finding that element is again is O(n) time
  • Besides, Im guessing, it is gonna be quite a challenge to keep the operations of same priority, in the same order as it was added in the queue.

In linked list based approach we could do insert, delete-next-prioritized in O(1) and with the use of hash map deleting a random item also comes down to O(1).

Hope I made a correct decision.

1 Like