sort

properties

benefits

  • good for nearly sorted lists
  • good for small sizes
  • often used as the recursive base case (when the problem size is small) for divide-and-conquer sort algorithms that have higher overhead like quick sort or merge sort.

implementation

def bubble_sort(low, high):
	for end in range(high, low, -1):
		swap = False
		for i in range(low, end - 1):
			if nums[i] > nums[i + 1]:
				swap = True
				nums[i], nums[i + 1] = nums[i + 1], nums[i]
		if not swap:
			return