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

Emily's Completed Methods for Arrays #34

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

Conversation

emirry
Copy link

@emirry emirry commented Sep 22, 2020

*need to review Big-O!

Copy link
Collaborator

@CheezItMan CheezItMan left a 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.

Comment on lines +9 to 11
# 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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines +21 to 23
# 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)
Copy link
Collaborator

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.

Comment on lines +33 to 35
# 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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines +48 to 50
# 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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines +65 to 67
# 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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines +80 to 82
# Time complexity: O(1), because I'm retrieving one element at a time?
# Space complexity: O(1)
def reverse(array, length)
Copy link
Collaborator

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.

Comment on lines +99 to 101
# 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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

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