Posts

Heap search algorithm with java code

Image
HEAPS The (binary) heap data structure is an array object that we can view as a nearly complete binary tree Each node of the tree corresponds to an element of the array.  The tree is completely filled on all levels except possibly the lowest, which is filled from the left up to a point. An array A that represents a heap is an object with two attributes:  A: length , which (as usual) gives the number of elements in the array, and  A: heap - size ,  which represents how many elements in the heap are stored within array A .  Apart from being a useful data structure heaps could also sort the numbers in a efficient way. Following is an example of a Heap. As in a max-heap the max element is the root node. We could remove the top element and then rebuild heap. And then remove the next max element. There by getting the array in sorted order The heap property naturally lends itself to the following parent , left and right child  by using array indexes. An element can be searched in a heap in a