Skip to main content

Algorithms (Code)

Sorting

Insertion sort

def insertion_sort(arr):
i = j = 0
for i in range(1, len(arr)):
j = i
while j > 0 and (arr[j] < arr[j-1]):
arr[j], arr[j-1] = arr[j-1], arr[j]
j = j - 1