-
Notifications
You must be signed in to change notification settings - Fork 53
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
Emily's Completed Methods for Arrays #34
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done Emily, take a look at my comments and let me know what questions you have. Nice work.
# Time complexity: O(n) because I'm performing a linear search until the loop reaches nil in the array. | ||
# Space complexity: O(1), because I'm only looking for 1 value, it doesn't matter what size the array is. | ||
def length(array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time complexity: O(1) because retrieving an element is constant, regardless of the size. | ||
# Space complexity: O(1) because size of the array doesn't matter? Still retrieving one element at a time. | ||
def print_array(array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 , however the time complexity is O(n) because you print out n
elements and it increases as the size of the array increases proportionately.
# Time complexity: O(n) for an unsorted array, because of its linear search to find that value. | ||
# Space complexity: O(1), because I'm only looking for 1 value. | ||
def search(array, length, value_to_find) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time complexity: O(n) because it involves a linear search for an unsorted array. O(1), if it's sorted because the search will end if it's the first element (largest_value = array[0]). | ||
# Space complexity: O(1), because I'm only looking for 1 value. | ||
def find_largest(array, length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time complexity: O(n) because it involves a linear search for an unsorted array. O(1), if it's sorted because the search will end if it's the first element (smallest_val = array[0]). | ||
# Space complexity: O(1), because I'm only looking for 1 value. | ||
def find_smallest(array, length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time complexity: O(1), because I'm retrieving one element at a time? | ||
# Space complexity: O(1) | ||
def reverse(array, length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 , however the time complexity is O(n) because you loop n/2 times.
# Time complexity: O(log n), to narrow down my search by n/2 after an iteration, and then n/4 if there's another iteration that's needed to find the value. | ||
# Space complexity: O(1), because I'm only looking for 1 value. | ||
def binary_search(array, length, value_to_find) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
*need to review Big-O!