In Detail : A Simple Selection Sort In Java Along With Generics Implementation
Selection Sort : Selection Sort is an elementary sorting algorithm with O(n^2) running time in worst case. A Real Life Example Illustrating Selection Sort : Consider you have a pile of electricity bills for the past year, and you want to arrange them in ascending order from staring from January. One approach might be to look through the pile until you find the bill for January and pull that out. Then look through the remaining pile until you find the bill for February and add that behind January. Proceed through the ever-shrinking pile of bills to select next one until you are done. This is the inspiration for our Selection Sort. How Selection Sort Works ? Just like all elementary sorting algorithms , Selection Sort also contains a double for loop. For every i th iteration of outer for loop, Selection Sort "selects" smallest element in the array, places it into position i. In other words, Selection sort finds ...