Skip to content

Conversation

@Allison-Northrop
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 it has to scan every variable in the string.
What is the space complexity of the length method? Provide justification. O(1) because there's a constant amount of variables
What is the time complexity of the print_array method? Provide justification. O(n) because it has to scan every object/variable in the string.
What is the space complexity of the print_array method? Provide justification. O(1) because there's a constant amount of variables it has to visit to print
What is the time complexity of the reverse method? Provide justification. O(n) because it has to visit every item.
What is the space complexity of the reverse method? Provide justification. O(1) because there's a constant amount of variables it needs to visit
What is the time complexity of the search method? Provide justification. O(n) because it has to scan every item before it finds it
What is the space complexity of the search method? Provide justification. O(1) because there's a constant amount of variables
What is the time complexity of the sort method? Provide justification. O(n^2) because it has to iterate more than once
What is the space complexity of the sort method? Provide justification. O(1) because there's a constant amount of variables
What is the time complexity of the delete method? Provide justification. O(n) because it has to visit every item until it finds the variable to delete.
What is the space complexity of the delete method? Provide justification. O(1) because there's a constant amount of variables
What is the time complexity of the empty method? Provide justification. O(n) because it has to visit every item and delete it
What is the space complexity of the empty method? Provide justification. O(1) because there's a constant amount of variables
What is the time complexity of the find_largest method? Provide justification. O(n) because it has to visit every item to compare with a variable.
What is the space complexity of the find_largest method? Provide justification. O(1) because there's a constant amount of variables.
What is the time complexity of the insert_ascending method? Provide justification. O(n) because you have to visit each item
What is the space complexity of the insert_ascending method? Provide justification. O(1) because there are constant variables

# Sorts the array in ascending order.
def sort(array, length)
puts "NOT IMPLEMENTED"
#TODO
Copy link
Collaborator

Choose a reason for hiding this comment

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

i = 0
length.times do
if value_to_delete == array[i]
array[i] = SPECIAL_VALUE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently this may cause a SPECIAL_VALUE to be in the middle of valid values in the array (fragmentation). How can you update this method so all valid values are towards the end?

@shrutivanw
Copy link
Collaborator

The implemented methods and their time, space complexities looks good.

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