

Suppose, an array is in ascending order, and you want to sort it in descending order. Insertion Sort in Python, Java, and C/C++ Place 4 behind 1 Place 3 behind 1 and the array is sorted

Placed it just behind the element smaller than it. Take the third element and compare it with the elements on the left of it.

The first element in the array is assumed to be sorted.Suppose we need to sort the following array. In the same way, other unsorted cards are taken and put in their right place.Ī similar approach is used by insertion sort. If the unsorted card is greater than the card in hand, it is placed on the right otherwise, to the left. We assume that the first card is already sorted then, we select an unsorted card. Insertion sort works similarly as we sort cards in our hand in a card game. Insertion sort is a sorting algorithm that places an unsorted element at its suitable place in each iteration. Decrease Key and Delete Node Operations on a Fibonacci Heap.
