Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brenna's PR #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Brenna's PR #19

wants to merge 2 commits into from

Conversation

bcmdarroch
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) because we iterate over each element in the array once.
What is the space complexity of the length method? Provide justification. O(1) because the variables i and length do not change in size based on the input array.
What is the time complexity of the print_array method? Provide justification. O(n) because we iterate over each element in the array once.
What is the space complexity of the print_array method? Provide justification. O(1) because the variable i does not change in size based on the input array.
What is the time complexity of the reverse method? Provide justification. O(n) because the values are switched in place over one iteration.
What is the space complexity of the reverse method? Provide justification. O(1) because variables i and j do not change based on input array.
What is the time complexity of the search method? Provide justification. O(n) because we iterate over each element in the array once.
What is the space complexity of the search method? Provide justification. O(1) because variable i does not change based on input array.
What is the time complexity of the delete method? Provide justification. O(n) because we iterate over each element in the array once.
What is the space complexity of the delete method? Provide justification. O(1) because the variable i does not change based on input array.
What is the time complexity of the empty method? Provide justification. O(n) because we iterate over each element in the array once.
What is the space complexity of the empty method? Provide justification. O(1) because the variable i does not change based on input array.
What is the time complexity of the find_largest method? Provide justification. O(n) because we iterate over each element in the array once.
What is the space complexity of the find_largest method? Provide justification. O(1) because the variable i does not change based on input array.
What is the time complexity of the insert_ascending method? Provide justification. O(n) because we iterate over each element in the array once.
What is the space complexity of the insert_ascending method? Provide justification. O(1) because the variables i, inserted, and temp do not change based on input array.

@shrutivanw
Copy link
Collaborator

Nice work! A few comments below:

In delete, if the length is less than 2 i.e. 1 or no element, you update array[0] to be special value. This seems wrong. What if the array was [3] and the value_to_delete was 5. Since 5 is not in the array, nothing should get deleted in this case. Similarly, if the array is empty, nothing should happen.

Because you're calling sort from delete method, the time complexity of delete will become O(n^2) - same as the time complexity of sort. How will you do this without calling sort to keep the time complexity O(n)?

In find_largest, the array is not sorted. So you'll need to find it by scanning each element. It's not guaranteed to be the last value before SPECIAL_VALUE starts.

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