Insertion sort has a Big O of O(n^2), because that is its worst case complexity.
The outer loop of insertion sort always executes n times, while the inner loop depends on the input.
O(n^2) because the inner loop will execute about half of the time.O(n^2) and the inner loop will execute every time.def insertion_sort(nums):
for i in range(len(nums)):
j = i
while j > 0 and nums[j - 1] > nums[j]:
nums[j], nums[j - 1] = nums[j - 1], nums[j]
j -= 1
return nums