Skip to main content
ICT
Lesson AB33 - PriorityQueues
 
Main Previous Next
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

A. Priority Queues page 3 of 9

  1. Often the items added to a queue have a priority associated with them: this priority determines the order in which they exit the queue - highest priority items are removed first. In this curriculum, the convention that will be followed is that the smallest value has the highest priority.

  2. For example, consider the software that manages a printer. In general, it is possible for users to submit documents for printing much more quickly than it is possible to print them. A simple solution is to place the documents in a FIFO ('first in, first out') queue. In a sense, this is fair, because the documents are printed on a first-come, first-served basis.

    However, a user who has submitted a short document for printing will experience a long delay when much longer documents are already in the queue. An alternative solution is to use a priority queue in which the shorter a document, the higher its priority. By printing the shortest documents first, the level of frustration experienced by the users is reduced. In fact, it can be shown that printing documents in order of their length minimizes the average time a user waits for a document.

  3. We can use a tree structure to keep track of the items in a priority queue - which generally provides O(log n) performance for both insertion and deletion. Unfortunately, if the tree becomes unbalanced, performance will degrade to O(n) in worst cases. This will probably not be acceptable when dealing with dangerous industrial processes, nuclear reactors, flight control systems or other life-critical systems.

  4. There is a structure that will provide guaranteed O(log n) performance for both insertion and deletion: it's called a heap.

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.