-
Notifications
You must be signed in to change notification settings - Fork 53
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
Wrote recursive methods #33
base: master
Are you sure you want to change the base?
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.
Overall well done. Take a look at my comments and let me know what questions you have.
# Time complexity: O(n) - it takes one recursion for every increase in n | ||
# Space complexity: O(n) - because of the system stack | ||
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.
👍
# Time complexity: O(n) - It takes n recursions for each character | ||
# Space complexity: O(n^2) - n is number of characters | ||
# String objects with length n * (n-1) * (n-2) ... are made | ||
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.
👍 , however your space/time complexity are both O(n^2)
# Time complexity: O(n) - It will take n/2 swaps to reverse the string | ||
# Space complexity: O(n) - For the system stack | ||
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.
👍
# Time complexity: O(n) - one recursion for each bunny | ||
# Space complexity: O(n) - system stack | ||
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.
👍
# Time complexity: O(n) - has to look through each character | ||
# Space complexity: O(n) - system stack | ||
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.
This is working if the number of "(" and ")" match, but what about ")("?
# Time complexity: O(n) - Linear search | ||
# Space complexity: O(n) - system stack | ||
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.
👍
# Time complexity: O(n) - n/2 recursions | ||
# Space complexity: O(n) - system stack | ||
def is_palindrome(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: O(logn) - Where n is the larger of n or m. | ||
# Reduces n by a factor of 10 every recursion | ||
# Space complexity: O(logn) - System stack | ||
def digit_match(n, m) |
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 compexlity: O(n) - System stack | ||
def fib(n, f0 = 0, f1 = 1, index = 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.
Nice work on a tail recursive version of Fibonacci.
No description provided.