Heapify

Domain: Data Structures

🎯 Motivation

Heapify is the process of rearranging an array into a valid heap, done in O(n) time — faster than inserting elements one by one.

📋 Concrete Example

import heapq; data = [3, 1, 4, 1, 5]; heapq.heapify(data) rearranges the list in-place into a valid min-heap.

🔗 Analogy

Rearranging a messy bookshelf so that the shortest book is always on the left of each shelf section. You fix it all at once instead of one book at a time.