3. Heap
A heap is a complete binary tree whose elements have
nodes that satisfy the the following property :The node
along any path from root to leaf are non increasing
5. Mapping the Heap into an Array
The mapping is 0
obtained form a 77
level order 1 2
traversal of the 66 55
tree.
3
4 5 6
44 60 33 55
7 8 9 10
22 41 58 25
0 1 2 3 4 5 6 7 8 9 10
77 66 55 44 60 30 55 22 41 58 25
6. Heap properties in Array
The Heap property easy to see in tree
structured but not clear at all in the
linearized array.
According to the mapping of the binary
tree in to an array.
7. Continue ....
The children of element at index i are at 2i+1
and 2i+2
77 66 55 44 60 33 55 22 41 58 25
0 1 2 3 4 5 6 7 8 9 10
8. Continue ....
The parent of element at index i is at (i-1)/2
77 66 55 44 60 33 55 22 41 58 25
0 1 2 3 4 5 6 7 8 9 10