Heap Operation
by:
A.keerthika
Introduction to Heap
definition:
A heap is a special tree-based data
structure that satisfies the heap property
Types of heaps:
Max Heap: The key at the root must be the
maximum among all keys present in the binary heap.
Min Heap: The key at the root must be the
minimum among all keys present in the binary heap
Heap properties
Complete Binary Tree structure
Heap Property: Nodes follow a specific
ordering (either max or min heap)
Visual Diagram of a Max Heap and a
Min Heap
● Insert: Inserting a new element while maintaining the
heap property
● Delete/Extract: Removing the root element and re-
heapifying
● Heapify: Ensuring the heap property is maintained
Basic Operation of Heaps
1. Insert the new element at the end of
the heap.
2. Perform "Upheap" (bubble-up) to
maintain the heap property.
Example diagram of insertion and upheap
process.
Insertion in heap
deletion in heap
1. Remove the root element
2. Replace the root with the last element.
3. Perform "Downheap" (bubble-down) to
restore heap order.
Example diagram of deletion and downheap
process.
Heapify Operation
Definition: Converts an unsorted binary tree into a
heap.
Types of Heapify:
Upheap (for insertions)
Downheap (for deletions)
Example: show a sequence of a tree being heapified
into a valid heap.
Heapify Operation
Heap Sort
Brief explanation of Heap Sort algorithm:
1. Build a max heap.
2. Repeatedly extract the maximum element and rebuild
the heap.
Time Complexity: O(n log n)
Example of Heap Sort on an array
Time Complexity of
Heap Operations
Insertion: O(log n)
Deletion: O(log n)
Heapify: O(n)
Heap Sort: O(n log n)
Application of Heaps
Priority Queues:
Efficient insertion and extraction of
minimum/maximum element.
Graph Algorithms:
Used in Dijkstra’s shortest path
algorithms. Prim’s minimum Spanning tree.etc.
Order Statistics:
finding k-th Targest or Smallest
Element.
Conclusion:
summary of heap operation
Empasize the Efficiency and
application of heaps in various
algorithms.

HEAP OPERATION IN DATABASE MANAGEMENT SYSTEM

  • 1.
  • 2.
    Introduction to Heap definition: Aheap is a special tree-based data structure that satisfies the heap property Types of heaps: Max Heap: The key at the root must be the maximum among all keys present in the binary heap. Min Heap: The key at the root must be the minimum among all keys present in the binary heap
  • 3.
    Heap properties Complete BinaryTree structure Heap Property: Nodes follow a specific ordering (either max or min heap) Visual Diagram of a Max Heap and a Min Heap
  • 4.
    ● Insert: Insertinga new element while maintaining the heap property ● Delete/Extract: Removing the root element and re- heapifying ● Heapify: Ensuring the heap property is maintained Basic Operation of Heaps
  • 5.
    1. Insert thenew element at the end of the heap. 2. Perform "Upheap" (bubble-up) to maintain the heap property. Example diagram of insertion and upheap process. Insertion in heap
  • 6.
    deletion in heap 1.Remove the root element 2. Replace the root with the last element. 3. Perform "Downheap" (bubble-down) to restore heap order. Example diagram of deletion and downheap process.
  • 7.
    Heapify Operation Definition: Convertsan unsorted binary tree into a heap. Types of Heapify: Upheap (for insertions) Downheap (for deletions) Example: show a sequence of a tree being heapified into a valid heap. Heapify Operation
  • 8.
    Heap Sort Brief explanationof Heap Sort algorithm: 1. Build a max heap. 2. Repeatedly extract the maximum element and rebuild the heap. Time Complexity: O(n log n) Example of Heap Sort on an array
  • 9.
    Time Complexity of HeapOperations Insertion: O(log n) Deletion: O(log n) Heapify: O(n) Heap Sort: O(n log n)
  • 10.
    Application of Heaps PriorityQueues: Efficient insertion and extraction of minimum/maximum element. Graph Algorithms: Used in Dijkstra’s shortest path algorithms. Prim’s minimum Spanning tree.etc. Order Statistics: finding k-th Targest or Smallest Element.
  • 11.
    Conclusion: summary of heapoperation Empasize the Efficiency and application of heaps in various algorithms.