A Heap is a special Tree-based data structure in which the tree is a complete binary tree. Generally, Heaps can be of two types:
- Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys present at all of it’s children. The same property must be recursively true for all sub-trees in that Binary Tree.
- Min-Heap: In a Min-Heap the key present at the root node must be minimum among the keys present at all of it’s children. The same property must be recursively true for all sub-trees in that Binary Tree.
What are heaps used for?
Heaps are used in many famous algorithms such as Dijkstra's algorithm for finding the shortest path, the heap sort sorting algorithm, implementing priority queues, and more. Essentially, heaps are the data structure you want to use when you want to be able to access the maximum or minimum element very quickly.
What are the three main properties of heap?
1.Ordering. Nodes must be arranged in an order according to values. The values should follow min-heap or max-heap property.
2.Structural. All levels in a heap should be full.
3.Methods or Operations of Heap. find - in order to find an item in a heap.
4.Implementation. Heaps are usually implemented in an array.
Top comments (0)