Algorithms are set of instructions designed to modify an input to create the desired output.
The Sorting problem is a typical programming task that Data Scientists and other programming disciplines come across. The sorting problem’s main task is to order a sequence of elements in either ascending or descending order.
Insertion Sort is one solution to the sorting problem. It’s easy to describe how the insertion works by thinking about the methods you would use to arrange a deck of cards in ascending order.
On the right side, you have a deck of face-down cards, and on the left side is an initial empty space. The first card will be on the initially empty left-hand space, and then with each card picked from the right-hand pile, you’ll compare with the cards in the left-hand pile to determine if the current card is less than the observed card.
If the card is not less than the card being observed on the left side, it’s left in the current position.
Essentially, the left deck in this example is always sorted.
The next section introduces the algorithm of Insertion sort properly. Once you build an intuition of how the algorithm works, a later section will show how the insertion sort algorithm is implemented in Python.