Very straightforward algorithm to sort numbers in array: compare one and next one. If the first one is bigger and next one, swap them. Repeat this iteration twice to make sure the value at index 0 can travel index n - 1.
Anytime when you find smaller element than previous element, go back and find the element that is smaller than the element the program is looking at. If it is already sorted, runtime analysis for Insertion Wort is O(n).
Start from the tail of the array, find the biggest one, and swap the tail and biggest element. Next, don’t include the last element of array and find the biggest one. Swap the biggest one with the tail. Repeat this till you only have one element.
Split an array into two arrays. Sort each array and merge two sorted array into the original one. My code is not clearn, but it helped me understand how merge sort works. Keep this recursively.
Pick a random element that is used as pivot. Start at the beginning of array and end of the array. Increment starting index while the element is less than or equal to pivot number. Decrement the end of the array index while the element is greater than or equal to pivot. If low is less than high, swap low index element and high index element. If low is greater than high, swap high and pivot number. Split array into before high and after high. Repeat the same thing recursively.
I like quicksort the best since I spent a lot of time to understand what is going on. Hope my code helps you to implement them!