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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/Applications/anaconda3/envs/conda-pipenv/bin/python"
}
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.7"
77 changes: 77 additions & 0 deletions src/bigo/cs27_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# search

def linear_search(l, value):

for i in range(len(l)):
if i == value:
return True

return False

def binary_search(l, value):
if len(l) <= 1:
pass

# define first and last indices
first = 0
last = len(l) - 1

# variable to store if found
found = False

# when the first item of the list is not the last item
# and found is not True
while first <= last and not found:
print(1)
middle = ( first + last ) // 2

if value == l[middle]:
found = True

else:
if value < l[middle]:
last = middle - 1
else:
first = middle + 1

return found


# insertion sort

def insertion_sort(l):
# separate first element, think of it as sorted


# for all other indices, starting at 1
for i in range(1, len(l)):

# put current number in a temp var
temp = l[i]

# look left, until we find position
j = i
while j > 0 and temp < l[j-1]:
l[j] = l[j-1]
j -= 1

# as we look left, shift items right

# when left is smaller than temp, or we're at zero, put at this spot
l[j] = temp

return l

l = [3,4,6,1,2,9,4,6,7,0,5]
l2 = sorted(l)
print(l)
value = 4
print('linear')
print(linear_search(l2, value))
print('binary')
print(binary_search(l2, value))
print('insertion sort')
print(f'list: {l}')
print(insertion_sort(l))


Binary file modified src/iterative_sorting/__pycache__/iterative_sorting.cpython-37.pyc
Binary file not shown.
54 changes: 43 additions & 11 deletions src/iterative_sorting/iterative_sorting.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,62 @@
# TO-DO: Complete the selection_sort() function below
def selection_sort( arr ):

def selection_sort(l):

# loop through n-1 elements
for i in range(0, len(arr) - 1):
cur_index = i
smallest_index = cur_index
for i in range(0, len(l) - 1):
j = i

# TO-DO: find next smallest element
# (hint, can do in 3 loc)

lowest_num = l[j]
lowest_index = j

for j in range(i, len(l)):
if l[j] < lowest_num:
lowest_num = l[j]
lowest_index = j

# swap the lowest with the current position
swap_num = l[i]
l[i] = lowest_num
l[lowest_index] = swap_num

# TO-DO: swap
return l


# TO-DO: implement the Bubble Sort function below
def bubble_sort(l):
swap_num = 1
while swap_num > 0:

# reset swap num
swap_num = 0

return arr
for i in range(len(l)-1):

# find smaller neighbors
if l[i] > l[i+1]:

# TO-DO: implement the Bubble Sort function below
def bubble_sort( arr ):
# swap
smaller_num = l[i+1]
l[i+1] = l[i]
l[i] = smaller_num

return arr
# update count
swap_num +=1


return l


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

return arr
return arr


l = [3,4,6,1,2,9,4,6,7,0,5]
print('selection_sort')
print(selection_sort(l))
print('bubble_sort')
print(bubble_sort(l))