Skip to content
Open

MVP #448

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

## Exercise I

a)
a) linear time O(n)- because the input size will stay at the same rate the whole time. Which indicates linear.


b)
b) Linearithmic time O(n log n) - because the j will continue to grow in the inner loop O(log n) even though the outer loop is linear.


c)
c) linear O(n) - The function is recursive and will call itself 'n' number of times indicating linear. And adding 2 two the recursive call is also linear which is a constant time operation.

## Exercise II

Expand Down
14 changes: 12 additions & 2 deletions recursive_count_th/count_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
Your function should return a count of how many occurences of ***"th"*** occur within `word`. Case matters.
Your function must utilize recursion. It cannot contain any loops.
'''

def count_th(word):

# TBC
print(word[:2])

if len(word) <= 1:
return 0

pass
elif word[0] == "t":
if word[1] == "h":
return 1 + count_th(word[1:])
else:
return count_th(word[1:])
else:
return count_th(word[1:])
17 changes: 16 additions & 1 deletion robot_sort/robot_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,23 @@ def sort(self):
Sort the robot's list.
"""
# Fill this out
pass
if self.can_move_right():
self.swap_item()

while self.can_move_right():
self.move_right()
if self.compare_item() == 1:
self.swap_item()
if not self.can_move_right():
while self.compare_item() != None:
if self.can_move_left():
self.move_left()

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

self.swap_item()

if __name__ == "__main__":
# Test our your implementation from the command line
Expand Down