Skip to content
6 changes: 3 additions & 3 deletions requirements_with_versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ pywifi==1.1.12
patterns==0.3
openai==1.107.1
background==0.2.1
pydantic==2.11.7
pydantic==2.11.9
openpyxl==3.1.2
pytesseract==0.3.13
requests-mock==1.12.1
pyglet==2.1.8
urllib3==2.5.0
thirdai==0.9.33
google-api-python-client==2.181.0
google-api-python-client==2.183.0
sound==0.1.0
xlwt==1.3.0
pygame==2.6.1
speechtotext==0.0.3
wikipedia==1.4.0
tqdm==4.67.1
Menu==3.2.2
yfinance==0.2.65
yfinance==0.2.66
tweepy==4.16.0
tkcalendar==1.6.1
pytube==15.0.0
Expand Down
36 changes: 36 additions & 0 deletions sorting_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,44 @@


def selection_sort(arr: list) -> list:
"""Sorts a list in ascending order using the selection sort algorithm.

Args:
arr: List of comparable elements (e.g., integers, strings).

Returns:
The sorted list (in-place modification).

Examples:
>>> selection_sort([])
[]
>>> selection_sort([1])
[1]
>>> selection_sort([1, 2, 3, 4])
[1, 2, 3, 4]
>>> selection_sort([4, 3, 2, 1])
[1, 2, 3, 4]
>>> selection_sort([3, 1, 3, 2])
[1, 2, 3, 3]
>>> selection_sort([5, 5, 5, 5])
[5, 5, 5, 5]
>>> selection_sort([2, 4, 1, 3])
[1, 2, 3, 4]
>>> selection_sort([-1, -3, 0, 2])
[-3, -1, 0, 2]
>>> selection_sort([0, -5, 3, -2, 1])
[-5, -2, 0, 1, 3]
>>> selection_sort(["banana", "apple", "cherry"])
['apple', 'banana', 'cherry']
>>> selection_sort(["Apple", "banana", "Cherry"])
['Apple', 'Cherry', 'banana']
>>> selection_sort([2147483647, -2147483648, 0])
[-2147483648, 0, 2147483647]
"""

"""TC : O(n^2)
SC : O(1)"""

n = len(arr)
for i in range(n):
for j in range(i + 1, n):
Expand Down
Loading