Sorting algorithm

Edit · View history

Sorting algorithm

A sorting algorithm is a method for arranging a collection of items (such as numbers, strings, or records) into a specific order, most commonly numerical or lexicographical. Sorting algorithms are fundamental in computer science, used as building blocks for more complex operations like Binary Search, Data Merging, and Database Indexing.

Overview

Sorting algorithms can be classified by several criteria. The most common distinction is between comparison-based and non-comparison-based sorts. Comparison sorts, such as Quicksort and Merge Sort, determine order by comparing pairs of elements using a comparison operator. Non‑comparison sorts, such as Radix Sort and Counting Sort, exploit special properties of the data (e.g., integer keys) to achieve faster asymptotic times under certain conditions.

Key properties of sorting algorithms include:

History

Early mechanical sorting methods include punched card sorters used in the late 19th and early 20th centuries. The first computer sorting algorithms were developed in the 1940s and 1950s alongside stored-program computers. Bubble Sort was described by Edward H. Friend in 1956, though it was known earlier as "sorting by exchange". Insertion Sort and Selection Sort are older, often taught as textbook examples of algorithm analysis.

Notable milestones:

Common sorting algorithms

Applications

Sorting is used in Search Algorithms, Data Compression, Graph Algorithms (e.g., Kruskal's Algorithm requires sorting edges), and Database Management (for Indexing and Query Optimization). Many programming languages provide built‑in sorting functions (e.g., Python’s sorted() implemented using Timsort, a hybrid algorithm).

See also