University of California, Santa Cruz

Prof. Paulo Franca - Spring 2000

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

bulletmaximum is always at the top of the heap (element 1)
bulletsave A[1] which is the result
bulletmove the last element to the first position
bulletdecrease the heap size
bulletrestablish the heap with heapify from element 1.