Skip to content

India - Water#36

Open
indiakato wants to merge 4 commits into
Ada-C14:masterfrom
indiakato:master
Open

India - Water#36
indiakato wants to merge 4 commits into
Ada-C14:masterfrom
indiakato:master

Conversation

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

Overall nice work India. You hit the main learning goals. Check out my comments especially regarding the reverse_inplace method.

Comment thread lib/recursive-methods.rb
Comment on lines +3 to 5
# Time complexity: O(n)
# Space complexity: O(n)
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
Comment on lines 17 to 19
# Time complexity: ?
# Space complexity: ?
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.

👍 Time & space complexity?

Comment thread lib/recursive-methods.rb
Comment on lines +27 to 29
# Time complexity: O(n^2)
# Space complexity: O(n^2)
def reverse_inplace(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 method is not reversing the string in place, instead it's creating a new string with each recursive call.

Could you see a way to do it with the following method signature?

Suggested change
# Time complexity: O(n^2)
# Space complexity: O(n^2)
def reverse_inplace(s)
# Time complexity: O(n^2)
# Space complexity: O(n^2)
def reverse_inplace(s, low = 0, high = s.length - 1)

Comment thread lib/recursive-methods.rb
Comment on lines +42 to 44
# Time complexity: O(n)
# Space complexity: O(n)
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
Comment on lines +55 to 57
# Time complexity: O(n^2)
# Space complexity: O(n^2)
def search(array, value)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 However can you see how to do this method with O(n) space/time complexity?

Comment thread lib/recursive-methods.rb
return is_palindrome(s[1..-2])
end
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.

Just noting the incomplete methods.

Comment thread lib/recursive-methods.rb
Comment on lines +67 to 69
# Time complexity: O(n^2)
# Space complexity: O(n^2)
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.

👍 Similar note to the above on 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