Skip to content

Resource · Guide or article

Heap Sort

Heap sort described as selection sort improved with a heap: repeatedly take the maximum and grow a sorted region.

Reviewed

Open the original: Heap Sort (opens the original site in a new tab)

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

Heapsort is a comparison-based sorting algorithm. Heapsort can be thought of as an improved selection sort: like that algorithm, it divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element and moving that to the sorted region. The improvement consists of the use of a heap data structure rather than a linear-time search to find the maximum.

PrepKit overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Reference

What it covers

  • Relationship to selection sort and the role of the heap.
  • Complexity table: n log(n) best, average, and worst; memory 1; not stable.

How to use it

PrepKit study advice, not a claim made by the source.

Code heapify and the sort loop, then explain aloud why it uses constant extra memory yet is not stable.

Scope and limitations

Very short: no heap construction steps or sift-down explanation beyond the animations. One Wikipedia link. A Portuguese version is linked.

Access and format

English README hosted free on GitHub (trekhleb/javascript-algorithms, MIT).

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/algorithms/sorting/heap-sort/README.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email