Docsity

Priority Queues and Heaps: Properties, Operations, and Implementations, Slides of Data Structures and Algorithms

Partial preview of the text

Download Priority Queues and Heaps: Properties, Operations, and Implementations and more Slides Data Structures and Algorithms in PDF only on Docsity!

Data structure Enqueue Find Min Dequeue Min

Unsorted List O(1) O(n) O(n)

Sorted List O(n) O(1) O(1)

AVL Tree O(log n) O(log n) O(log n)

MinHeap O(log n) O(1) O(log n)

Applications of Priority Queues

Many, many applications.

Scheduling queues for a processor, print queues, transmit queues, backlogs, etc.….

This means this item will be in the front of queue

“Obtained” via a remove().

 Note: a priority queue is no longer FIFO!

 You will still remove from front of queue, but insertions are governed by a priority.

Applications of Priority Queues

Any event/job management that assign priority to events/jobs

In Operating Systems

Scheduling jobs

In Simulators

Scheduling the next event (smallest event time)

Priority Queues: Access Time

remove()So, the first item has priority and can be retrieved (removed) quickly and returned to calling environment.Hence, ‘remove()’ is easy (and will take O(1) time)

insert()  (^) But, we want to insert quickly. Must go into proper position.  (^) For our purposes here: Implementing data structure: array;  (^) slow to insert(), but for  (^) small number of items in the pqueue, and  (^) where insertion speed is not critical,  (^) this is the simplest and best approach.

 (^) A binary heap is a partially ordered complete binary tree

  • (^) The tree is completely filled on all levels except possibly the lowest.  (^) In a more general d-Heap
  • (^) A parent node can have d children  (^) We simply refer to binary heaps as heaps 0 3 2 4 5 root