Selection sort
Selection sort is another simple sorting algorithm. It is a stable sorting algorithm. In bubble sort, we find that in every pass, if adjacent elements are not in order, they are swapped. Selection sort provides an improvement over bubble sort, with one swapping in every pass. In every pass, it finds out the largest or the smallest element and puts it in the right position. Consider that we have a sequence of integers.
Our sequence has [12,10,16,11,9,7] as elements. We can understand how selection sort works on this given sequence, with the help of the following diagram:
In the first pass of selection sort, the algorithm will look ...
Get Learning Functional Data Structures and Algorithms now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.