diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index 4d658a4a12e4..a0a22c245b06 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -8,6 +8,10 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]: comparable items inside :return: the same collection ordered in ascending order + Best case time complexity: O(n) when the collection is already sorted. + Average and worst case time complexity: O(n^2). + Space complexity: O(1). + Examples: >>> bubble_sort_iterative([0, 5, 2, 3, 2]) [0, 2, 2, 3, 5] @@ -66,6 +70,10 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]: :param collection: mutable ordered sequence of elements :return: the same list in ascending order + Best case time complexity: O(n) when the collection is already sorted. + Average and worst case time complexity: O(n^2). + Space complexity: O(n) because recursive calls use the call stack. + Examples: >>> bubble_sort_recursive([0, 5, 2, 3, 2]) [0, 2, 2, 3, 5]