Skip to content

Conversation

@botrethewey
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): method iterates through all the elements in the array once
What is the space complexity of the length method? Provide justification. O(1): only the counter variable i is used in the method, and it is independent of the array size
What is the time complexity of the print_array method? Provide justification. O(n): method iterates through all the elements in the array once
What is the space complexity of the print_array method? Provide justification. O(1): additional counter variable i is used in the method, and it is independent of the array size
What is the time complexity of the reverse method? Provide justification. O(n): method iterates through all the elements in the array once
What is the space complexity of the reverse method? Provide justification. O(1): only two additional counter variables are used in the method, and they are independent of the array size
What is the time complexity of the search method? Provide justification. O(n): method iterates through all the elements in the array, once at most
What is the space complexity of the search method? Provide justification. O(1): additional counter variable i is used in the method, and it is independent of the array size
What is the time complexity of the delete method? Provide justification. O(n): method iterates through all the elements in the array once
What is the space complexity of the delete method? Provide justification. O(1): additional variables are used in the method, but they are independent of the array size
What is the time complexity of the empty method? Provide justification. O(n): method iterates through all the elements in the array once
What is the space complexity of the empty method? Provide justification. O(1): the counter variable i is used in the method, but it is independent of the array size
What is the time complexity of the find_largest method? Provide justification. O(n): method iterates through all the elements in the array once
What is the space complexity of the find_largest method? Provide justification. O(1): the counter variable i is used in the method, but it is independent of the array size
What is the time complexity of the insert_ascending method? Provide justification. O(n): method iterates through all the elements in the array once at most
What is the space complexity of the insert_ascending method? Provide justification. O(1): additional variables are used in the method, but they are independent of the array size

@shrutivanw
Copy link
Collaborator

Nicely done! In delete and insert_ascending because you're calling the sort method, you're time complexity for this method will be the same as sort O(n^2). See if you can implement delete and insert_ascending without calling sort in O(n) time.

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