# Selection Sort | kirupa.com

**URL:** https://forum.kirupa.com/t/selection-sort-kirupa-com/457095
**Category:** programming
**Created:** [January 4, 2015, 1:31am UTC](https://forum.kirupa.com/t/selection-sort-kirupa-com/457095 "2015-01-04T01:31:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [January 4, 2015, 1:31am UTC](https://forum.kirupa.com/t/selection-sort-kirupa-com/457095/1 "2015-01-04T01:31:47Z")

</div>

by [kirupa](http://www.kirupa.com/me/index.htm) | 3 January 2015

A slow but very easy-to-comprehend sort algorithm is **selection sort**. It's approach is very simple. Let's say you have a boring list of values that you want sorted

* * *
This is a companion discussion topic for the original entry at [http://www.kirupa.com/sorts/selectionsort.htm](http://www.kirupa.com/sorts/selectionsort.htm)

---

<div class="post-metadata">

### Author: ![James\_Curran](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/james_curran/32/7138_2.png) [@James\_Curran](https://forum.kirupa.com/u/James_Curran)
#### Post date: [January 7, 2015, 7:25pm UTC](https://forum.kirupa.com/t/selection-sort-kirupa-com/457095/2 "2015-01-07T19:25:07Z")

</div>

Your description is very good, however you drag too much implementation detail into the basic description. notably when you swap two items to move the smallest into the sorted portion.

You assumption is that the collection to be sorted can only be in an array. But the are many other ordered collection types.

So, in your initial description, you should only mention finding the smallest and moving it to a new collection (which you mention in a passing way as “cray, cray”. This is in fact the best way to handle it if the collection were a linked list. In a addition to be more generic, it will make the whole explanation simpler and easier to understand.

You should then discuss swapping as an optimization for the special case of the collection being an array.

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [January 8, 2015, 3:49am UTC](https://forum.kirupa.com/t/selection-sort-kirupa-com/457095/3 "2015-01-08T03:49:45Z")

</div>

James - that is really good feedback. I’ll revise the tutorial to have the explanation focus on the “separate” collection approach. You are right that having the sorted items in the front is an implementation detail and doesn’t need to be called out so early!

😄
