Implementation reference:
def bubble_sort(nums):
swapping = True
end = len(nums)
while swapping:
swapping = False
for i in range(1, end):
if nums[i - 1] > nums[i]:
temp = nums[i - 1]
nums[i - 1] = nums[i]
nums[i] = temp
swapping = True
end -= 1
return nums
Sometimes it's useful to know how the algorithm will perform based on what the input data is instead of just how much data there is. In the case of bubble sort (and many other algorithms), the best and worst case scenarios can actually change the time complexity.