CS Notes 12

CS Notes 12 - Priority Queue/Heap Monday, March 28, 2011...

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

View Full Document Right Arrow Icon
Priority Queue/Heap Monday, March 28, 2011 3:23 PM Similar to regular queues When you dequeue, you always dequeue the entry with the highest priority What data structure should we use? (Worst case times) 1. Linked List o Unordered (CLL) Enqueue: O(1) Dequeue: O(n) o Ordered (Sorted) Enqueue: O(n) Dequeue: O(1) 1. AVL Tree o Enqueue: insert: O(log n) Must look to see if the object already exists in the tree o Dequeue o Must store all nodes of the same priority at the same location (in a LL) 1. Array o Enqueue: O(1) o Dequeue: O(r) r=range of array You would have to start from the rear and work your way back There might be many empty spaces Heap Store heap in array/arraylist Must fill every level left to right Heap structure o In any level, nodes are filled left to right without gaps o All levels except last must be filled before going to the next Heap order o The priority at any node x >= priorities at its children
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

CS Notes 12 - Priority Queue/Heap Monday, March 28, 2011...

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

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