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


Not Available

Table of Contents

    1. Technical Definition
    2. Discussion
    3. Plain-Word Explanation
    4. Code Implementation
  1. How To Cite
  2. References
  3. Discussion

Technical Definition


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
        push!(sorted, val)
        deleteat!(arr, ind)
    return sorted

How To Cite

Zelko, Jacob. Selection Sort. December 21 2020.



CC BY-SA 4.0 Jacob Zelko. Last modified: January 17, 2023. Website built with Franklin.jl and the Julia programming language.