Open
Conversation
CheezItMan
reviewed
Sep 22, 2020
Collaborator
CheezItMan
left a comment
There was a problem hiding this comment.
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) |
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) |
Collaborator
There was a problem hiding this comment.
👍 , 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) |
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) |
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) |
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) |
Collaborator
There was a problem hiding this comment.
👍 , 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
*need to review Big-O!