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
15 changes: 12 additions & 3 deletions Short-Answer/Algorithms_Answers.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
## Exercise I

a)

Single while statements causes O(n)

b)

Nested loops create (O(n^2))

c)

Single if statements that will eventually lead to 0 creates O(n)
## Exercise II

i = 0
while f == i:
if egg= unbroken:
i ++

else:
return i
this should be O(log n)


10 changes: 7 additions & 3 deletions recursive_count_th/count_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
Your function must utilize recursion. It cannot contain any loops.
'''
def count_th(word):
if len(word) == 0:
return 0

# TBC

pass
elif word[0:2] == "th":
return count_th(word[1:]) + 1
else:
return count_th(word[1:])

30 changes: 28 additions & 2 deletions robot_sort/robot_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,34 @@ def sort(self):
"""
Sort the robot's list.
"""
# Fill this out
pass
while not self.light_is_on():
self.set_light_on()

while self.can_move_right():
self.swap_item()
self.move_right()

if self.compare_item() == 1:
self.swap_item()
self.set_light_off()

self.move_left()
self.swap_item()
self.move_right()



while self.can_move_left():
self.swap_item()
self.move_left()

if self.compare_item() == -1:
self.swap_item()
self.set_light_off()

self.move_right()
self.swap_item()
self.move_left()


if __name__ == "__main__":
Expand Down