Heap is a complete binary tree represented as an array. There are two main types: min heap and max heap. A max heap has the largest element at the root and each parent is greater than or equal to its children. Heap sort uses the heap property to sort an array in O(n log n) time. It first builds a max heap from the array. Then it repeatedly removes the maximum element from the heap, adding it to the sorted portion of the array.