Overview

This chapter introduces heapsort, a comparison-based sorting algorithm that combines the best attributes of merge sort and insertion sort: it runs in O(n lg n) time like merge sort, yet sorts in place like insertion sort. The chapter also introduces the heap data structure—a nearly complete binary tree stored as an array—which is not only the engine behind heapsort but also the foundation for an efficient priority queue implementation used extensively in later chapters (e.g., Dijkstra's algorithm, Prim's MST).

Key Concepts

6.1 — Heaps

6.2 — Maintaining the Heap Property (MAX-HEAPIFY)