Heap Data Structure

What is heap data structure?

Heap is complete binary tree that satisfy either min-heap or max-heap condition.

Max Heap : Every element must be >= all descendent elements.

Min Heap : Every element must be <= all descendent elements.

In 1, 2, 3.... based indexing

Root = array[index]

Parent = array[index/2]

Left Node = array[2 * index]

Right Node = array[2 * index + 1]

In 0, 1, 2, 3.... based indexing, Good Read

Root = array[index]

Parent = array[(index-1)/2]

Left Node = array[2 * index + 1]

Right Node = array[2 * index + 2]


Heap implementations : 

1. Priority Queue : A. Min,  B. Max

2. Heap Sort : Ascending order, Descending order





Comments

Popular posts from this blog

SQL basic interview question

gsutil Vs Storage Transfer Service Vs Transfer Appliance