FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pygorithm/pygorithm/sorting/selection_sort.py at master · lambdafunc/pygorithm · GitHub
lambdafunc
/
pygorithm
Public
forked from
OmkarPathak/pygorithm
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pygorithm
/
pygorithm
/
sorting
/
selection_sort.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (39 loc) · 989 Bytes
Breadcrumbs
pygorithm
/
pygorithm
/
sorting
/
selection_sort.py
Copy path
File metadata and controls
50 lines (39 loc) · 989 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Author: OMKAR PATHAK
Created On: 31st July 2017
- Best O(n^2)
- Average O(n^2)
- Worst O(n^2)
"""
import
inspect
def
sort
(
_list
):
"""
selection sort algorithm
:param _list: list of integers to sort
:return: sorted list
"""
# For iterating n - 1 times
for
i
in
range
(
len
(
_list
)
-
1
):
minimum
=
i
# Compare i and i + 1 element
for
j
in
range
(
i
+
1
,
len
(
_list
)):
if
_list
[
j
]
<
_list
[
minimum
]:
minimum
=
j
if
minimum
!=
i
:
_list
[
i
],
_list
[
minimum
]
=
_list
[
minimum
],
_list
[
i
]
return
_list
# TODO: Are these necessary?
def
time_complexities
():
"""
Return information on functions
time complexity
:return: string
"""
return
"Best Case: O(n ^ 2), Average Case: O(n ^ 2), Worst Case: O(n ^ 2)"
def
get_code
():
"""
easily retrieve the source code
of the sort function
:return: source code
"""
return
inspect
.
getsource
(
sort
)
Back
|
FazBrowse Home
|
New Git URL