Full Byte Developer.

Quick sort Python code you can run

Run quick sort Python code, inspect its pivot, and compare the quick sort algorithm with earlier sorts.

Published here · 2 sources

I built this quick sort level so you can inspect its pivot. The repository documents the same terminal command used by the level [1].

Run quick sort Python code

bash
python3 quick_sort.py

You should see the pivot reach a final position, then both remaining sides sort.

Run quick sort's ordered-row weak case

bash
python3 quick_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 quick 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 quick sort algorithm pivot

This level chooses its last value as the pivot [2]. Bubble sort swaps neighbors, selection sort places the smallest value, insertion sort grows a prefix, and merge sort writes an extra row. Run heap sort's predictable pyramid next, or browse Dev explainers.

Send this to the friend who wants to inspect a quick-sort pivot.

Keep this guide

By Full Byte Developer

Filed under Dev explainers

Questions about this guide

How do I run quick sort Python code?

Run python3 quick_sort.py from the ALGO ARCADE folder.

When does this quick sort algorithm use lopsided partitions?

This implementation chooses the last value as its pivot, so an ordered row can produce lopsided partitions.

Sources

Next in this stack