From 9cdac158746b050d8409731be6a1268d4c01666e Mon Sep 17 00:00:00 2001 From: sharanabasava-05 Date: Wed, 20 May 2026 19:29:13 +0530 Subject: [PATCH 1/2] added complexity analysis to bubble sort docstring --- sorts/bubble_sort.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index 4d658a4a12e4..dfb0fa7a9e4e 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -47,6 +47,24 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]: >>> collection_arg = random.choices(string.ascii_letters + string.digits, k=100) >>> bubble_sort_iterative(collection_arg) == sorted(collection_arg) True + + Pure implementation of bubble sort algorithm in Python + :param collection:.... + :return:... + + Time Complexity: + Best Case: O(n) + Occurs when the list is already sorted. + The algorithm stops early because no swaps occur. + + Average Case: O(n²) + Happens for randomly ordered elements. + + Worst Case: O(n²) + Occurs when the list is sorted in reverse order. + + Space Complexity:O(1) + Sorting is done in-place using constant extra memory. """ length = len(collection) for i in reversed(range(length)): From 9d42a8c9ac042220a98d982bfd18f13be064b1fc Mon Sep 17 00:00:00 2001 From: sharanabasava-05 Date: Wed, 20 May 2026 21:26:52 +0530 Subject: [PATCH 2/2] fix PR checklist formatting --- sorts/bubble_sort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index dfb0fa7a9e4e..7d342b5d1e34 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -50,7 +50,7 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]: Pure implementation of bubble sort algorithm in Python :param collection:.... - :return:... + :return:.... Time Complexity: Best Case: O(n)