Insertion Sort

Insertion Sort builds the final sorted array one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort, but it performs well for small datasets or nearly sorted datasets.

Steps:

  1. Start with the second element
  2. Compare it with the previous elements and insert it in the correct position
  3. Move to the next element and repeat until the array is sorted

Time Complexity

Best: O(n)

Average: O(n²)

Worst: O(n²)

Space Complexity

O(1)

Array length:

7

Speed:

Canvas is not supported in your browser. Please use Edge or Chrome.