From dd66eabfedfb9955d7c6a759cd184ad09be7e54a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 28 Jun 2026 01:58:03 +0530 Subject: [PATCH 1/2] improve docstrings in insertion_sort.py to include complexity analysis --- sorts/insertion_sort.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sorts/insertion_sort.py b/sorts/insertion_sort.py index 2e39be255df7..0df5dc7c58a6 100644 --- a/sorts/insertion_sort.py +++ b/sorts/insertion_sort.py @@ -30,6 +30,10 @@ 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: O(n^2) - worst and average case + Time Complexity: O(n) - best case (already sorted, inner while never runs) + Space Complexity: O(1) - sorts in place, no extra memory used Examples: >>> insertion_sort([0, 5, 3, 2, 2]) From 768f509c113c3215f3a469ed4fd672d5cf963842 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 27 Jun 2026 20:39:20 +0000 Subject: [PATCH 2/2] [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 0df5dc7c58a6..d295f0256549 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: O(n^2) - worst and average case Time Complexity: O(n) - best case (already sorted, inner while never runs) Space Complexity: O(1) - sorts in place, no extra memory used