lecture22

# lecture22 - COMP 250 Winter 2010 22 - heaps 1 March 8, 2010...

This preview shows pages 1–2. Sign up to view the full content.

COMP 250 Winter 2010 22 - heaps 1 March 8, 2010 (updated March 17) Priority Queue We next consider a diferent kind oF binary tree, which is related to queues. Our de±nition oF a queue was that the next item to be removed is the one that was in the queue longers. A natural way to implement such a queue was using a linear data structure, such as a linked list or a (circular) array. A priority queue is a diferent kind oF queue, in which the element that is removed is selected based on some criterion that could include the time oF entry into the queue but other considerations as well. ²or example, in a hospital emergency room, patients are treated not in a ±rst-come ±rst- serve order, but rather the order is determined by the relative severity oF the case (perhaps in combination with other Factors, including how long the patient has been waiting). We do not consider speci±c examples here, but rather we just assume there is some way oF comparing objects according to their priority. Then, the next item to be removed is the one with highest priority. (We oFten assign low numerical values to high priorities. Think: “my number one priority” vs. “my number 2 priority”. One way to implement a priority queue is to maintain a sorted list oF the elements in the queue. This could be done with a linked list or array. Each time an item is added, it would need to be inserted into the sorted list. A second way to implement a priority queue would be to use a binary search tree. The item that is removed next is Found by the findMinimum() operation. This would be a better way to implement a priority queue than the linear method, since an insertion and deletion tend to occur relatively quickly. It can still take long though, since we have not guarenteed that the binary tree will be balanced. We can still have long paths in the tree. Heaps

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/25/2011 for the course COMP 250 taught by Professor Blanchette during the Spring '08 term at McGill.

### Page1 / 4

lecture22 - COMP 250 Winter 2010 22 - heaps 1 March 8, 2010...

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

View Full Document
Ask a homework question - tutors are online