Selection Sort

Selection Sort

selectionSort.rb

Selection sort improves on the bubble sort algorithm, but it still isn't the pinnacle of efficiency. However, selection sort has its place in our coding tool bag because it can be used to quickly sort small lists. The algorithm isn't complicated, so implementing it in code can swiftly take care of a sorting need. Instead of comparing two elements within a data set, selection sort will search for the smallest element of the data set and move it to the beginning of the list. The same process is repeated for the second element and so on. It's interesting to observe that this algorithm also uses exchanges to sort. Other algorithms' efficiencies may be dependent on the starting order of a data set. That ...

Get Wicked Cool Ruby Scripts 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.