From 7513a1b74919e281221c5f0c9f88ed6795e7313f Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 29 Jun 2026 19:52:16 +0530 Subject: [PATCH 1/4] Improve insertion_sort docstring with complexity analysis --- sorts/insertion_sort.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sorts/insertion_sort.py b/sorts/insertion_sort.py index 2e39be255df7..7468dd3de2fd 100644 --- a/sorts/insertion_sort.py +++ b/sorts/insertion_sort.py @@ -30,6 +30,14 @@ def insertion_sort[T: Comparable](collection: MutableSequence[T]) -> MutableSequ :param collection: some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending + + Time Complexity: + Best Case: O(n) + Average Case: O(n²) + Worst Case: O(n²) + + Space Complexity: + O(1) - sorts in place Examples: >>> insertion_sort([0, 5, 3, 2, 2]) From 9e3cd718ebea463d7310b5e8cac4a8526a82c04d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Jun 2026 15:06:57 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/insertion_sort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorts/insertion_sort.py b/sorts/insertion_sort.py index 7468dd3de2fd..22767aaf2525 100644 --- a/sorts/insertion_sort.py +++ b/sorts/insertion_sort.py @@ -30,7 +30,7 @@ def insertion_sort[T: Comparable](collection: MutableSequence[T]) -> MutableSequ :param collection: some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending - + Time Complexity: Best Case: O(n) Average Case: O(n²) From 48624281f50027289ec97146c9bd71bca31139c6 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 30 Jun 2026 22:50:00 +0530 Subject: [PATCH 3/4] Fix doctest formatting --- sorts/pancake_sort.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sorts/pancake_sort.py b/sorts/pancake_sort.py index e5d600738435..0502f8ccf66c 100644 --- a/sorts/pancake_sort.py +++ b/sorts/pancake_sort.py @@ -8,7 +8,7 @@ python pancake_sort.py """ - +from __future__ import annotations def pancake_sort(arr): """Sort Array with Pancake Sort. :param arr: Collection containing comparable items @@ -20,6 +20,9 @@ def pancake_sort(arr): [] >>> pancake_sort([-2, -5, -45]) [-45, -5, -2] + + Time Complexity: (O(n^2)) + Space Complexity: (O(n)) """ cur = len(arr) while cur > 1: @@ -32,8 +35,6 @@ def pancake_sort(arr): cur -= 1 return arr - if __name__ == "__main__": - user_input = input("Enter numbers separated by a comma:\n").strip() - unsorted = [int(item) for item in user_input.split(",")] - print(pancake_sort(unsorted)) + import doctest + doctest.testmod() From bd0151769cc854de7c6fb4869a71b61e6a425f3e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 17:20:16 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/pancake_sort.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sorts/pancake_sort.py b/sorts/pancake_sort.py index 0502f8ccf66c..c8ab9740972c 100644 --- a/sorts/pancake_sort.py +++ b/sorts/pancake_sort.py @@ -9,6 +9,8 @@ """ from __future__ import annotations + + def pancake_sort(arr): """Sort Array with Pancake Sort. :param arr: Collection containing comparable items @@ -20,8 +22,8 @@ def pancake_sort(arr): [] >>> pancake_sort([-2, -5, -45]) [-45, -5, -2] - - Time Complexity: (O(n^2)) + + Time Complexity: (O(n^2)) Space Complexity: (O(n)) """ cur = len(arr) @@ -35,6 +37,8 @@ def pancake_sort(arr): cur -= 1 return arr + if __name__ == "__main__": import doctest + doctest.testmod()