Sorting Algorithms

Bubble Sort

Bubble works based on checking a pair and swapping it if it is the wrong way round, repeated for each pair in the array/list.

It is a very basic sort and can be implemented with almost no effort.

It has an average time complexity of n2.









Insertion Sort

Insertion Sort works by taking the second element and comparing it with the first. It swaps them if the second is smaller.

It then takes the third element and compares it with the second then first, placing it above the first element to be smaller.

This process is repeated for every element.

It has a time complexity of n2





Merge Sort

Merge Sort sorts by using a divide and conquer approach, splitting the original list into multiple sublists.

These sublists are further split again and again until they become individual elements.

These elements are combined into sublists again and then into the final list.

It has a time complexity of nLog(n)






Quick Sort

Quick Sort works by selecting an element as a pivot (In the example below, this being the middle element).

The sort then moves all elements smaller than the pivot to the left and all elements larger to the right.

A new pivot is selected from the sublists and the process repeats, until the list is sorted.

It has a time complexity of n2





Bogo Sort

Bogo Sort is a simple sort that randomly scrambles the elements in the list.

The list is checked to see if it is sorted; if not, the list is rescrambled.

It has a time complexity of (n+1)! on average

Miracle Sort

Miracle Sort is a very simple sort that requires no programming at all.

The list is left alone with the hope that eventually it will become sorted.

It has an average time complexity of no.