Selection Sort












complexity Analysis

Best-case: The best case occurs when the array is already sorted. So the number of comparisons required is N-1 and the number of swaps required = 0. Hence the best case complexity is O(N)

Average-case: The number of comparisons is constant in Bubble Sort. So in average case, there are O(N2) comparisons.

Worst-case: The worst-case condition for bubble sort occurs when elements of the array are arranged in decreasing order. In the worst case, the total number of iterations or passes required to sort a given array is (N-1). where ā€˜N’ is the number of elements present in the array.




code

                        
                            // Code will be generated here