From dd66eabfedfb9955d7c6a759cd184ad09be7e54a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 28 Jun 2026 01:58:03 +0530 Subject: [PATCH] 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])