From 97a4f5c5cfc1d236e5216c1fbd8f5464c59021a0 Mon Sep 17 00:00:00 2001 From: SHAIK AYESHA <2400032689@kluniversity.in> Date: Mon, 24 Nov 2025 19:10:49 +0530 Subject: [PATCH] Add time and space complexity to bubble_sort docstrings Enhanced documentation for bubble_sort_iterative and bubble_sort_recursive functions by adding: - Time Complexity: O(n^2) for both implementations - Space Complexity: O(1) for iterative, O(n) for recursive due to call stack This improves code readability and helps developers understand algorithm performance characteristics. Addresses issue #13948 about documentation inconsistencies. --- sorts/bubble_sort.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index 9ec3d5384f38..9db22d30163f 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -7,6 +7,9 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]: :param collection: some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending + + Time Complexity: O(n^2) - where n is the number of elements + Space Complexity: O(1) - only uses a constant amount of extra space Examples: >>> bubble_sort_iterative([0, 5, 2, 3, 2]) @@ -59,6 +62,9 @@ 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: O(n^2) - where n is the number of elements + Space Complexity: O(n) - due to recursive call stack Examples: >>> bubble_sort_recursive([0, 5, 2, 3, 2])