Insertion Sort

Insertion sort is one of the first few algorithms that you would come across when learning about sorting algorithms. It is an easy to understand sorting algorithm that helps to build the foundation of sorting logic. However, it is not as efficient as some of the other algorithms as the worst-case complexity of Insertion Sort is O(n²).

Lets see how this algorithm works:

  1. Given an unsorted array with n elements
    arr = [3, 4, 7, 5, 6, 2, 1]
  2. We skip the first element as it makes no sense to compare it with itself.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Manpreet Singh

Software developer who loves writing about programming, technology, passive income strategies etc.