From 2c171b09cabb0d274e10583a50995a5410eb4e13 Mon Sep 17 00:00:00 2001 From: RONGALI MOHAN KRISHNA 2400033266 <2400033266@kluniversity.in> Date: Thu, 27 Nov 2025 09:26:28 +0530 Subject: [PATCH] docs: add time and space complexity to selection_sort docstring Added Time Complexity O(n^2) and Space Complexity O(1) documentation to the selection_sort function docstring, improving code documentation for beginners as requested in issue #13948. --- sorts/selection_sort.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sorts/selection_sort.py b/sorts/selection_sort.py index 506836b53e44..c0ca63ce77b7 100644 --- a/sorts/selection_sort.py +++ b/sorts/selection_sort.py @@ -5,6 +5,12 @@ def selection_sort(collection: list[int]) -> list[int]: :param collection: A list of integers to be sorted. :return: The sorted list. + + Time Complexity: O(n^2) - Due to the nested loops, where n is the length + of the collection. The outer loop runs n-1 times, and the inner loop + runs n-i-1 times for each iteration. + Space Complexity: O(1) - Only a constant amount of extra space is used + for variables (length, i, min_index, k). Examples: >>> selection_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5]