Edit page

Insertion Sort

Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. (Source: Wikipedia)

It iterates the input elements by growing the sorted array at each iteration. It compares the current element with the largest value in the sorted array. If the current element is greater, then it leaves the element in its place and moves on to the next element else it finds its correct position in the sorted array and moves it to that position. This is done by shifting all the elements, which are larger than the current element, in the sorted array to one position ahead. (Source: hackerearth)

Algorithm Visualization Algorithm Visualization

Complexity

NameBestAverageWorstMemoryStableComments
Insertion sortnn2n21Yes

References

  • Geeksforgeeks
  • Wikipedia
  • YouTube
  • Programiz
  • Algomation
  • Hackerearth
  • Tutorialspoint