Well-known computer science algorithms published for practice and educational purposes.
Bubble, selection and insertion sort algorithms were implemented to retrieve all iterations of their respective processes, instead of the sorted items.
>>> bubble_sort([3, 2, 1])
[[3, 2, 1], [2, 3, 1], [2, 1, 3], [1, 2, 3]]
>>> bubble_sort([1, 2, 3], ascending=False)
[[1, 2, 3], [2, 1, 3], [2, 3, 1], [3, 2, 1]]>>> selection_sort([3, 1, 2])
[[3, 1, 2], [1, 3, 2], [1, 2, 3]]
>>> selection_sort([2, 1, 3], ascending=False)
[[2, 1, 3], [3, 1, 2], [3, 2, 1]]>>> insertion_sort([3, 1, 2])
[[3, 1, 2], [1, 3, 2], [1, 2, 3]]
>>> insertion_sort([2, 1, 3], ascending=False)
[[2, 1, 3], [2, 3, 1], [3, 2, 1]]Returns a list of tuples containing all merges performed.
>>> merge_sort([2, 3, 1])
[([3, 1], [1, 3]), ([2, 3, 1], [1, 2, 3])]
>>> merge_sort([2, 1, 3], ascending=False)
[([1, 3], [3, 1]), ([2, 1, 3], [3, 2, 1])]