Technology

Sorting Algorithms

Sorting algorithms put data into a chosen order, with different methods trading off speed, memory use, and how they handle equal values.

Sorting algorithms arrange items by a key, such as a number, name, or date. Common methods include insertion sort, merge sort, quicksort, and heapsort, each using a different strategy to establish order. For n items, merge sort and heapsort have worst-case running times proportional to n log n, while insertion sort can require time proportional to n². A stable sorting algorithm preserves the original relative order of items with equal keys, which matters when sorting records by multiple fields.

Where this leads

Verified sources