Binary Heap - Introduction

Heap Data Structure - GeeksforGeeks #Image Credit - GeeksForGeeks

  • Types of heap:
    • Min Heap - every node is less than or equal to its children(s)
    • Max Heap - every node is more than or equal to its children(s)

  • Operations on any heap :
    • create
    • insert
    • extract/delete - we can extract/delete only the top node in any heap
    • traverse
    • delete entire heap
    • get size of heap
    • peek top of heap

  • We should prefer implementing binary heap using arrays and not linked list, as during bottom to top heapify, in reaching the bottom rightmost node we take only 0(1) time in case of array but we take 0(n) time in case of linked list because first, we need to level order traverse the binary heap tree to get bottom-most rightmost element. 

  • Heaps are used to efficiently implement: 
    • Prim's Algorithm
    • Heapsort
    • Priority queue

Comments

Popular posts from this blog

Divide and Conquer - Introduction

Bubble Sort