-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Leaves - Mariya #39
base: master
Are you sure you want to change the base?
Leaves - Mariya #39
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so you're missing some of the methods. The ones you have are working although you have some issues with time/space complexity. We'll go over things in class today. Let me know if you have questions.
@@ -3,47 +3,62 @@ | |||
# Time complexity: ? | |||
# Space complexity: ? | |||
def factorial(n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Missing Time/space complexity.
return s | ||
end | ||
a = s[0] | ||
b = s.slice(1, s.length - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s.slice creates a new array and copies all the individual elements over and so is O(n) by itself.
end | ||
|
||
# Time complexity: ? | ||
# Space complexity: ? | ||
def reverse(s) | ||
raise NotImplementedError, "Method not implemented" | ||
def reverse(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This works, but because you create a new array with each recursive call this is O(n2) for both time/space complexity.
end | ||
a = s[0] | ||
b = s.slice(1, s.length - 1) | ||
return reverse(b) + a | ||
end | ||
|
||
# Time complexity: ? | ||
# Space complexity: ? | ||
def reverse_inplace(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok this this is missing
end | ||
|
||
# Time complexity: ? | ||
# Space complexity: ? | ||
def reverse_inplace(s) | ||
raise NotImplementedError, "Method not implemented" | ||
raise NotImplementedError, "Method not implemented" | ||
end | ||
|
||
# Time complexity: ? | ||
# Space complexity: ? | ||
def bunny(n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
No description provided.