March 2019
Intermediate to advanced
336 pages
9h 9m
English
Selection sort is an algorithm that divides the input collection into two fragments. This sublist of elements is sorted by swapping the smallest or largest element from the left of the list to the right. The algorithm is of the order O(n2). This algorithm is inefficient for large collections, and it performs worse than the insertion sort algorithm.
The following code shows the implementation of the SelectionSorter function, which takes the collection to be sorted:
//main package has examples shown// in Go Data Structures and algorithms bookpackage main// importing fmt packageimport ( "fmt")// Selection Sorter methodfunc SelectionSorter(elements []int) { var i int for i = 0; i < len(elements)-1; i++ { var min int min = i var j int ...Read now
Unlock full access