Skip to content

Conversation

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

As you pointed out you didn't get them all done, but most of what you have is pretty good. We'll go over the solutions in class. Let me know what questions you have.

# 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 s.length <= 1
return s
else
return s[-1] + reverse(s[0..-2])

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 on lines +16 to 18
# Time complexity: o(n^2)
# Space complexity: o(n^2)
def reverse(s)

Choose a reason for hiding this comment

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

Correct on the time/space complexities. Can you think of a way to do better?

# Space complexity: ?
# Time complexity:
# Space complexity:
def reverse_inplace(s)

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.


# Time complexity: o(n)
# Space complexity: o(n)
def bunny(n)

Choose a reason for hiding this comment

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

👍


# Time complexity: o(n)
# Space complexity: o(n^2)
def nested(s)

Choose a reason for hiding this comment

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

👍 Time complexity is also O(n^2) because of s[1...-1]

Comment on lines 60 to 62
# 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.

👍 Big-O is O(n^2) due to the repeated creation of new arrays.

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