Skip to content

Latest commit

History

History
42 lines (36 loc) 路 1.51 KB

File metadata and controls

42 lines (36 loc) 路 1.51 KB

馃悕 Algorithms

Actions status Code style: black

Well-known computer science algorithms published for practice and educational purposes.

Sorting

Bubble, selection and insertion sort algorithms were implemented to retrieve all iterations of their respective processes, instead of the sorted items.

Bubble

>>> 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

>>> 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

>>> 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]]

Merge

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])]