Insertion sort python algorithm: Why do we subtract 1 from i?
Insertion sort python algorithm: Why do we subtract 1 from i? Question: Here is the code: list_a = [3,2,5,7,4,1] def insertion_sort(list_a): indexing_length = range(1,len(list_a)) for i in indexing_length: value_to_sort = list_a[i] while list_a[i-1] > value_to_sort and i>0: list_a[i], list_a[i-1] = list_a[i-1], list_a[i] i = i – 1 return list_a I understand the logic to the …