The Definitive Guide to Selection Sort
Key Takeaways
- ✓Selection Sort achieves O(n²) average-case time complexity.
- ✓Space complexity is O(1).
- ✓Minimizes the number of swaps — exactly O(n)
- ✓When memory writes are expensive (flash memory, EEPROM)
- ✓Understanding Selection Sort is essential for technical interviews.
What Is Selection Sort?
How Selection Sort Works
Time & Space Complexity Analysis
Did You Get the Big O Right? NexusBro Will Tell You in Seconds.
Paste your algorithm. Get complexity analysis, edge cases, and optimizations.
Test My AlgorithmAdvantages and Disadvantages
Real-World Use Cases
Implementation Tips
Practice Problems
Unlock Unlimited QA Audits for $15.99/mo
Free: 5 audits/day. Pro $15.99/mo: 50/day + 250 pages. Pro Max $99/mo: unlimited audits, 10K pages, API access.
See PlansFrequently Asked Questions
Is selection sort stable?
Standard selection sort is not stable because the swap operation can change the relative order of equal elements. A stable variant exists using insertion instead of swapping, but it is less common.
Why does selection sort always take O(n²)?
Selection sort must scan the entire unsorted portion to find the minimum in each iteration, regardless of the input order. This means it performs n(n-1)/2 comparisons even on sorted input.
When is selection sort better than insertion sort?
Selection sort is better when the cost of writing/swapping is much higher than comparing, since it does exactly n-1 swaps. This is relevant for writing to flash memory or other media where writes are expensive.
Can selection sort be parallelized?
The minimum-finding step can be parallelized, but the sequential nature of the swap-and-advance step limits overall parallelism. Other algorithms like merge sort parallelize much more effectively.
What is the difference between selection sort and heapsort?
Heapsort can be seen as an optimized selection sort that uses a heap to find the maximum/minimum in O(log n) instead of O(n), improving overall complexity from O(n²) to O(n log n).
Related Articles
Unlock Unlimited QA Audits for $15.99/mo
Free: 5 audits/day. Pro $15.99/mo: 50/day + 250 pages. Pro Max $99/mo: unlimited audits, 10K pages, API access.
See PlansNoizz helps you discover and compare the best new products and tools. Try it free →
Is your site built to last?
Run a free QA audit and get your Site Health Score in seconds.
Check Your Site FreeNo signup required