|
Introduction
Syllabus
Guidelines for labs
Lab sections
Take quiz & check grades
| |
Extract Max
Extract the element at the top of the heap
Book procedure:
- ExtractMax(A)
- if (A.heapsize <1) error, underflow
- max=A[1];
- A[1]=A[A.heapsize];
- A.heapsize=A.heapsize-1;
- Heapify(a,1);
- return max;
Explanation
 | maximum is always at the top of the heap (element 1) |
 | save A[1] which is the result |
 | move the last element to the first position |
 | decrease the heap size |
 | restablish the heap with heapify from element 1. |
|