Loyola College in Maryland

CS 462 - Algorithm Analysis
Spring 2004


Loyola College > Department of Computer Science > Dr. James Glenn > CS 462 > Examples > Project 1 Heap Example

Heap
Priority0161080
Index in Data32013

Data
KeyIndex in Heap
DC2
Philly3
Dallas1
Seattle4
Map
KeyIndex in Data
DC0
Philly1
Dallas2
Seattle3

To complete the removal of Kansas City, we must fix the heap:

The result should be the following

Heap
Priority110680
Index in Data2103

Data
KeyIndex in Heap
DC2
Philly1
Dallas0
Seattle3
Map
KeyIndex in Data
DC0
Philly1
Dallas2
Seattle3

To add New York with priority 3 we

The result should be the following

Heap
Priority1368010
Index in Data24031

Data
KeyIndex in Heap
DC2
Philly4
Dallas0
Seattle3
NY1
Map
KeyIndex in Data
DC0
Philly1
Dallas2
Seattle3
NY4

To remove the item with the lowest priority, we

The result should be the following

Heap
Priority310680
Index in Data2103

Data
KeyIndex in Heap
DC2
Philly1
NY0
Seattle3
Map
KeyIndex in Data
DC0
Philly1
Seattle3
NY2