CSE373: Data Structures & Algorithms Lecture 9: Priority ...
嚜澧SE373: Data Structures & Algorithms
Lecture 9: Priority Queues and Binary Heaps
Nicki Dell
Spring 2014
Priority Queue ADT
?
?
A priority queue holds compare-able items
Each item in the priority queue has a ※priority§ and ※data§
每 In our examples, the lesser item is the one with the greater priority
每 So ※priority 1§ is more important than ※priority 4§
?
Operations:
每 insert: adds an element to the priority queue
每 deleteMin: returns and deletes the item with greatest priority
每 is_empty
?
Our data structure: A binary min-heap (or binary heap or heap) has:
每 Structure property: A complete binary tree
每 Heap property: The priority of every (non-root) node is less important
than the priority of its parent (Not a binary search tree)
Spring 2014
CSE 373
2
Operations: basic idea
? deleteMin:
1. Remove root node
2. Move right-most node in last
row to root to restore
structure property
3. ※Percolate down§ to restore
heap property
? insert:
1. Put new node in next position
on bottom row to restore
structure property
2. ※Percolate up§ to restore
heap property
Spring 2014
CSE 373
10
20
40
50
80
60
85
99
700
Overall strategy:
? Preserve structure property
? Break and restore heap
property
3
DeleteMin
Delete (and later return) value at root node
1
4
7
3
5
8
9
11 9 6 10
Spring 2014
CSE 373
4
DeleteMin: Keep the Structure Property
?
?
?
We now have a ※hole§ at the root
每 Need to fill the hole with another value
Keep structure property: When we are done,
the tree will have one less node and must still
be complete
4
7
3
5
8
11 9 6 10
Pick the last node on the bottom row of the
tree and move it to the ※hole§
4
7
3
5
8
9
11 9 6 10
Spring 2014
CSE 373
9
5
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- python quick reference card
- programs based on array
- stat 345 01 nonparametric statistics
- cse373 data structures algorithms lecture 9 priority
- sta141c big data high performance statistical computing
- python arrays
- cse 142 python slides
- python tutorial stanford computer vision lab
- stats 507 data analysis in python university of michigan
- chapter 1 scalar variables and data types
Related searches
- highest priority synonym
- acls algorithms 2019
- acls algorithms pdf
- acls algorithms 2020
- acls aha algorithms 2020
- 2015 pals algorithms pdf download
- acls algorithms printable
- 2020 acls algorithms aha
- acls algorithms complete pdf
- acls 2015 algorithms printable
- acls algorithms 2015 pdf
- acls algorithms 2015 printable