priorty_queues

Priorty_queues - Priority Queues Two kinds of priority queues Min priority queue Max priority queue Min Priority Queue Collection of elements Each

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

View Full Document Right Arrow Icon
Priority Queues Two kinds of priority queues: Min priority queue. Max priority queue.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Min Priority Queue Collection of elements. Each element has a priority or key. Supports following operations: isEmpty size add/put an element into the priority queue get element with min priority remove element with min priority
Background image of page 2
Max Priority Queue Collection of elements. Each element has a priority or key. Supports following operations: isEmpty size add/put an element into the priority queue get element with max priority max
Background image of page 3

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

View Full DocumentRight Arrow Icon
Complexity Of Operations Two good implementations are heaps and leftist trees. isEmpty, size, and get => O(1) time put and remove => O(log n) time where n is the size of the priority queue
Background image of page 4
Applications Sorting use element key as priority put elements to be sorted into a priority queue extract elements in priority order if a min priority queue is used, elements are extracted in ascending order of priority (or key) if a max priority queue is used, elements are extracted in descending order of priority (or key)
Background image of page 5

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

View Full DocumentRight Arrow Icon
Sorting Example Sort five elements whose keys are 6, 8, 2, 4, 1 using a max priority queue. Put the five elements into a max priority queue. Do five remove max operations placing removed elements into the sorted array from right to left.
Background image of page 6
After Putting Into Max Priority Queue Sorted Array 6 8 2 4 1 Max Priority Queue
Background image of page 7

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

View Full DocumentRight Arrow Icon
After First Remove Max Operation Sorted Array 6 2 4 1 8 Max Priority Queue
Background image of page 8
After Second Remove Max Operation Sorted Array 2 4 1 8 6 Max Priority Queue
Background image of page 9

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

View Full DocumentRight Arrow Icon
After Third Remove Max Operation Sorted Array 2 1 8 6 4 Max Priority Queue
Background image of page 10
After Fourth Remove Max Operation Sorted Array 1 8 6 4 2 Max Priority Queue
Background image of page 11

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

View Full DocumentRight Arrow Icon
After Fifth Remove Max Operation Sorted Array 8 6 4 2 1 Max Priority Queue
Background image of page 12
Complexity Of Sorting Sort n elements. n put operations => O(n log n) time.
Background image of page 13

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

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

This note was uploaded on 01/24/2011 for the course CSE 303 taught by Professor Mm during the Spring '10 term at MIT.

Page1 / 77

Priorty_queues - Priority Queues Two kinds of priority queues Min priority queue Max priority queue Min Priority Queue Collection of elements Each

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

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