Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion sorts/bubble_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]:
"""Pure implementation of bubble sort algorithm in Python

:param collection: some mutable ordered collection with heterogeneous
comparable items inside
comparable items inside
:return: the same collection ordered in ascending order

Time Complexity:
- Worst Case: O(n^2)
- Average Case: O(n^2)
- Best Case: O(n)

Space Complexity: O(1) auxiliary space

Examples:
>>> bubble_sort_iterative([0, 5, 2, 3, 2])
[0, 2, 2, 3, 5]
Expand Down Expand Up @@ -66,6 +73,13 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]:
:param collection: mutable ordered sequence of elements
:return: the same list in ascending order

Time Complexity:
- Worst Case: O(n^2)
- Average Case: O(n^2)
- Best Case: O(n)

Space Complexity: O(n) auxiliary stack space due to recursion

Examples:
>>> bubble_sort_recursive([0, 5, 2, 3, 2])
[0, 2, 2, 3, 5]
Expand Down