Comparisons are blue,

swaps are red.

…

Insertion sort works by inserting elements from an unsorted array into a sorted subsection of the array, one item at a time. Insertion sort is a sorting algorithm that builds a final sorted array (sometimes called a list) one element at a time.

The insertion sort, although still O(n2), works in a slightly different way. It always maintains a sorted sublist in the lower positions of the list. Each new item is then "inserted" back into the previous sublist such that the sorted sublist is one item larger.

Insertion Sort is one of the simpler sorting algorithms. It's highly intuitive, stable, in-place, and of comparison-type.

Insertion sort is a great sorting algorithm for small data sets. It's especially good at inserting new elements in the sorted list, because it only needs to create one link between two adjacent items that are already ordered correctly.

Insertion sort is a sorting algorithm based on the idea that one element from an input list of elements will be consumed in each iteration. The output should always remain sorted, and it's up to you whether or not this property interests you!

Based on its name alone, insertion sort can seem like your ordinary homework assignment: insert A into B until they are ordered correctly. But before the implementation phase begins with pencils scribbling furiously against paper, consider how much thought must go into designing such a simple task-- after all, what if we need fifty sorts?

A quicksort algorithm is a sorting technique that relies on partitioning the data set into two parts and recursively processing these smaller sets. The process can be demonstrated with an example of 5 numbers: 3, 2, 6, 4, 1. In this case there are three elements in each part: one less than or equal to number six (3), four greater than but not larger than number six (4) and one more than both elements five(5). This leads us to conclude that our input array was sorted after applying the first iteration which moves all values out of place except for those we want left alone - namely positions 3-6 where they will remain untouched due to their position within the original list instead of being moved.

By deriving simple steps for insertion sort, we can achieve this.

- Step 1 − If it is the first element, it is already sorted. You will receive a 1;
- Step 2 − Next, pick an element
- Step 3 − The sub-lists should all be compared together
- Step 4 − A sub-list will be sorted if it contains more elements than the value to be sorted
- Step 5 − Value to insert
- Step 6 − Continue until all the items are sorted

We need above all to know about changes; no one wants or needs to be reminded 16 hours a day that his shoes are on.

…