mirror of
https://git.adityakumar.xyz/dsa.git
synced 2024-11-09 21:39:43 +00:00
update selection sort algorithm
This commit is contained in:
parent
5a1269694d
commit
f2205cf799
1 changed files with 9 additions and 0 deletions
|
@ -28,6 +28,15 @@ Here's how Selection Sort works step by step:
|
||||||
|
|
||||||
5. Repeat steps 2-4 until the entire list is sorted.
|
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
|
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
|
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
|
heapsort. However, Selection Sort has its advantages such as simplicity and performing only a
|
||||||
|
|
Loading…
Reference in a new issue