Data Structure 23 + 24
Data Structure 23 + 24
LECTURE 23 + 24
INSTRUCTOR: Tayyba Khalid
Content:
■ Heaps
– Types
– Applications
– Advantages / Disadvantages
■ Binary heap
Heaps
■ A Heap is a complete binary tree data structure that satisfies the
heap property: for every node, the value of its children is greater than
or equal to its own value.
■ Heaps are usually used to implement priority queues, where the
smallest (or largest) element is always at the root of the tree.
Types:
Binomial
Heap
Binary
Fibonac
Heap ci Heap
K-ary
Leftist
Heap Heap
Applications:
1. Priority Queues: Heaps are commonly used to implement priority queues, where
elements with higher priority are extracted first. This is useful in many applications
such as scheduling tasks, handling interruptions, and processing events.
3. Graph algorithms: Heaps are used in graph algorithms such as Prim’s Algorithm
, Dijkstra’s algorithm., and the A* search algorithm.
7. Order statistics: The Heap data structure can be used to efficiently find
the kth smallest (or largest) element in an array
■ Min-heap:
• Heap Property: Each node is smaller than its children
• Root is the minimum element in the tree
• Smallest key always at the front of a queue
• Able to extract min with O(1) time complexity
Max-heap:
Advantages disadvantages
• Flexible size ■ Slow lookup (slower than
searching a BST)
• Fast insert