Skip to content
Closed
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
18 changes: 18 additions & 0 deletions sorts/bubble_sort.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,15 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]:
comparable items inside
:return: the same collection ordered in ascending order

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

Space Complexity: O(1)

Stable: Yes

Examples:
>>> bubble_sort_iterative([0, 5, 2, 3, 2])
[0, 2, 2, 3, 5]
Expand DownExpand Up@@ -66,6 +75,15 @@ 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:
Best Case: O(n)
Average Case: O(n^2)
Worst Case: O(n^2)

Space Complexity: O(n)

Stable: Yes

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