Skip to content

Leaves - Morgan#40

Closed
morganschuler wants to merge 1 commit intoAda-C12:masterfrom
morganschuler:master
Closed

Leaves - Morgan#40
morganschuler wants to merge 1 commit intoAda-C12:masterfrom
morganschuler:master

Conversation

@morganschuler
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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.

Some good work here. Of course some of the methods are incomplete and not working. Take a look at my comments and let me know if you have questions.

Comment thread lib/recursive-methods.rb
Comment on lines +5 to 8
def factorial(num)
raise ArgumentError if num < 0
return num * factorial(num - 1)
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're missing a base case here.

def factorial(num)
  raise ArgumentError, "Cannot accept a number < 0"
  return 1 if num <= 1

  return num * factorial(num - 1)
end

Comment thread lib/recursive-methods.rb
def reverse(s)
raise NotImplementedError, "Method not implemented"
if s.length > 1 then
((s[s.length - 1, 1] = s[(s.length - (s.length + 1)), 1]) + reverse_recursive(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.

You don't have a reverse_recursive method 🤔

Comment thread lib/recursive-methods.rb
def reverse_inplace(s)
raise NotImplementedError, "Method not implemented"
return s if s.length <= 1
reversed_str = 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.

You're calling the reverse method in the method above here.

It's also in no way in place.

Comment thread lib/recursive-methods.rb
# Space complexity: ?
# Time complexity: O(n)
# Space complexity: O(n)
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, although since you are creating a new array with s[1..s.length-2] your time & space complexities are off.

They should be O(n2)

Comment thread lib/recursive-methods.rb
raise NotImplementedError, "Method not implemented"
# Time complexity: O(n)
# Space complexity: O(n)
def search(array, value, index = 0)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're never calling this method with another index number, so you don't need this argument.

Alternatively you don't need to create a new array and instead call the method with an increasing index.

Comment thread lib/recursive-methods.rb
# Space complexity: ?
# Time complexity: O(n)
# Space complexity: O(n)
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.

👍

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