update selection sort algorithm

This commit is contained in:
Aditya 2024-05-28 11:06:18 +05:30
parent 5a1269694d
commit f2205cf799
Signed by: aditya
SSH key fingerprint: SHA256:jL1IvWsjjlPtw6HvDIHfXfhO9IkIokNEyIfuFhSdoyU

View file

@ -28,6 +28,15 @@ Here's how Selection Sort works step by step:
5. Repeat steps 2-4 until the entire list is sorted.
```
for i := 1 to n do
{
Examine a[i] to a[n] and suppose
the smallest element is at a[j];
Interchange a[i] and a[j];
}
```
The algorithm's time complexity is O(n<sup>2</sup>) for all cases (worst, average, and best), making it
inefficient on large lists compared to more advanced algorithms like quicksort, mergesort or
heapsort. However, Selection Sort has its advantages such as simplicity and performing only a