Skip to content

Conversation

@sjscotton
Copy link

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.

Nice work, you hit the learning goals here. See my comments regarding space and time as you missed the cost of some of the built-in ruby methods.

Overall, outstanding work


# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n), where n is the length of s, reverse will get called n/2 times

Choose a reason for hiding this comment

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

This is actually O(n^2) since s[1...-1] creates a new string of length n-2 each iteration. This is true for both space & time.


# Time complexity: O(n), where n is the length of s, reverse will get called n/2 times
# Space complexity: O(n) where n is the length of s, n/2 number of stack frames will be used. Unless you are using a language that utilizes tail recursion, then the space complexity would be constant
def r_reverse_inplace(s, i)

Choose a reason for hiding this comment

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

👍 Outstanding

# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n), where n is the length of s, nested will get called n/2 times
# Space complexity: O(n) where n is the length of s. A new stack frame will be used each call, and by slicing into the array a new array is created during each call, which i think would make it 0(2n)

Choose a reason for hiding this comment

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

O(n^2) similar to reverse.

# Space complexity: ?
# Time complexity: O(n)
# Space complexity: O(n),
def search(array, value)

Choose a reason for hiding this comment

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

O(n^2) similar to reverse.

# Space complexity: ?
# Time complexity: O(n), where n is the length of s, nested will get called n/2 times
# Space complexity: O(n) where n is the length of s. A new stack frame will be used each call
def is_palindrome(s)

Choose a reason for hiding this comment

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

O(n^2) similar to reverse.

Could you have used a technique similar to the one you used with reverse_in_place?

return is_palindrome(s.slice!(1...-1))
end

# Time complexity: O(log10 n) where n is the smaller number between n and m, each call to r_didget_match divids both numbres by 10 and terminates when wither becomes 0.

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