How to implement Selection Sort in java

Posted on Updated on

Selection sort is a sorting algorithm, specifically an in-place comparison sort. It is a combination of searching and sorting. During each pass, the unsorted smallest (or largest) value is moved to its proper position in the array. In the selection sort, the inner loop finds the next smallest (or largest) value and the outer loop places that value into its proper location. The total number of iterations are one less than total number of elements in the array.

Performance of Selection Sort

Worst case performance : О(n2)
Best case performance : O(n2)
Average case performance : О(n2)

Understand Selection Sort with an example.

Selection-sort

Let us see how this can be implemented in Java.

Output

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.