day21 - COP 3503 Computer Science II CLASS NOTES DAY#21...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 3503 – Computer Science II CLASS NOTES - DAY #21 A priority queue is essentially a list of items in which each item has associated with it a priority . In general, different items may have different priorities and thus we speak of one item having a higher priority than another. Given such a list we can determine which is the highest (or lowest) priority item in the list. In general, items are inserted into a priority queue in arbitrary order. However, items are removed from the priority queue in the order of their priorities, typically starting with the highest priority item first. A single integer value is commonly used to indicate the priority of an item an typically the smaller this value the higher the priority of the item, however, this is also a problem specific consideration and other situations may occur. Priority queues are commonly used by operating systems to manage the various functions of process control. For example, consider the software which manages a shared resource such as a networked printer. In general, it is possible for users to submit print jobs much more quickly than it is possible for the printer to print them (case in point are the CCII labs!). A simple solution is to place the print jobs into a FIFO queue. While this may seem fair in that the jobs are printed on a first-come, first-served basis, 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 the document, the higher its priority. In fact, it can be proven that printing documents in the order of their length minimizes the average time a user waits for their document to be printed. Priority queues are also often used in the implementation of algorithms. Typically the problem to be solved consists of a number of subtasks, and the solution strategy involves prioritizing the subtasks and then performing those subtasks in the order of their priorities. Priority queues can be used to improve the performance of many backtracking algorithms. Priority queues are the basis for an optimal comparison based sorting algorithm known as the heap sort (we’ll look at this sort later). Many graph algorithms utilize priority queues to control traversing within the graph. A mergeable priority queue is one that provides the ability to merge efficiently two priority queues into one. While this capability goes beyond the depth at which we will look at priority queues it is nonetheless an important aspect of dealing with priority queues. The reason that I mention it here is that a special kind of tree, called a leftist tree (no, its not a political statement) is typically employed when Day 21 - 1 Heaps and Priority Queues
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
two or more priority queues will be merged; we will not discuss leftist trees in any detail, except for a cursory look. There are also more complex versions of priority queues which are double-ended in which both the highest and lowest priority items can be removed simultaneously.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/12/2011.

Page1 / 15

day21 - COP 3503 Computer Science II CLASS NOTES DAY#21...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online