Skip to content
BENIBIX Learn

Sorting Algorithm

Development🧮 Algorithms & Data StructuresSorting Algorithms

Also known as Sort, Sorting

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

Think of it like

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

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.

Why it matters

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

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 code

python
>>> sorted([5, 2, 9, 1])
[1, 2, 5, 9]
Python's built-in sort puts the numbers smallest first.

Common mistake

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

Key takeaways

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