From e5fcd6bd34ba3adf08c758d0062f9dddb0de69a6 Mon Sep 17 00:00:00 2001 From: Aditya Mitra <216041780+Aditya70-creator@users.noreply.github.com> Date: Fri, 19 Jun 2026 09:17:16 +0530 Subject: [PATCH] docs: add complexity analysis to bubble_sort docstrings Added time and space complexity analysis for both iterative and recursive bubble sort implementations. --- sorts/bubble_sort.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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]