Skip to content

Leaves - Alice#20

Open
sun-alice wants to merge 1 commit into
Ada-C12:masterfrom
sun-alice:master
Open

Leaves - Alice#20
sun-alice wants to merge 1 commit into
Ada-C12:masterfrom
sun-alice:master

Conversation

@sun-alice

Copy link
Copy Markdown

No description provided.

@CheezItMan CheezItMan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread lib/recursive-methods.rb
# 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/recursive-methods.rb
raise NotImplementedError, "Method not implemented"
return s if s.length <= 1

reversed_s = reverse(s[1..-1])

Copy link
Copy Markdown

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.

Comment thread lib/recursive-methods.rb
Comment on lines +12 to 14
# 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)

Copy link
Copy Markdown

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.

Comment thread lib/recursive-methods.rb
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 Awesome!

Comment thread lib/recursive-methods.rb
# 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/recursive-methods.rb
# 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍
This works, but has similar issues with time/space complexity as reverse.

Comment thread lib/recursive-methods.rb
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 The time/space complexity is O(log n) in both.

This also assumes that the array is sorted.

Comment thread lib/recursive-methods.rb
# 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)

Copy link
Copy Markdown

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.

Comment thread lib/recursive-methods.rb
# 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)

Copy link
Copy Markdown

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.

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