# Sorting Algorithm

> Steps that put a list in order, like small to big or A to Z.

**Field:** Software Development  
**Category:** Algorithms & Data Structures  
**Also known as:** Sort, Sorting

## Think of it like

Think of it like putting cards in order. There are many ways, and some are much faster.

## Definition

A sorting algorithm puts a list of items in order, like smallest to largest or A to Z. There are dozens of them, and they differ in speed, memory and how they treat equal items. Simple ones like bubble sort take O(n²) steps. Good ones like merge sort and quicksort take about O(n log n). In practice you call the sort your language gives you, which is fast and well tested.

## Example

Emma sorts 5, 2, 9, 1 with Python's sorted and gets 1, 2, 5, 9. For a million items it still takes under a second.

## Example code

```python
>>> sorted([5, 2, 9, 1])
[1, 2, 5, 9]
```

Python's built-in sort puts the numbers smallest first.

## Why it matters

Sorted data is far faster to search and easier to read. Sorting is one of the most common jobs code does.

## Common mistake

Writing your own sort for real work. The built-in one is faster and has been tested for years.

## Three principles

- **Puts items in order.** By any rule you choose.
- **Many kinds.** Speed and memory differ.
- **Use the built-in.** For real code.

## Related terms

- [Bubble Sort](https://learn.benibix.com/term/development/bubble-sort)
- [Merge Sort](https://learn.benibix.com/term/development/merge-sort)
- [Quicksort](https://learn.benibix.com/term/development/quicksort)
- [Binary Search](https://learn.benibix.com/term/development/binary-search)
- [Insertion Sort](https://learn.benibix.com/term/development/insertion-sort)
- [Selection Sort](https://learn.benibix.com/term/development/selection-sort)

---

Source: https://learn.benibix.com/term/development/sorting-algorithm
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
