A Heap is a tree based data structure and it is a complete binary tree which satisfies the heap ordering property. The ordering can be one of two types:
the min-heap property: the value of each node is greater than or equal to the value of its parent, with the minimum-value element at the root.
the max-heap property: the value of each node is less than or equal to the value of its parent, with the maximum-value element at the root.
Basic Operations:
Following are the basic operations supported by a list.
-
Insertion − Adds an element at the max heap.
-
Deletion − Deletes an element at the beginning of the heap.
-
Display − Displays the complete heap.
-
Max − Get the max element from the heap.
- Space - O(n)
- Search - O(n)
- Insertion - O(1)
- Delete - O(log n) (Deletion from beginning)
- Peek - O(1)