diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index 4d658a4a12e4..8e9da320a338 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -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] @@ -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]