Skip to content
Open
Show file tree
Hide file tree
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
Binary file modified src/iterative_sorting/__pycache__/iterative_sorting.cpython-37.pyc
Binary file not shown.
24 changes: 12 additions & 12 deletions src/iterative_sorting/iterative_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ def selection_sort( arr ):
for i in range(0, len(arr) - 1):
cur_index = i
smallest_index = cur_index
# TO-DO: find next smallest element
# (hint, can do in 3 loc)




# TO-DO: swap




min_val = min(arr[cur_index+1: ])
min_index = arr.index(min_val)
if min_val < arr[cur_index]:
arr[min_index]= arr[cur_index]
arr[cur_index] = min_val
return arr


# TO-DO: implement the Bubble Sort function below
def bubble_sort( arr ):

while arr != sorted(arr):
for i in range(0, len(arr) - 1):
left = arr[i]
right = arr[i+1]
if left > right:
arr[i], arr[i+1] = right, left
return arr



# STRETCH: implement the Count Sort function below
def count_sort( arr, maximum=-1 ):

Expand Down
29 changes: 24 additions & 5 deletions src/recursive_sorting/recursive_sorting.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
# TO-DO: complete the helpe function below to merge 2 sorted arrays
# TO-DO: complete the helper function below to merge 2 sorted arrays
def merge( arrA, arrB ):
elements = len( arrA ) + len( arrB )
merged_arr = [0] * elements
elem = len( arrA ) + len( arrB )
merged_arr = [0] * elem
# TO-DO

while ((len(arrA) > 0) | (len(arrB) > 0)):
if not arrA:
merged_arr.append(arrB[0])
arrB.pop(0)
elif not arrB:
merged_arr.append(arrA[0])
arrA.pop(0)
elif (arrA[0] < arrB[0]):
merged_arr.append(arrA[0])
arrA.pop(0)
elif (arrB[0] < arrA[0]):
merged_arr.append(arrB[0])
arrB.pop(0)
merged_arr.pop(0)

return merged_arr


# TO-DO: implement the Merge Sort function below USING RECURSION
def merge_sort( arr ):
# TO-DO

if len(arr) > 1:
mid = len(arr) // 2
left = arr[0:mid]
right = arr[mid: ]
arr = merge(merge_sort(left), merge_sort(right))

return arr


Expand Down