Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann.

Similar presentations


Presentation on theme: "CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann."— Presentation transcript:

1 CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann

2 Michael Eckmann - Skidmore College - CS 206 - Fall 2008 Today’s Topics Questions? Quickly finish up radix sort Priority Queues

3 Read from page 239 in text book.

4 Priority Queues Priority queues have the following characteristics –Each item placed into a priority queue has a priority value associated with it –When a remove is requested from a priority queue, we remove the highest priority item –We should also have a way to determine if the priority queue is empty –We can also have a peek to see what item has the highest priority without removing it It is best to limit priority values to be integers (reason to be seen shortly).

5 Priority Queues It is also a wise thing to maintain the following values for a priority queue –current size (how many items are in the queue)‏ –the priority of the highest priority item in the queue to make remove more efficient however it causes (some) additional work –after the remove happens we need to possibly change this value –after an add we just need to check if the one we added is higher than the highest, if so, change it.

6 Priority Queues Implementation of a priority queue could be an array of queues. The index of the array is the priority value (see how we want our priority values to be integers?)‏ The range of priority values (all integers) determines how many queues we're storing --- that is, how many elements of the array there will be. Let's implement a priority queue in this way now.

7 Priority Queues If we don't want to limit the priority values to integers or the range of priorities is large --- an array of queues is impractical. What alternate implementation(s) could handle a large range of floating point priorities?

8 Priority Queues What alternate implementation(s) could handle a large range of floating point priorities? –Store a linked list of nodes where each node contains a priority value and the item stored in the priority queue –This will require more work to insert into the priority queue, but will remove the need to keep track of largest priority, etc. Let's implement a priority queue in this way.

9 Deques Deque (or Dequeue) stands for double-ended queue. It is pronounced “deck”. Allows adding to and removing from both the front and rear. –Since this allows adding and removing from both ends what kind of linked list would be best to implement this data structure?


Download ppt "CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann."

Similar presentations


Ads by Google