Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

docs: add time and space complexity to selection_sort docstring #13972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kl2400033266 wants to merge 1 commit into TheAlgorithms:master
base: master
Choose a base branch
Loading
from kl2400033266:docs/add-complexity-selection-sort
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
View file Open in desktop
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

AltStyle によって変換されたページ (->オリジナル) /