Facebook LinkedIn Discord Youtube E-mail

Notes

Algorithms ▸
Selection Sort Algorithm - bjelDark

Animation | Rigging | UE | Unity | Scripts | Photography | MISC

Category selection

Selection Sort Algorithm

Very slow sorting algorithm.

Empty array is created, and it will be populated with items in sorted order.

Algorithm works by finding the smallest item in an array, popping it (taking it from the array), and appending it to the sorted array.

Now, the array to sort is smaller by one element, and is getting smaller with each step.

This is repeated until entire array is exhausted, so algorithm must check each item (n times).

Finding smallest item is done by marking the first element as smallest, then taking the second and comparing the two.

If the second is smaller, smallest item is updated; it's left as it is, if first one is smaller.

Moving on to the third element, comparimg, updating if needed. This procedure is repeated by taking next elements, comparing, updating, until the end of array is reached (n times again).

Algorithm's Complexity: Big O(n2)

  Selection Sort [Python Implementation]: