# Heap sort Python code you can run

> Run heap sort Python code and see its max-heap algorithm move the largest value.

Source: https://fullbytedeveloper.com/blog/heap-sort-python
Keyword: HEAP
Published here: 2026-11-23

I built this heap sort Python level so you can see it. The repository documents the command [1].

## Run heap sort Python code

```bash
python3 heap_sort.py
```

You should see the largest value move to the last open position on each round.

## Run heap sort on an ordered row

```bash
python3 heap_sort.py 1 2 3 4 5 6 7 8
```

You should see the stage-clear row remain `1 2 3 4 5 6 7 8` and print compare and swap counters.

## Race heap sort with the other sorting levels

The arcade races every current sorting level on the same shuffled 10,000-number row. It runs each plain sorting function three times and prints the median time [1].

```bash
python3 arcade.py --race 10000
```

You should see Bubble sort, Selection sort, Insertion sort, Merge sort, Quick sort, and Heap sort with a time and extra-memory line.

## Inspect the heap sort algorithm

Heap sort restores the heap after moving its top value to the end [2]. [Quick sort relies on a pivot](/blog/quick-sort-pivot-worst-case), while [merge sort uses a second row](/blog/merge-sort-python). Browse [Dev explainers](https://fullbytedeveloper.com/blog/topic/dev-explainers) for the rest of the series.

Send this to the friend who wants to picture a heap without a separate tree object.

## Sources

1. [ALGO ARCADE README](https://github.com/kamilikamil/algo-arcade/blob/main/README.md)
2. [ALGO ARCADE heap sort source](https://github.com/kamilikamil/algo-arcade/blob/main/heap_sort.py)
