Selection Sort is a comparison-based sorting algorithm. It sorts an
array by repeatedly selecting the smallest (or largest) element from
the unsorted portion and swapping it with the first unsorted element.
This process continues until the entire array is sorted.
-
First we find the smallest element and swap it with the first
element. This way we get the smallest element at its correct
position.
-
Then we find the smallest among remaining elements (or second
smallest) and swap it with the second element.
-
We keep doing this until we get all elements moved to correct
position.
Complexity Analysis of Selection Sort
Time Complexity: O(n2) ,as there are two nested loops:
- One loop to select an element of Array one by one = O(n)
-
Another loop to compare that element with every other Array element
= O(n)
- Therefore overall complexity = O(n) * O(n) = O(n*n) = O(n2)
Usage Tips:
- Enter positive numbers separated by commas (e.g., 5, 10, 15)
- Maximum recommended input: 125
- Maximum array size: 50 numbers
- Larger numbers will be automatically scaled to fit the display