Selection Sort
Selection sort repeatedly selects the smallest element from the unsorted portion and places it at the beginning.
Selection Sort Visualization
Complexity
Time Complexity:
O(n^2)Space Complexity:
O(1)Pseudocode
for i from 0 to n-1:
minIndex = i
for j from i+1 to n:
if arr[j] < arr[minIndex]:
minIndex = j
swap(arr[i], arr[minIndex])Related Algorithms
Insertion Sort
Insertion Sort builds the sorted array one element at a time by inserting each element into its correct position. It's efficient for small datasets and nearly sorted arrays.
Time: O(n²) | Space: O(1)
Bubble Sort
Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. It's easy to understand but inefficient for large datasets.
Time: O(n²) | Space: O(1)