Heaps

Intro

Binary Heap is a Binary Tree with 2 more specifications (heap property)

Min Binary Heap

Max Binary Heap

Fibonacci Heaps

Binomial Heaps

Usage

Comparison

Advantages

Disadvantages

Problems

Corner CasesCorner Cases

Screenshot 2026-01-10 at 18.22.20.png

Implementation

Binary Heap is implemented as Complete Binary Tree (it's also Balancedheight of the tree is log(n)) **where:

⇒ this allows us to efficiently store our Heap as a List:

Algorithms

Heap Sort

Prim's Minimal-Spanning-Tree Algorithm

Dijkstra's Shortest-Path Algorithm

Selection Algorithms (kth smallest/biggest)

Patterns

Code

In Python, it is available using heapq module.

heapify(iterable)

heappush(heap, ele)

heappop(heap)

heappushpop(heap, ele)

heapreplace(heap, ele)

nlargest(k, iterable, key = fun)