Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Wrote recursive methods #33

wants to merge 8 commits into from

Conversation

Beatress
Copy link

@Beatress Beatress commented Nov 3, 2020

No description provided.

Copy link

@CheezItMan CheezItMan left a 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.

Comment on lines +3 to 5
# 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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +12 to 15
# 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)

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)

Comment on lines +21 to 23
# 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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +36 to 38
# Time complexity: O(n) - one recursion for each bunny
# Space complexity: O(n) - system stack
def bunny(n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +48 to 50
# Time complexity: O(n) - has to look through each character
# Space complexity: O(n) - system stack
def nested(s)

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 ")("?

Comment on lines +66 to 68
# Time complexity: O(n) - Linear search
# Space complexity: O(n) - system stack
def search(array, value)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +82 to 84
# Time complexity: O(n) - n/2 recursions
# Space complexity: O(n) - system stack
def is_palindrome(s)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +100 to 103
# 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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +124 to +126
# Space compexlity: O(n) - System stack
def fib(n, f0 = 0, f1 = 1, index = 1)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants