Skip to content

Conversation

@ricecakemonster
Copy link

Restricted Array

Congratulations! You're submitting your assignment.

Comprehension Questions

What is the time and space complexity for each method you implemented? Provide justification.

Question Answer
What is the time complexity of the length method? Provide justification. O(n) calculation time increases according to the array size.
What is the space complexity of the length method? Provide justification. O(1) no additional space needed
What is the time complexity of the print_array method? Provide justification. O(n)
What is the space complexity of the print_array method? Provide justification. O(1)
What is the time complexity of the reverse method? Provide justification. O(n)
What is the space complexity of the reverse method? Provide justification. O(1)
What is the time complexity of the search method? Provide justification. O(n)
What is the space complexity of the search method? Provide justification. O(1)
What is the time complexity of the delete method? Provide justification. O(n)
What is the space complexity of the delete method? Provide justification. O(1)
What is the time complexity of the empty method? Provide justification. O(n)
What is the space complexity of the empty method? Provide justification. O(1)
What is the time complexity of the find_largest method? Provide justification. O(n)
What is the space complexity of the find_largest method? Provide justification. O(1)
What is the time complexity of the insert_ascending method? Provide justification. O(n)
What is the space complexity of the insert_ascending method? Provide justification. O(1)

@shrutivanw
Copy link
Collaborator

Nice work!

Couple of comments:

  • Currently, you delete method leaves the array fragmented. e.g. if you start with [2, 3, 5, 7] and value_to_delete is 3, then the array will become [2, SPECIAL_VALUE, 5, 7]. How can you update this so that all SPECIAL_VALUEs are at the end of the array?

  • Because you are calling sort from your insert_ascending method, the time complexity of insert_ascending will be the same as sort i.e. O(n^2). How can you avoid calling sort and update the insert algorithm so that the time complexity remains O(n)?

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