Algorithms And Data Structures Codexery

Quicksort

Efficient divide-and-conquer sorting algorithm developed by Tony Hoare.

Quicksort

It is a divide-and-conquer algorithm that works by selecting a pivot element and partitioning other elements into sub-arrays, making it slightly faster than merge sort and heapsort for randomized data. Quicksort remains a commonly used algorithm for sorting and is a comparison sort that can sort items of any type with a defined less-than relation.

developed_by
Tony Hoare
type
Divide-and-conquer sorting algorithm
average_complexity
O(n log n)
worst_case_complexity
O(n^2)
also_known_as
Partition-exchange sort

Lore & Background

He needed to sort Russian words before looking them up in a dictionary on magnetic tape, and after finding insertion sort too slow, he devised quicksort. He wrote the partition part in Mercury Autocode but struggled with unsorted segments; upon returning to England, he was asked to write code for Shellsort, and his boss bet a sixpence that Hoare did not know a faster algorithm—a bet his boss ultimately lost.

Reader's Guide

Quicksort's significance lies in its efficiency and widespread adoption, appearing in Unix as the default library sort subroutine and lending its name to the C standard library subroutine qsort and Java's reference implementation. The algorithm is a family of closely related methods based on partitioning, with details varying across implementations. Nico Lomuto's simpler partition scheme, popularized by Bentley's Programming Pearls and Introduction to Algorithms, is easier to understand but less efficient than Hoare's original, performing three times more swaps and degrading to O(n^2) when all elements are equal.

Did You Know?

More in Algorithms And Data Structures 1-24

Elsewhere in the Algorithms And Data Structures universe

Spotted an error? Know more?

This is a living reference — every entry is fact-audited, and reader corrections feed straight into our audit queue. Suggest an edit · See this site's audit record

Comments

Loading…
Open in the interactive codex →