diff --git a/Short-Answer/Algorithms_Answers.md b/Short-Answer/Algorithms_Answers.md index b276aca1b..a28fc2a1b 100644 --- a/Short-Answer/Algorithms_Answers.md +++ b/Short-Answer/Algorithms_Answers.md @@ -2,13 +2,13 @@ ## Exercise I -a) +a) O(1) -b) +b) O(n) -c) +c) O(n) ## Exercise II diff --git a/Short-Answer/Algorithms_Questions.md b/Short-Answer/Algorithms_Questions.md index 46f444535..cbb92f9a5 100644 --- a/Short-Answer/Algorithms_Questions.md +++ b/Short-Answer/Algorithms_Questions.md @@ -6,7 +6,7 @@ Give an analysis of the running time of each snippet of pseudocode with respect to the input size n of each of the following: ```python -a) a = 0 +a) a = 0 while (a < n * n * n): a = a + n * n ``` diff --git a/recursive_count_th/count_th.py b/recursive_count_th/count_th.py index 07456a00b..a7922c369 100644 --- a/recursive_count_th/count_th.py +++ b/recursive_count_th/count_th.py @@ -4,7 +4,12 @@ Your function must utilize recursion. It cannot contain any loops. ''' def count_th(word): - - # TBC - - pass + + if word == "": + return 0 + + if word[:2] == "th": + return 1 + count_th(word[1:]) + else: + return 0 + count_th(word[1:]) + diff --git a/robot_sort/robot_sort.py b/robot_sort/robot_sort.py index db6b1985b..197697a51 100644 --- a/robot_sort/robot_sort.py +++ b/robot_sort/robot_sort.py @@ -96,8 +96,22 @@ def sort(self): """ Sort the robot's list. """ - # Fill this out - pass + if self.can_move_right() is False: + return self._list + self.swap_item() + while self.can_move_right(): + self.move_right() + if self.compare_item() == 1: + self.swap_item() + while self.can_move_left(): + self.move_left() + if self.compare_item() == None: + self.swap_item() + break + self.move_right() + self.sort() + + if __name__ == "__main__":