Sorting Algorithm
1. Permutation Sort
1) Find the all the permutations for the given list
2) Pick one permutation
3) Check whether it is sorted. If the given list is a sorted one, return the list
Example
1.[1,2,3] is given
2.Possible Permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]
3.Pick one permutation: [1,3,2]
=>No, not sorted.
4.Pick one permutation: [1,2,3]
=>Yes, it is sorted => return [1,2,3]
Implementation
https://gist.github.com/growingpenguin/b5e3730e4f04b30e2d6aa60957209953
2. Selection Sort
Professor Description (Recitation2)
1) Find the biggest with index <= i
2) Swap
3) Sort 1…i-1
It is usually called the prefix max function to find the biggest element of the array between index 0 and index i.
Professor code (Recitation2)
Example
Implementation
https://gist.github.com/growingpenguin/58b21a8fe8743642a724de6f55fb5b55
3. Insertion Sort
Implementation
https://gist.github.com/growingpenguin/d845a69964587406e6dfa245e4e7a1b8
4. Merge Sort
geekforgeeks MergeSort
Example
Implementation
https://gist.github.com/growingpenguin/fd2880f24745c4e32663892913094da1