Back to Dashboard
Selection Sort
A simple sorting algorithm that repeatedly finds the minimum element from the unsorted part and puts it at the beginning.
FastSlow
Initializing...
Time Complexity
Best
Average
Worst
Space Complexity
StabilityFALSE
In-placeTRUE
Explanation
What is Selection Sort?
Selection Sort is a simple sorting algorithm that divides the input list into two parts: a sorted sublist of items built up from left to right and a sublist of the remaining unsorted items that occupy the rest of the list.
Steps
- Find the smallest element in the unsorted part of the array.
- Swap it with the first element of the unsorted part.
- Move the boundary between the sorted and unsorted parts one element to the right.
Complexity
- Best Case:
- Average Case:
- Worst Case:
Pseudo Code
1procedure selectionSort(list)2 for i from 0 to list.length - 23 minIdx = i4 for j from i + 1 to list.length - 15 if list[j] < list[minIdx]6 minIdx = j7 swap(list[i], list[minIdx])8end procedure
Sponsor Ad