Video · + 1 min read
Selection Sort
Given an array of size , the selection sort iterates through indices , at each step finding the minimum element of the sub-array and swapping its position with . See the following example of the selection sort:
64 25 12 22 11 // this is the initial, starting state of the array
11 25 12 22 64 // sorted sublist = {11}
11 12 25 22 64 // sorted sublist = {11, 12}
11 12 22 25 64 // sorted sublist = {11, 12, 22}
11 12 22 25 64 // sorted sublist = {11, 12, 22, 25}
11 12 22 25 64 // sorted sublist = {11, 12, 22, 25, 64}
This is since in the worst case you will have to search .

The selection sort algorithm.
Insertion Sort
The insertion sort iteratively sorts the first elements of the array, by finding what position the next element should go. This is because in the worst case, the array starts sorted in the opposite direction, so you need to make at most swaps.

The insertion sort algorithm.
Merge Sort
Merge sort is a recursive sort that splits an array in two halves and sorts each half, then merges the two sorted components together. Try proving that merge sort runs in !

The merge sort algorithm.
Beyond
Finally, here is a cute little video to show you some of the sorting algorithms.
