golang tutorial - Sorting In Golang | Sorting In Go - golang - go programming language - google go - go language - go program - google language
Sorting In Golang
- Sorting is any process of arranging the items systematically
- ordering: arranging items in a sequence ordered by some criterion.
- categorizing: grouping items with similar properties.
- The most common uses of sorted sequences are:
- making lookup or search efficient;
- making merging of sequences efficient.
- enable processing of data in a defined order.
- Go’s sort package implements sorting for builtins and user-defined types. We’ll look at sorting for builtins first.
Common sorting algorithms
- Bubble sort : Exchange two adjacent elements if they are out of order. Repeat until array is sorted.
- Insertion sort : Scan successive elements for an out-of-order item, then insert the item in the proper place.
- Selection sort : Find the smallest element in the array, and put it in the proper place. Swap it with the value in the first position. Repeat until array is sorted.
- Quick sort : Partition the array into two segments. In the first segment, all elements are less than or equal to the pivot value. In the second segment, all elements are greater than or equal to the pivot value. Finally, sort the two segments recursively.
- Merge sort : Divide the list of elements in two parts, sort the two parts individually and then merge it.