Insertion Sort
Last updated
Last updated
Insertion Sort is another sorting algorithm that we can use to sort arrays. Going back to the statistics package example discussed in the previous chapter, we can use Insertion Sort to sort our array of integers so that we can find the median value.
As with Selection Sort, Insertion Sort uses loops to iterate over the array. However, there is an important difference: while Selection Sort searches for the smallest element on each iteration, Insertion Sort immediately puts each element into its designated position as it iterates over the array.
Here is an example of what an Insertion Sort algorithm looks like: