From bdea44d363923c8fd89dd6bbde113e2784b9394b Mon Sep 17 00:00:00 2001 From: Abhijit Singh Date: Sun, 21 Jun 2026 21:22:43 +0530 Subject: [PATCH] docs: add bubble sort complexity notes --- sorts/bubble_sort.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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]