File Exchange

image thumbnail


version 1.0 (2.12 KB) by

heap data type

1 Download


View License

Implements heap data type.

h- an array in which the data is stored
heapSize- the size of the heap
Heap- constructor for the Heap class, acepts numeric arrays as an input.
heapSort- method for performing sorting, runtime O(nlogn),although, very, very slow... not to be used for sorting arrays!!!
heapMaximum- returns maximum in the heap heapExtractMax- extracts maximum value from the heap
heapIncreaseKey- increses the key in the postion i
maxKeyInsert- inserts a key in the heap

made by Hanan Kavitz
free for distribution

Comments and Ratings (3)


Yasha (view profile)

The description should mention that this heap only sorts keys and does not support key-value pairs.

Hanan Kavitz

Hanan Kavitz (view profile)

Derec Hello,
Heap is a very usefull data type used in many algorithms primarily due to the fact that you can get maximum number in the heap with runtime of O(1) and extracting maximum(or minimum) with runtime of O(logn).
What I meant is that sorting is done, in this case, much slower than just using sort(A).
For any other operation with Heap this code is good.

What is the point of this submission, if, as you say in your preamble to Heap, "very, very slow... not to be used for sorting arrays!!! "

MATLAB Release
MATLAB 7.13 (R2011b)
Tags Add Tags

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video