Sorting algorithms
= an โ๏ธ Algorithm for sorting e.g. an ๐ Array (programming)
Algorithms
- Random sort:
- check if list = sorted
- Randomly permute(sort) the list
- repeat 1 if list != sorted
- โ N! complexity
- Selection sort:
- start at first element, compare to all other elements
- if there is a smaller element, swap the current element with it
- continue until end
- recursive: call function again without first element
- iterative: repeat loop at next element using loop counter
- Bucket sort:
- create an array with a spot for each possible value
- iterate through elements, add 1 to each corresponding spot in the array
- iterate through array, return corresponding element(s) for each spot
Recursive Algorithms
- Quick sort (O(n log n) - O(n^2)):
- Termination check: isSorted, array > 1?
- Identify pivot element, swap elements from left/right side to the other one if itโs smaller/bigger than the pivot
- Repeat recursively for each side