Skip to content
Open
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
86 changes: 86 additions & 0 deletions Homework1sub/algs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ def pointless_sort(x):
This function always returns the same values to show how testing
works, check out the `test/test_alg.py` file to see.
"""
assert 2 == 2
return x

def insertionsort(x):
"""
def insertionsort(somelist):
count = 0
assign = 0

assign +=1
for i in range(1,len(somelist)):
count += 2
while i > 0 and somelist[i] < somelist[i-1]:
somelist[i], somelist[i-1] = somelist[i-1], somelist[i]
assign += 2
i -= 1 #subtract 1 from the i and make the new i equal to i-1
assign += 1

print("number of conditionals:", count)
print("number of assignments:", assign)
return somelist
"""
return np.array([1,2,3])

def bubblesort(x):
Expand Down Expand Up @@ -65,8 +87,72 @@ def quicksort(x):
return quicksort(elements_not_greater_than_pivot) + [pivot] + quicksort(elements_greater_than_pivot)


"""

assert 2 == 2
return
def quicksort_assign(x):
"""
count = 0
assign = 0
setpivot = len(somelist2)

count += 1
if setpivot <= 1: #is sequence length 1 or less?
return assign
else:
pivot = somelist2.pop()

elements_greater_than_pivot = []
elements_not_greater_than_pivot = []

assign += 1
count += 1
for i in somelist2:
if i > pivot:
elements_greater_than_pivot.append(i)

else:
elements_not_greater_than_pivot.append(i)

#the .appends are not assignments because there are no variable changes
return quicksort_assign(elements_not_greater_than_pivot) + assign + quicksort_assign(elements_greater_than_pivot)


"""

assert 2 == 2
return

def quicksort_conditional(x):
"""
count = 0
assign = 0
setpivot = len(somelist2)

count += 1
if setpivot <= 1: #is sequence length 1 or less?
return count
else:
pivot = somelist2.pop()

elements_greater_than_pivot = []
elements_not_greater_than_pivot = []

assign += 1
count += 1
for i in somelist2:
if i > pivot:
elements_greater_than_pivot.append(i)

else:
elements_not_greater_than_pivot.append(i)


return quicksort_conditional(elements_not_greater_than_pivot) + count + quicksort_conditional(elements_greater_than_pivot)


"""

assert 2 == 2
return