Full Byte Developer.

Heap sort Python code you can run

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

Published here · 2 sources

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, while merge sort uses a second row. Browse Dev explainers for the rest of the series.

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

Keep this guide

By Full Byte Developer

Filed under Dev explainers

Questions about this guide

How do I run heap sort Python code?

Run python3 heap_sort.py from the ALGO ARCADE folder.

Where does the heap sort algorithm keep the largest value?

A max heap puts it at the top before heap sort sends it to the last open row position.

Sources

Next in this stack