-
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
Yasmin- Leaves #34
base: master
Are you sure you want to change the base?
Yasmin- Leaves #34
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.
As you pointed out you didn't get them all done, but most of what you have is pretty good. We'll go over the solutions in class. Let me know what questions you have.
# Time complexity: ? | ||
# Space complexity: ? | ||
# Time complexity: o(n) | ||
# Space complexity: o(n) | ||
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.
👍
if s.length <= 1 | ||
return s | ||
else | ||
return s[-1] + reverse(s[0..-2]) |
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[1..-1]
creates a new array and copies all the individual elements over and so is O(n) by itself.
# Time complexity: o(n^2) | ||
# Space complexity: o(n^2) | ||
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.
Correct on the time/space complexities. Can you think of a way to do better?
# Time complexity: ? | ||
# Space complexity: ? | ||
# 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.
We'll go over this in class.
# Space complexity: ? | ||
|
||
# Time complexity: o(n) | ||
# Space complexity: o(n) | ||
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.
👍
# Space complexity: ? | ||
|
||
# Time complexity: o(n) | ||
# Space complexity: o(n^2) | ||
def nested(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.
👍 Time complexity is also O(n^2) because of s[1...-1]
# Time complexity: ? | ||
# Space complexity: ? | ||
def search(array, value) |
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.
👍 Big-O is O(n^2) due to the repeated creation of new arrays.
No description provided.