Heap Operations | Data Structures Interview | Skill-Lync Resources
Medium Data Structures Heaps & Priority Queues

Explain the heapify operation and its time complexity.

Answer

Heapify maintains heap property by moving a node to its correct position. Heapify-down (sift-down) compares parent with children and swaps with larger (max-heap) or smaller (min-heap) child, repeating until valid. Single heapify is O(log n). Building a heap from array uses bottom-up heapify on all non-leaf nodes, achieving O(n) total time (not O(n log n)) because most nodes are near the bottom with small heights.

Master These Concepts with IIT Certification
IIT Certified

Master These Concepts with IIT Certification

175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.

Relevant for Roles

Software Engineer Backend Developer Algorithm Developer