bogo
bubble
insertion
Intelligent Design
merge
miracle
selection
stalin
quick
Sorting Algorithms
Bogo Sort
Bogo sort repeatedly randomises the list, then checks if the list is sorted. If not, it randomises it again.
This is an example of an esoteric sorting algorithm, intended primarily as a joke.
Bubble Sort
Bubble sort is one of the simplest sorting algorithms. It repeatedly compares adjacent elements, swapping them if they aren't in the right order.
Insertion Sort
Insertion sort iterates through the list and inserting each element into the correct position in the sorted list.
Typically, only a single list is used, with the sorted portion being at the start of the list, however it can be shown with two lists.
Intelligent Design
Intelligent design sort is based on the theory of intelligent design, assuming that input list was already sorted optimally by an intelligent Sorter.
Read more about Intelligent Design sort here
Merge Sort
Merge sort is an example of a divide and conquer algorithm. It recursively divides the list into halves, until each half contains only a single element.
The halves are then repeatedly merged together, combined elements in the correct order.
Miracle Sort
Miracle sort is a very simple sorting algorithm as it makes no attempt to sort the list.
Instead, it waits for a miracle to happen, periodically checking if the list has become sorted. Mircale sort is another esoteric sorting algorithm
Selection Sort
Selection sort repeatedly finds the smallest element in the list and moves it to the front.
Stalin Sort
Stalin sort is another simple algorithm. It iterates through the list and compares each element to the one before it. If the element is out of order, it is eliminated.
This method of sorting is the only algorithm that will only require a single pass, even if some items are purged in the process and is another example of an esoteric sorting algorithm.
Quick Sort
Quick sort is another divide and conquer algorithm. It first selects a pivot element (typically the middle item) and moves any items less than the pivot to the left, and any items greater than the pivot to the right.
It repeates this process recursively, selecting a new pivot in each sublist, until the sublist has a length of 1 or all elements have been used as a pivot.
Time & Space Complexity
| Algorithm | Best Case | Average Case | Worst Case | Space Complexity |
|---|---|---|---|---|
| Bogo Sort | O(n) | O(n!) | O(∞) | O(1) |
| Bubble Sort | O(n) | O(n²) | O(n²) | O(1) |
| Insertion Sort | O(n) | O(n²) | O(n²) | O(1) |
| Intelligent Design Sort | O(1) | O(1) | O(1) | O(1) |
| Merge Sort | O(n logn) | O(n logn) | O(n logn) | O(n) |
| Miracle Sort | O(n) | O(∞) | O(∞) | O(1) |
| Selection Sort | O(n²) | O(n²) | O(n²) | O(1) |
| Stalin Sort | O(n) | O(n) | O(n) | O(1) |
| Quick Sort | O(n logn) | O(n logn) | O(n²) | O(n) |