What is a heap?

Arrays Linked Lists Questions



46 Short 80 Medium 67 Long Answer Questions Question Index

What is a heap?

A heap is a specialized tree-based data structure that satisfies the heap property. It is a complete binary tree where each node's value is greater than or equal to its children's values (in a max heap) or less than or equal to its children's values (in a min heap). The root node of the heap contains the maximum (or minimum) value in a max (or min) heap, respectively. Heaps are commonly used to implement priority queues and are efficient for operations such as insertion, deletion, and finding the maximum (or minimum) element.