From 33488dba8c52d2ca0f02bfd0033b9fda19ffa2b9 Mon Sep 17 00:00:00 2001 From: Ashish Date: Fri, 1 May 2026 10:31:10 +0530 Subject: [PATCH 1/4] Improved bubble_sort docstrings by adding time and space complexity --- sorts/bubble_sort.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index 4d658a4a12e4..2ed3ffba7be2 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -2,7 +2,17 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]: - """Pure implementation of bubble sort algorithm in Python + """Pure implementation of bubble sort algorithm in Python. + Bubble sort repeatedly steps through the list, compares adjacent elements, and swaps them + if they are in the wrong order. This process is repeated until the list is sorted. + + Time COmplexity: + Worst Case: O(n^2) + Average Case: O(n^2) + Best Case: O(n) (When the list is already sorted and optimized with early stopping) + + Space Complexity: + O(1) (in-place sorting) :param collection: some mutable ordered collection with heterogeneous comparable items inside @@ -62,6 +72,13 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]: def bubble_sort_recursive(collection: list[Any]) -> list[Any]: """It is similar iterative bubble sort but recursive. + Time Complexity: + Worst Case: O(n^2) + Average Case: O(n^2) + Best Case: O(n^2) (no early stopping optimization like iterative version) + + Space Complexity: + O(n) due to recursion stac :param collection: mutable ordered sequence of elements :return: the same list in ascending order From d00a6c18be1cc18d903b8c034cab551f12676676 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 May 2026 05:07:55 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/bubble_sort.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index 2ed3ffba7be2..cc347f26eafa 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -3,9 +3,9 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]: """Pure implementation of bubble sort algorithm in Python. - Bubble sort repeatedly steps through the list, compares adjacent elements, and swaps them - if they are in the wrong order. This process is repeated until the list is sorted. - + Bubble sort repeatedly steps through the list, compares adjacent elements, and swaps them + if they are in the wrong order. This process is repeated until the list is sorted. + Time COmplexity: Worst Case: O(n^2) Average Case: O(n^2) From 152ea4b6ff58b5e7f886526fa372c91123f50bb4 Mon Sep 17 00:00:00 2001 From: Ashish Date: Fri, 1 May 2026 10:48:05 +0530 Subject: [PATCH 3/4] Fix line length issues in docstrings --- sorts/bubble_sort.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index cc347f26eafa..dfb0f8f10769 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -3,13 +3,15 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]: """Pure implementation of bubble sort algorithm in Python. - Bubble sort repeatedly steps through the list, compares adjacent elements, and swaps them - if they are in the wrong order. This process is repeated until the list is sorted. - - Time COmplexity: + Bubble sort repeatedly steps through the list, compares adjacent + elements, and swaps them if they are in the wrong order. + This process is repeated until the list is sorted. + + Time Complexity: Worst Case: O(n^2) Average Case: O(n^2) - Best Case: O(n) (When the list is already sorted and optimized with early stopping) + Best Case: O(n) (When the list is already sorted and + optimized with early stopping) Space Complexity: O(1) (in-place sorting) @@ -75,7 +77,8 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]: Time Complexity: Worst Case: O(n^2) Average Case: O(n^2) - Best Case: O(n^2) (no early stopping optimization like iterative version) + Best Case: O(n^2) (no early stopping + optimization like iterative version) Space Complexity: O(n) due to recursion stac From 8bfad979a8b2752f5ed0b182eb0d6b2774c6ea22 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 May 2026 05:18:35 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/bubble_sort.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index dfb0f8f10769..63bc67645f93 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -3,14 +3,14 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]: """Pure implementation of bubble sort algorithm in Python. - Bubble sort repeatedly steps through the list, compares adjacent - elements, and swaps them if they are in the wrong order. - This process is repeated until the list is sorted. - + Bubble sort repeatedly steps through the list, compares adjacent + elements, and swaps them if they are in the wrong order. + This process is repeated until the list is sorted. + Time Complexity: Worst Case: O(n^2) Average Case: O(n^2) - Best Case: O(n) (When the list is already sorted and + Best Case: O(n) (When the list is already sorted and optimized with early stopping) Space Complexity: @@ -77,7 +77,7 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]: Time Complexity: Worst Case: O(n^2) Average Case: O(n^2) - Best Case: O(n^2) (no early stopping + Best Case: O(n^2) (no early stopping optimization like iterative version) Space Complexity: