Selection Sort🛫
selection sort is a sorting algorithm that is used to sort an array/list.
Time Complexity
The time complexity of the selection sort is O(n²). i.e. Quadratic time.
Explanation
In Selection sort, we do the following operations:
- First, pick an element from a list
- Second, we compare that element with the other remaining elements in this list.
- Repeat step first until the list is empty.
So, we have to perform step first for every element in the list, and the time complexity for that is O(n)
And then we have to compare that element with the other remaining elements in the list, and the time complexity for that is O(n — z), where z is the number of elements we have already checked, but since we ignore constants in Big O notation, so instead of writing O(n — z) we will just write it as O(n)
So we have O(n * n) time complexity for the whole algorithm, which we can also write as O(n²).