Insertion Sort

Insertion Sort #

Insertion sort is one of many sorting algorithms used to sort data in different data structures.

Each sorting algorithm has its own advantages and disadvantages. Insertion sort is no exception. It is a simple algorithm that is easy to implement and understand. However, it is not the most efficient sorting algorithm when it comes to large data sets.

Concept #

img.png

Complexity and Stability #

CaseTime ComplexitySpace ComplexityStable
Best CaseO(n)O(1)Yes
Average CaseO(n^2)O(1)Yes
Worst CaseO(n^2)O(1)Yes
SpaceO(1)O(1)Yes