Skip to content

Conversation

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

This is good progress, you have some well done methods here, you should be proud. Take a look at my notes and let me know if you have questions.

# Space complexity: ?
# Time complexity: O(n)
# Space complexity: O(n)
def factorial(n)

Choose a reason for hiding this comment

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

👍

if rev.length == string.length
return rev
end
rev = string[first] + rev

Choose a reason for hiding this comment

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

String concatenation creates a new array and copies all the individual elements over and so is O(n) by itself.

# Time complexity: O(n)
# Space complexity: O(1)

def reverse(string, rev = "", first = 0)

Choose a reason for hiding this comment

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

👍 Nice work, however because you are creating new arrays with each iteration you have time/space complexity of O(n2)

# Space complexity: O(1)

#All the variables that you have to change would go in the parameters.
def reverse_inplace(s, first = 0, last = s.length - 1)

Choose a reason for hiding this comment

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

👍 However your space complexity is O(n) because of the call stack.

def bunny(n)
raise NotImplementedError, "Method not implemented"
return ears = (n + n)
bunny(n)

Choose a reason for hiding this comment

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

Just for readability

Suggested change
bunny(n)
return ears + bunny(n)

#I want to add n to itself,but I don't now what my base case would be
def bunny(n)
raise NotImplementedError, "Method not implemented"
return ears = (n + n)

Choose a reason for hiding this comment

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

Suggested change
return ears = (n + n)
ears = 2

raise NotImplementedError, "Method not implemented"
# Time complexity: O(n)
# Space complexity: O(n)
def nested(s, first = 0, last = s.length - 1)

Choose a reason for hiding this comment

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

👍


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

Choose a reason for hiding this comment

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

We'll go over this in class.

raise NotImplementedError, "Method not implemented"
# Time complexity: O(n)
# Space complexity: O(n)
def is_palindrome(string, length = 0, letter = 0, hash = {}, results = [])

Choose a reason for hiding this comment

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

I think you made this a little more complicated than you needed to here.

def is_palindrome(string, first = 0, last = string.length -1)
  return true if first > last
  return false if string[first] != string[last]
  return is_palindrome(string, first + 1, last -1)
end

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