Sorting Algorithms in a few Words
3 min readFeb 27, 2021
This note contains the basic ideas of different sorting algorithms in brief and plain words. It is for my own revision purpose and does not guarantee to be fully accurate.
Selection Sort
- Start from A[0] (subject), find the smallest number among all elements
- Swap the subject element with the smallest number that was found
- Repeat the above steps start from the next position (A[1])
- Keep on repeating until the last cycle
- It is basically the worst sorting algorithm as you must check until the last cycle and can’t skip checking any element
- Runtime: O(n²)
Bubble Sort
- Start from A[0], compare A[0] with A[1]. Swap them if A[0] is larger
- Shift the comparison window by 1. That’s mean A[1] and A[2] are to be compared in the next step
- Repeat until the last 2 elements are checked. By then the largest element will be at the last position and fixed
- Restart the checking from A[0]. Do the comparison and swap from A[0] until the last unfixed element
- Keep on repeating until no element is swapped in a cycle or reach the last cycle
- Runtime: O(n²)
Insertion Sort
- Start from A[1], compare A[1] with A[0]. Swap them if A[1] is smaller