Skip to content

Comments

Branches -- Paige D.#22

Open
minipaige02 wants to merge 1 commit intoAda-C12:masterfrom
minipaige02:master
Open

Branches -- Paige D.#22
minipaige02 wants to merge 1 commit intoAda-C12:masterfrom
minipaige02:master

Conversation

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

Overall nice work, you hit the learning goals here. Well done. Check my comments below especially with regard to time/space complexity. 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.

👍

def reverse(s)
raise NotImplementedError, "Method not implemented"
return s if s.length <= 1
return s[-1] + reverse(s[1..-2]) + s[0]

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.

# Space complexity: ?
# Time complexity: O(n)
# Space complexity: O(n)
def reverse(s)

Choose a reason for hiding this comment

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

This works, but the time/space complexities are actually O(n2) because you are generating a new array with each recursive call.

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

Choose a reason for hiding this comment

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

👍

# Space complexity: ?
# 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.

👍

# Space complexity: ?
# Time complexity: O(n)
# Space complexity: O(n)
def nested(s)

Choose a reason for hiding this comment

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

👍 This works, but you have similar time/space issues with the above methods.

raise NotImplementedError, "Method not implemented"
# Time complexity: o(n)
# Space complexity: O(n)
def search(array, value, i = 0)

Choose a reason for hiding this comment

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

👍

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

Choose a reason for hiding this comment

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

👍

end No newline at end of file
# Time complexity: O(n) - where n is the number with less digits
# Space complexity: O(n) - where n is the number with less digits
def digit_match(n, m, match_count = 0)

Choose a reason for hiding this comment

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

👍

@minipaige02
Copy link
Author

Thanks for your feedback, Chris! I can see now how some of my methods are creating new arrays each time and therefore greatly increasing the 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