Beginner Topic 9 of 51 Algorithms
Selection Sort
Repeatedly selecting the minimum from the unsorted part.
How it works
Selection sort divides the array into a sorted prefix and an unsorted remainder. On each pass it scans the remainder for the minimum element and swaps it into the next position of the prefix. It always makes O(n squared) comparisons regardless of input order, but performs at most n minus 1 swaps, and the standard version is not stable.
Where it is used
Selection sort is useful when writes are far more expensive than reads, such as on flash memory, and for teaching. It is simple to implement and has predictable behavior on any input.
Common pitfall
It does not benefit from partially sorted data, since it always scans everything. Swapping can break the relative order of equal elements, which matters when sorting records by multiple keys. For anything beyond small arrays, choose merge sort, quicksort or the built-in sort.
Where it fits in the course
Selection Sort is topic 9 of 51 in Algorithms, rated Beginner. It follows Bubble Sort. The next topic is Insertion Sort.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Algorithms quiz.
- Explore the Sorting Algorithms visualizer: Bubble, selection, insertion, merge and quick sort animated.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Algorithms quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Selection Sort?
Where do people use Selection Sort?
What is the most common mistake with Selection Sort?
What should I learn before this topic?
How can I practice it?
Is Selection Sort hard to learn?
How long does it take to learn Selection Sort?
Which topics are related to Selection Sort?
What should I study after Selection Sort?
Related topics
- Bubble Sort (Algorithms)
- Insertion Sort (Algorithms)
- Binary Search (Algorithms)
- Merge Sort (Algorithms)