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

Danielle Birbal - Restricted-Array #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

birbalds
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 every element of the array is visited once
What is the space complexity of the length method? Provide justification. Constant because only a int variable is used
What is the time complexity of the print_array method? Provide justification. O(n) because every element of the array is visited once
What is the space complexity of the print_array method? Provide justification. Constant because only a int variable is used
What is the time complexity of the reverse method? Provide justification. O(n) because every element of the array is visited once
What is the space complexity of the reverse method? Provide justification. Constant because only variables were used
What is the time complexity of the search method? Provide justification. O(n) because it can take visiting each element of the array once to get a result
What is the space complexity of the search method? Provide justification. Constant because no extra space needed
What is the time complexity of the delete method? Provide justification. O(n) because every element is potentially visited once
What is the space complexity of the delete method? Provide justification. Constant because no extra space is used
What is the time complexity of the empty method? Provide justification. O(n) because every element is visited
What is the space complexity of the empty method? Provide justification. Constant because no extra space is used
What is the time complexity of the find_largest method? Provide justification. O(n) because every element is visited once
What is the space complexity of the find_largest method? Provide justification. Constant because only variables were used
What is the time complexity of the insert_ascending method? Provide justification. O(n) because every element is visited only once
What is the space complexity of the insert_ascending method? Provide justification. Constant because only variables were used

@birbalds birbalds changed the title Completed array methods Danielle Birbal - Restricted-Array Aug 17, 2017
# Returns true if found, false otherwise.
def search(array, length, value_to_find)
(0...length).each do |i|
return true if array[i] = value_to_find
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be comparison instead of assignment. i.e. if array[i] == value_to_find and not if array[i] = value_to_find, which will always be true.

@shrutivanw
Copy link
Collaborator

Nicely done!

Apart from the minor bug in search (This should be comparison instead of assignment. i.e. if array[i] == value_to_find and not if array[i] = value_to_find, which will always be true.), the rest 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