From 5377d01be070aa15b0ff6c86ecd27a15c5f51fce Mon Sep 17 00:00:00 2001 From: Ali Satwat Khan Date: Sun, 12 Jul 2026 17:09:26 +0500 Subject: [PATCH 1/3] docs: expand bubble sort docstrings with algorithm explanation Add a concise description of how bubble sort works (repeated adjacent comparisons/swaps until a pass makes no swaps) and note time/space complexity for both the iterative and recursive implementations. No behavior changes; all existing doctests pass. --- sorts/bubble_sort.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index 4d658a4a12e4..c66d5d59dd93 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -2,7 +2,18 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]: - """Pure implementation of bubble sort algorithm in Python + """Pure implementation of the bubble sort algorithm in Python (iterative). + + Bubble sort works by repeatedly stepping through the collection, + comparing each pair of adjacent elements and swapping them if they + are in the wrong order. This process repeats, with each full pass + "bubbling" the next-largest unsorted element into its correct + position at the end of the collection, until a full pass completes + with no swaps, at which point the collection is sorted. + + Time complexity: O(n) best case (already sorted, thanks to the + early-exit optimization), O(n^2) average and worst case. + Space complexity: O(1) auxiliary (sorts in place). :param collection: some mutable ordered collection with heterogeneous comparable items inside @@ -61,7 +72,19 @@ 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. + """Pure implementation of the bubble sort algorithm in Python (recursive). + + Functionally identical to the iterative version: each call makes a + single pass through the collection, comparing adjacent elements and + swapping any pair that is out of order. If any swap occurred during + the pass, the function calls itself again on the (partially sorted) + collection; once a pass completes with no swaps, the collection is + sorted and the recursion stops. + + Time complexity: O(n) best case (already sorted), O(n^2) average and + worst case. + Space complexity: O(1) auxiliary for the sort itself (sorts in place), + though the recursion adds O(n) call-stack frames in the worst case. :param collection: mutable ordered sequence of elements :return: the same list in ascending order From fd67085109ad40c375fb7bcb523efcf8e9e12678 Mon Sep 17 00:00:00 2001 From: Ali Satwat Khan Date: Fri, 31 Jul 2026 04:10:03 +0500 Subject: [PATCH 2/3] Fix Ruff 0.16 lint failures --- data_structures/binary_tree/inorder_tree_traversal_2022.py | 2 +- machine_learning/sequential_minimum_optimization.py | 2 +- web_programming/download_images_from_google_query.py | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/data_structures/binary_tree/inorder_tree_traversal_2022.py b/data_structures/binary_tree/inorder_tree_traversal_2022.py index 1357527d2953..a4846a5c29a5 100644 --- a/data_structures/binary_tree/inorder_tree_traversal_2022.py +++ b/data_structures/binary_tree/inorder_tree_traversal_2022.py @@ -43,7 +43,7 @@ def insert(node: BinaryTreeNode | None, new_value: int) -> BinaryTreeNode | None return node -def inorder(node: None | BinaryTreeNode) -> list[int]: # if node is None,return +def inorder(node: BinaryTreeNode | None) -> list[int]: # if node is None,return """ >>> inorder(make_tree()) [6, 10, 14, 15, 20, 25, 60] diff --git a/machine_learning/sequential_minimum_optimization.py b/machine_learning/sequential_minimum_optimization.py index 625fc28fe60c..e96f06d6f080 100644 --- a/machine_learning/sequential_minimum_optimization.py +++ b/machine_learning/sequential_minimum_optimization.py @@ -451,7 +451,7 @@ def test_cancer_data(): print("Hello!\nStart test SVM using the SMO algorithm!") # 0: download dataset and load into pandas' dataframe if not os.path.exists(r"cancer_data.csv"): - request = urllib.request.Request( # noqa: S310 + request = urllib.request.Request( CANCER_DATASET_URL, headers={"User-Agent": "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"}, ) diff --git a/web_programming/download_images_from_google_query.py b/web_programming/download_images_from_google_query.py index 659cf6a398a3..940cc3a5f024 100644 --- a/web_programming/download_images_from_google_query.py +++ b/web_programming/download_images_from_google_query.py @@ -88,8 +88,11 @@ def download_images_from_google_query(query: str = "dhaka", max_images: int = 5) opener.addheaders = [ ( "User-Agent", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" - " (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19582", + ( + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" + " (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36" + " Edge/18.19582" + ), ) ] urllib.request.install_opener(opener) From 001ad600e43601a24ab9620bf1c352723a63a797 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 30 Jul 2026 20:27:34 -0400 Subject: [PATCH 3/3] S310 --- machine_learning/sequential_minimum_optimization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/machine_learning/sequential_minimum_optimization.py b/machine_learning/sequential_minimum_optimization.py index e96f06d6f080..625fc28fe60c 100644 --- a/machine_learning/sequential_minimum_optimization.py +++ b/machine_learning/sequential_minimum_optimization.py @@ -451,7 +451,7 @@ def test_cancer_data(): print("Hello!\nStart test SVM using the SMO algorithm!") # 0: download dataset and load into pandas' dataframe if not os.path.exists(r"cancer_data.csv"): - request = urllib.request.Request( + request = urllib.request.Request( # noqa: S310 CANCER_DATASET_URL, headers={"User-Agent": "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)"}, )