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.
pip install allalgorithms
from allalgorithms.sorting import insertion_sort
arr = [77, 2, 10, -2, 1, 7]
print(insertion_sort(arr))
# -> [-2, 1, 2, 7, 10, 77]
Returns a sorted array
array
: Unsorted Array