To Expand The #Selftaught Movement Across Southeast Asia!

If you're a beginner in Sorting Algorithms, the first few sorting algorithms that you are going to learn would be good ol' Bubble Sort. It's simple to code and the easiest to understand out of all the other sorting algorithms. I'll explain a bit further on how to code this in a while.

Firstly, let's write an algorithm in order to sort these numbers using Bubble Sort. Keep in mind that each pass in bubble sort would 'Bubble' the biggest number to the end of the list.

Algorithm:

1. Go through the list of numbers
2. Only sort out the numbers that have not been sorted yet
3. When going through the list of unsorted numbers, swap numbers accordingly when met with a bigger number.

So here is an illustration of what happens with the numbers [5,4,1,2,8]! Notice that the biggest number in the list appears at the end! In the 2nd Pass, the second biggest element would bubble to the end of the list! For the 3rd pass, we will only compared the numbers from 0 to len(array) - the number of items already sorted The very last pass which only compares the final two numbers

Now that we are done with Bubble Sort, let's take a look at another basic sorting algorithm called Insertion Sort.

Insertion sort makes use of having pointers to keep track of the last few items that we have sorted. In a way, it is similar to Bubble Sort whereby the first few items in the list would be sorted as we traverse the list.

Algorithm:

We can assume that the first item in the list is already sorted so we can start traversing the list from the second item!

1. Traverse list from 1 to n (length of list)
2. We initialise a variable, inserted_num to store the new inserted element that we are looking at in this case is the array[i]
3. We have a pointer, position,  to track the current position of sorted numbers, this would be (i-1) to begin with!
4. We compare the value of the inserted element with the current element in the sorted number array list
5. We will stop when we reach a number that is smaller than the number to be inserted
6. Insert the number at its correct position!