Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sorts/selection_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down