CSC263H1 Lecture Notes - Lecture 3: Priority Queue, Increment And Decrement Operators

67 views2 pages
27 Oct 2015
School
Course
Professor

Document Summary

Like a queue except every item has a priority (usually a number) that determines retrieval order. Applications: job scheduling in an operating system, printer queues, event-driven simulation algorithms, etc. (n) for insert: special case: if only a xed number k priorities {p1, p2, . , pk} and k is small, then keep an array with k positions (one for each priority) and store items in a linked list at each position. Then, insert (1) maximum, extractmax (k) increasepriority (1) Simple data structures used to represent priority queues. Implication: every subtree of a heap is also a heap. Enough to query operations fast while not requiring full sorting after each update. Increment heapsize , add element at new index heapsize . Result might violate heap property: bubble element up (exchange it with its parent) until priority no greater than priority of parent. Return element at index 1 (if heapsize 1). This leaves hole at index 1: move element at heapsize +

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions