the cedar ledge

# Selection Sort

Date: December 21 2020

Summary: Selection sort utilizes repeated usages of linear searches to

Keywords: ##zettel #selection #sort #algorithms #archive

# Bibliography

Not Available

### Plain-Word Explanation

Imagine that I, your humble sorter, is seated in front of 10 cards each with a value between the numbers of 1 - 10. Every single card is face up and is in a line with each card next to the other. I know you want the cards sorted, so what I do, since I am somewhat slow, is look through every single card in that line and find the smallest valued card.

I take the smallest card and start a new row of cards which are sorted from the smallest valued card to the largest valued card. I then repeat this process and take the next smallest value and put it next to the smallest card I found. I continue this back and forth process until all the cards are sorted. That is tiring, but this method of sorting is called selection sort!

### Code Implementation

``````function selectionsort(arr)
sorted = [] #
while length(arr) > 0
val = arr[1]
ind = 1
for curr = 2:length(arr)
if arr[curr] < val
val = arr[curr]
ind = curr
end
end
push!(sorted, val)
deleteat!(arr, ind)
end
return sorted
end``````

## How To Cite

Zelko, Jacob. Selection Sort. https://jacobzelko.com/12212020214012-selection-sort. December 21 2020.

## Discussion

CC BY-SA 4.0 Jacob Zelko. Last modified: May 19, 2024. Website built with Franklin.jl and the Julia programming language.