From 2dfa10d6af6572fed890fbcc98140ad267b08d28 Mon Sep 17 00:00:00 2001 From: kumarsatyam9378-art Date: Tue, 18 Aug 2026 18:24:20 +0530 Subject: [PATCH] Add time and space complexity analysis to insertion_sort docstring Document the performance characteristics of insertion sort in the function docstring: - Time Complexity: O(n^2) worst/average case, O(n) best case (already sorted input) - Space Complexity: O(1), sorts in place Fixes #14866 --- sorts/insertion_sort.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sorts/insertion_sort.py b/sorts/insertion_sort.py index 2e39be255df7..ab43dae3884b 100644 --- a/sorts/insertion_sort.py +++ b/sorts/insertion_sort.py @@ -31,6 +31,12 @@ def insertion_sort[T: Comparable](collection: MutableSequence[T]) -> MutableSequ comparable items inside :return: the same collection ordered by ascending + Time Complexity: + - O(n^2) in the worst and average cases + - O(n) in the best case, when the collection is already sorted + Space Complexity: + - O(1), since the collection is sorted in place + Examples: >>> insertion_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5]