Skip to content
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
jithinraj
/
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
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
pygorithm
/
pygorithm
/
sorting
/
insertion_sort.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
25 lines (21 loc) · 697 Bytes
master
Breadcrumbs
pygorithm
/
pygorithm
/
sorting
/
insertion_sort.py
Copy path
Top
File metadata and controls
Code
Blame
25 lines (21 loc) · 697 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
# Author: OMKAR PATHAK
# Created On: 31st July 2017
# Best O(n); Average O(n^2); Worst O(n^2)
# insertion sort algorithm
def sort(List):
for i in range(1, len(List)):
currentNumber = List[i]
for j in range(i - 1, -1, -1):
if List[j] > currentNumber :
List[j], List[j + 1] = List[j + 1], List[j]
else:
List[j + 1] = currentNumber
break
return List
# time complexities
def time_complexities():
return '''Best Case: O(n), Average Case: O(n ^ 2), Worst Case: O(n ^ 2)'''
# easily retrieve the source code of the sort function
def get_code():
import inspect
return inspect.getsource(sort)
You can’t perform that action at this time.