SortingD3Phase 2heapin-placeselection

Heap Sort

Heap-backed sorting sequence visualizing sift-up and sift-down operations.

Easy Explanation

Heap Sort builds a max-heap so the largest value is easy to remove, then repeats to produce sorted order.

Renderer Mode

`Simple` uses abstract, short-form-friendly visuals. `Advanced` keeps the current detailed view.

Arrays + Grid
Visualizer
O(1)Heap Sort
Deterministic max-heap build and extraction playback with sift-down compare and swap events.

Phase

Extract Max

Heap Size

0

Comparisons

0

Swaps

0

Ready

Press Play or Step to start execution.

No values available for visualization.
Heap Sort Implementation
Pseudocode + TypeScript
Reference implementation examples are intentionally abstracted from the playback engine so learners can map concepts to code.
pseudocode
function heapSort(values):
  n <- length(values)

  for i from floor(n / 2) - 1 down to 0:
    siftDown(values, i, n)

  for end from n - 1 down to 1:
    swap values[0], values[end]
    siftDown(values, 0, end)

  return values

function siftDown(values, root, heapSize):
  while true:
    largest <- root
    left <- 2 * root + 1
    right <- left + 1

    if left < heapSize and values[left] > values[largest]:
      largest <- left

    if right < heapSize and values[right] > values[largest]:
      largest <- right

    if largest == root:
      break

    swap values[root], values[largest]
    root <- largest
1.00xNo Run