Implementation happens on the following initial description:
We pick up the first element and assume it is the smallest in the array. After that we iterate trough the array searching for the real smallest element. If we find one, we switch our current with the found one and continue with the next element.
🤔 Thoughts
This is basicly the reverse of the Insertionsort. The easiest way to compare the two is to imagine a hand full of playing cards that should be sorted.
Insertion
We let the first card be and go to the second one. Pick it up and compare it the cards to the left and keep moving left until the card we are holding is bigger then the card to the left and drop it there. To back to our starting point and repeat the process until the last card was picked up and droped.
Selectionsort
We look at our first card and go trough all cards to the right. On the way we mark the lowest card we found. After we went all the way back to the right, we remember the marked card and switch it with the first one and repeat the process with the second card and so on until we reach the last card on the right.
Selectionsort
Implementation happens on the following initial description:
We pick up the first element and assume it is the smallest in the array. After that we iterate trough the array searching for the real smallest element. If we find one, we switch our current with the found one and continue with the next element.
🤔 Thoughts
This is basicly the reverse of the Insertionsort. The easiest way to compare the two is to imagine a hand full of playing cards that should be sorted.
Insertion
We let the first card be and go to the second one. Pick it up and compare it the cards to the left and keep moving left until the card we are holding is bigger then the card to the left and drop it there. To back to our starting point and repeat the process until the last card was picked up and droped.
Selectionsort
We look at our first card and go trough all cards to the right. On the way we mark the lowest card we found. After we went all the way back to the right, we remember the marked card and switch it with the first one and repeat the process with the second card and so on until we reach the last card on the right.