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

Commit 6a6195e

Browse files
committed
🚀 Initialized Project: Completed Exercise
0 parents commit 6a6195e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

‎binary_search.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def binary_search(r_list: list, req: int):
2+
lo = 0
3+
hi = len(r_list) - 1
4+
5+
while lo <= hi:
6+
mid = (lo + hi) // 2
7+
print(r_list[lo: hi + 1])
8+
if r_list[mid] == req:
9+
return r_list[mid]
10+
elif r_list[mid] < req:
11+
lo = mid + 1
12+
else:
13+
hi = mid - 1
14+
15+
return None
16+
17+
18+
n_list = [-1, 0, 1, 3, 4, 4, 10]
19+
print(binary_search(n_list, -1))

‎selection_sort.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# The time complexity of this algorithm is O(n2)
2+
def selection_sort(u_list: list):
3+
new_list = []
4+
# this function runs n times taking O(n) time
5+
for k in range(len(u_list)):
6+
# Return the smallest item in the array
7+
# This operation takes O(n) time
8+
i = 0
9+
for j in range(1, len(u_list)):
10+
if u_list[j] < u_list[i]:
11+
i = j
12+
13+
new_list.append(u_list.pop(i))
14+
15+
return new_list
16+
17+
18+
print(f'sorted list: {selection_sort([0, -1, 4, 3, 4, 10, 1])}')

0 commit comments

Comments
(0)

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