Sorting algorithm
An algorithm that puts data in order. They're compared by speed, whether they're in place (no extra array), whether they're stable, whether they're adaptive (use existing order) and whether they sort by comparing.
Example
Sorting 1 million numbers with merge sort costs about 20 million steps; with bubble sort, about 500 billion.
Test yourself: Sorting algorithm
What makes a good sort
What can be sorted with a sorting algorithm?
You can sort 1,000 students by grade, by last name or by age: the algorithm is the same, the comparison rule changes.
What makes a good sort
An adaptive sort, with already sorted data, works ___.
Insertion sort with 1,000 already sorted items does 999 comparisons; with reversed data, about 500,000.
What makes a good sort
A comparison sort can't be faster than O(___) in the worst case.
With 1 million items, no comparing algorithm can guarantee fewer than about 20 million comparisons.
0/3
â–¶ Play