Lecture 3 Heap Algorithms
Lecture 3 Heap Algorithms
Introduction
• There are several types of heaps, however, we are going to discuss the
binary heap. A binary heap is a data structure, which looks similar to a
complete binary tree. Heap data structure obeys ordering properties
discussed below. Generally, a Heap is represented by an array. Here, we
are representing a heap by H.
• As the elements of a heap is stored in an array, considering the starting
index as 1, the position of the parent node of ith element can be found
at ⌊ i/2 ⌋ . Left child and right child of ith node is at position 2i and 2i + 1.
• A binary heap can be classified further as either a max-heap or a min-
heap based on the ordering property.
Max-Heap
• In this heap, the key value of a node is greater than or equal to the
key value of the highest child.
Hence, H[Parent(i)] ≥ H[i]
Min-Heap