Selection Sort
Selection Sort is a simple in-place comparison sorting algorithm. It divides the input list into two parts: a sorted sublist of items which is built up from left to right at the front (left) of the list and a sublist of the remaining unsorted items that occupy the rest of the list.
### How it works: 1. Initialize the minimum value index to the first element in the unsorted sublist. 2. Iterate through the unsorted sublist to find the actual minimum value. 3. Swap the found minimum value with the first element of the unsorted sublist. 4. Move the sublist boundary one element to the right. 5. Repeat until the array is completely sorted.
Selection sort is noted for its simplicity and has performance advantages over more complicated algorithms in certain situations, particularly where auxiliary memory is limited.
### How it works: 1. Initialize the minimum value index to the first element in the unsorted sublist. 2. Iterate through the unsorted sublist to find the actual minimum value. 3. Swap the found minimum value with the first element of the unsorted sublist. 4. Move the sublist boundary one element to the right. 5. Repeat until the array is completely sorted.
Selection sort is noted for its simplicity and has performance advantages over more complicated algorithms in certain situations, particularly where auxiliary memory is limited.
Constraints
- 1 <= array.length <= 10^4
- -10^9 <= array[i] <= 10^9
TimeO(O(n²))
SpaceO(O(1))
Ready to startStep 0 / 0
TypeScript