Leaves - Alice#20
Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Overall nice work, you hit the learning goals here. Well done. Check my comments below especially with regard to time/space complexity. Let me know if you have questions.
| # Space complexity: ? | ||
| # Time complexity: O(n), the amount of recursive calls depends on the size of n. | ||
| # Space complexity: O(n), each recursive call is added to the stack. | ||
| def factorial(n) |
| raise NotImplementedError, "Method not implemented" | ||
| return s if s.length <= 1 | ||
|
|
||
| reversed_s = reverse(s[1..-1]) |
There was a problem hiding this comment.
s[1..-1] creates a new array and copies all the individual elements over and so is O(n) by itself.
| # Time complexity: O(n), the amount of recursive calls depends on the size of the string. | ||
| # Space complexity: O(n), each recursive call is added to the stack. | ||
| def reverse(s) |
There was a problem hiding this comment.
This works, but because you create a new array with each recursive call this is O(n2) for both time/space complexity.
| raise NotImplementedError, "Method not implemented" | ||
| # Time complexity: O(n), the amount of recursive calls depends on the size of the string. | ||
| # Space complexity: O(n), each recursive call is added to the stack. | ||
| def reverse_inplace(s, low = 0, high = s.length-1) |
| # Space complexity: ? | ||
| # Time complexity: O(n), the amount of recursive calls depends on the size of n. | ||
| # Space complexity: O(n), each recursive call is added to the stack. | ||
| def bunny(n) |
| # Space complexity: ? | ||
| # Time complexity: O(n), the amount of recursive calls depends on the size of the string. | ||
| # Space complexity: O(n), each recursive call is added to the stack. | ||
| def nested(s) |
There was a problem hiding this comment.
👍
This works, but has similar issues with time/space complexity as reverse.
| raise NotImplementedError, "Method not implemented" | ||
| # Time complexity: O(log n), the amount of searches is cut in half with every recursive call. | ||
| # Space complexity: O(n), each recursive call is added to the stack. | ||
| def search(array, value, low = 0, high = array.length-1) |
There was a problem hiding this comment.
👍 The time/space complexity is O(log n) in both.
This also assumes that the array is sorted.
| # Space complexity: ? | ||
| # Time complexity: O(n), the amount of recursive calls depends on the size of the string. | ||
| # Space complexity: O(n), each recursive call is added to the stack. | ||
| def is_palindrome(s) |
There was a problem hiding this comment.
👍
This works, but because you create a new array with each recursive call this is O(n2) for both time/space complexity.
| # Space complexity: ? | ||
| # Time complexity: O(n), the amount of recursive calls depends on the size either of n or m. | ||
| # Space complexity: O(n), each recursive call is added to the stack. | ||
| def digit_match(n, m) |
There was a problem hiding this comment.
👍
This works, but because you create a new array with each recursive call this is O(n2) for both time/space complexity.
No description provided.