PRIORITY QUEUE   :
Print this page
 

Queues are dynamic collections which have some concept of order. This can be either based on order of entry into the queue - giving us First-In-First-Out (FIFO) or Last-In-First-Out (LIFO) queues. Both of these can be built with linked lists: the simplest "add-to-head" implementation of a linked list gives LIFO behavior. A minor modification - adding a tail pointer and adjusting the addition method implementation - will produce a FIFO queue.

Performance

A straightforward analysis shows that for both these cases, the time needed to add or delete an item is constant and independent of the number of items in the queue . Thus we class both addition and deletion as an O (1) operation. For any given real machine + operating system + language combination, addition may take c 1 seconds and deletion c 2 seconds, but we aren't interested in the value of the constant, it will vary from machine to machine, language to language, etc . The key point is that the time is not dependent on n - producing O (1) algorithms.

Once we have written an O (1) method, there is generally little more that we can do from an algorithmic point of view. Occasionally, a better approach may produce a lower constant time. Often, enhancing our compiler, run-time system, machine, etc will produce some significant improvement. However O (1) methods are already very fast, and it's unlikely that effort expended in improving such a method will produce much real gain!

   
 
Prev