Given a constant number of priorities implement a priority queue with O(1) enqueue and dequeue implementations.
Use a hashtable, the key is priority level and the associated value is the linked list which maintains the objects with the same priority level. Also maintain a priority queue to record the priority levels, if a new level join, we update this priority queue, and if we want to dequeue, first get the max priority level from the priority queue and look up the key in the hash table. Enqueue is O(1), dequeue is O(1), while the priority levels are constant
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment