I am working on homework with Heaps, and I understand how they are structured. The heap must have every node satisfying the heap property,
The max-heap property is that for each node I am different than the root, Heap [Parent (i)]> Heap [i]
So, with each node, higher nodes have higher numbers, lower nodes have lower numbers. I understand it. But I cannot see the use of the heap, and then just get the highest n numbers in the list. I do not see an easy way to search for a specific value and return node, or to search for n the smallest numbers (in the max heap). Both are relatively simple in the binary search tree.
Why don't you just use a simple binary search tree? Or better yet, a balanced binary search tree?
EDIT: I must point out that this is not a search for an answer to a home problem. The problem with homework was writing pseudo-code for the parallel p-heap for the insert () and extractMax () functions. And I already answered them. They just made me realize that I really didn't understand Haps.
heap data-structures
jb.
source share