Professional Documents
Culture Documents
By Ali Saeed
Definition
• A binary heap 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.
Application of Heap
• Min Heap and Max Heap are used to
implement a priority queue.
Examples
Development of Max-Heap
• Data: 15,7,12,28,36,1,37,13,4,25,3,9,27,2,5,16
Next Steps
Next Step
Next Step
Next Step
Class Exercise
• Develop Min-Heap of the following data:
• 13, 5 , 33, 90, 100, 10, 22, 18, 11, 43, 1
Class Exercise
• Develop Max-Heap of the following data:
Parent of K?
Left Child of G?
Right Child of K?
Class Exercise
On which array index ,the right child of K will be stored?
Class Exercise
On which array index ,the right child of B will be stored?
Array implementation
Cont…
Cont…
Output of the code
Time Complexity of Min/Max Heap
• Thanks