C36206 - 3 Priority Queues 3 Priority Queues ADT Stack LIFO ADT Queue FIFO ADT Priority Queue pick the element with the lowest(or highest priority

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

View Full Document Right Arrow Icon
3. Priority Queues 3. Priority Queues ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority. Malek Mouhoub, CS340 Winter 2007 1 3. Priority Queues 3. Priority Queues 3.1 Model 3.2 Implementation 3.3 Binary Heap 3.4 d-Heaps 3.5 Min-Max Heap Malek Mouhoub, CS340 Winter 2007 2
Background image of page 1

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

View Full DocumentRight Arrow Icon
3.2 Implementation 3.2 Implementation 1st case : use a linked list insert at the front of the list : O (1) deleteMin requires traversing the list : O ( N ) Malek Mouhoub, CS340 Winter 2007 3 3.2 Implementation 2nd case : use a sorted linked list insertion requires O ( N ) but only O (1) for deleteMin. Malek Mouhoub, CS340 Winter 2007 4
Background image of page 2
3.2 Implementation 3rd case : use a binary search tree O (log N ) average running time for both insertion and deletion. Elements are deleted at each time from the left subtree which affects the balance of the tree. The binary search tree supports many operations that are not required by priority queue. Malek Mouhoub, CS340 Winter 2007 5 3.3 Binary Heap 3.3 Binary Heap A binary heap is a complete binary tree : a tree that is completely Flled, with possible exception of the bottom level, which is Flled from left to right. Can easily be represented by an array (and an integer representing the current heap size) instead of a linked list. ±or any element in array position i : the left child is in position 2 i , the right child is in position 2 i + 1 , and the parent is in position [ i/ 2] . The operations required to traverse the tree are very simple and are performed quickly (because of the heap-order property). Malek Mouhoub, CS340 Winter 2007 6
Background image of page 3

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

View Full DocumentRight Arrow Icon
3.3 Binary Heap A B C D E H I J F G A B C D E F G H I J 0 1 2 3 4 5 6 7 8 9 10 11 12 13 Malek Mouhoub, CS340 Winter 2007 7 3.3 Binary Heap Heap-Order Property The smallest element should be at the root. Any node should be smaller than all of its descendants (any
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/15/2010 for the course CS 340 taught by Professor Dr.malek during the Fall '10 term at University of Regina.

Page1 / 13

C36206 - 3 Priority Queues 3 Priority Queues ADT Stack LIFO ADT Queue FIFO ADT Priority Queue pick the element with the lowest(or highest priority

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

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