Selection sort in java

Selection sort is an in place comparison sorting algorithm. It is very simple to implement but it does not go well with large number of inputs.

Selection sort algorithm :

  • Find the minimum element in the list.
  • Swap minimum element with current element.
  • Repeat the whole process until array is fully sorted.
Below visualization will make it more clear

Java program to implement Selection sort:

When you run above program, you will get below output:

Time complexity:

Best case : O(N^2)
Average case : O(N^2)
Worst case : O(N^2)

Add Comment