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

Sahana Murthy - Restricted Array Homework #25

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

Conversation

sahanamurthy
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 there is a loop that visits each element within the array.
What is the space complexity of the length method? Provide justification. O(1) because there are a constant number of variables throughout the entire function (i and count)
What is the time complexity of the print_array method? Provide justification. O(n) because there is a loop that visits each element within the array.
What is the space complexity of the print_array method? Provide justification. O(1) because there is a constant number of variables throughout the entire function (L)
What is the time complexity of the reverse method? Provide justification. O(n) because there is a loop that visits each element within the array.
What is the space complexity of the reverse method? Provide justification. O(1) because there are a constant number of variables being stored throughout the entire function.
What is the time complexity of the search method? Provide justification. O(n) because there is a loop that visits each element within the array.
What is the space complexity of the search method? Provide justification. O(1) because there are a constant number of variables being stored throughout the entire function.
What is the time complexity of the sort method? Provide justification. O(n^2) because there is a nested loop and for each iteration of i, the method will also iterate through the array for j.
What is the space complexity of the sort method? Provide justification. O(1) because there are a constant number of variables being stored throughout the entire function.
What is the time complexity of the delete method? Provide justification. O(n) because there is a loop that visits each element within the array.
What is the space complexity of the delete method? Provide justification. O(1) because there are a constant number of variables being stored throughout the entire function.
What is the time complexity of the empty method? Provide justification. O(n) because there is a loop that visits each element within the array.
What is the space complexity of the empty method? Provide justification. O(1) because there are a constant number of variables being stored throughout the entire function.
What is the time complexity of the find_largest method? Provide justification. O(n) because there is a loop that visits each element within the array.
What is the space complexity of the find_largest method? Provide justification. O(1) because there are a constant number of variables being stored throughout the entire function.
What is the time complexity of the insert_ascending method? Provide justification. O(n) because there is a loop that visits each element within the array.
What is the space complexity of the insert_ascending method? Provide justification. O(1) because there are a constant number of variables being stored throughout the entire function.

@shrutivanw
Copy link
Collaborator

Two minor comments below. The rest looks great!

You can improve your sort a little by only upating the value of min to be j if array[j] < array[min]. Then after the inner loop is complete, check if min and i are not the same, if they are not, swap array[min] with array[i]. In the case where the array is sorted in descending manner, by making this update you will have one swap instead of n-1 swaps.

For delete, you currently will end up with a fragmented array. e.g. if I wanted to delete 6 from [2, 4, 6, 8, 9], I'll have [2, 4, SPECIAL_VALUE, 8, 9]. How can you update your code to make so that all SPECIAL_VALUEs are at the end of the array?

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