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]