March 2019
Intermediate to advanced
336 pages
9h 9m
English
Insertion sort is an algorithm that creates a final sorted array one element at a time. The algorithm's performance is of the order O(n2). This algorithm is less efficient on large collections than other algorithms, such as quick, heap, and merge sort. In real life, a good example of insertion sort is the way cards are manually sorted by the players in a game of bridge.
The implementation of the insertion sort algorithm is shown in the following code snippet. The RandomSequence function takes the number of elements as a parameter and returns an array of random integers:
//main package has examples shown// in Go Data Structures and algorithms bookpackage main// importing fmt and bytes packageimport ( "fmt" "math/rand" "time")// randomSequence ...
Read now
Unlock full access