Heap
A heap is a special tree-based data structure where the tree is a complete binary tree. This means that every level of the tree is completely filled except possibly the last level.
Types of Heaps
- Max Heap: The value of any parent node in a max heap is greater than or equal to the value of its children.
- Min Heap: The value of any parent node in a min heap is less than or equal to the value of its children.
Operations on Heaps
- Insert: Adds an element to the heap and maintains the heap property.
- Delete: Removes the root element (maximum or minimum) from the heap and restores the heap property.
- Find-Max/Find-Min: Returns the maximum/minimum element in the heap.
- Increase/Decrease-Key: Increases/decreases the value of a specific key in the heap, maintaining the heap property.