sort

module
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2025 License: MIT-0

README

Sorting algorithms

Go Reference Go Report Go Coverage

Sorting algorithms implemented in Go.
Use as a learning resource.
Clarity and simplicity, not so much performance, are the goals.

Quicksort

The most interesting (and more practical) algorithm here is Tony Hoare's Quicksort. It's relatively fast, only slightly slower than the standard library on the average case. It's flexible, and gives you asymptotically optimal algorithms for median finding, top-K, etc (which the standard library lacks).

quicksort visualization

This version avoids quadratic behavior by using median-of-ninthers when a bad pivot is detected:

median-of-ninthers visualization

The algorithm is fully deterministic, and every step contributes to partially sorting the array.

Heapsort

An implementation of Floyd's bottom-up Heapsort.

heapsort visualization

Shellsort

An implementation of Shellsort with the Gonnet & Baeza-Yates gap sequence.

heapsort visualization

Credits

Visualizations thanks to: github.com/invzhi/sorting-visualization

Directories

Path Synopsis
Package heap implements Floyd's bottom-up Heapsort.
Package heap implements Floyd's bottom-up Heapsort.
Package quick implements Tony Hoare's Quicksort and Quickselect.
Package quick implements Tony Hoare's Quicksort and Quickselect.
Package shell implements Shellsort with the Gonnet & Baeza-Yates gap sequence.
Package shell implements Shellsort with the Gonnet & Baeza-Yates gap sequence.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL