Skip to content
Open

mvp #433

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

## Exercise I

a)
a) Linear


b)
b) The iteration increase the time


c)
c) no looping since it's only called once

## Exercise II

Expand Down
4 changes: 4 additions & 0 deletions Short-Answer/Algorithms_Questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ a) a = 0
a = a + n * n
```

it's a single while loop so it 0(n)


```
b) sum = 0
Expand All @@ -20,6 +22,7 @@ b) sum = 0
j *= 2
sum += 1
```
This is a nested loop 0(n^2)

```
c) def bunnyEars(bunnies):
Expand All @@ -28,6 +31,7 @@ c) def bunnyEars(bunnies):

return 2 + bunnyEars(bunnies-1)
```
0(n) it's a recursion.

## Exercise II

Expand Down
9 changes: 8 additions & 1 deletion recursive_count_th/count_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
Your function must utilize recursion. It cannot contain any loops.
'''
def count_th(word):
if not word:
return 0
elif word[:2] == 'th':
return 1 + count_th(word[2:])
else:
return count_th(word[1:])


# TBC

pass
# pass
17 changes: 16 additions & 1 deletion robot_sort/robot_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,22 @@ def sort(self):
Sort the robot's list.
"""
# Fill this out
pass
if self.can_move_right() == False:
return

self.swap_item()

while self.can_move_right():
self.move_right()
if self.compare_item() == 1:
self.swap_item()

while self.compare_item() is not None:
self.move_left()

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


if __name__ == "__main__":
Expand Down