-
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
Restricted Arrays #40
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.
Not bad Kalkidan, you hit most of the learning goals. Take a look at the feedback on the binary_search
method. Let me know what questions you have on it.
# Time complexity: 0(n) Linear: iteration depends on length, we have to go through the array until we find the termination character nil. | ||
# Space complexity: O(1); uses constant memory, doesn't matter how big array is, we have one counter, no new data structures being created | ||
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(n) linear, in order to print every element in array we have to go through entire array. | ||
# Space complexity: O(1) uses constant amount of memory, prints elements in array. No matter how array changes, | ||
# new memory is not taken up for this method. | ||
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.
👍
# Time complexity: O(n) linear, have to iterate through array until we find it. | ||
# Space complexity: O(1), constant memory, | ||
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) linear: since it's unsorted, will have to go through the entire array until the largest value is found. | ||
# Space complexity: O(1) memory usage does not change for this method, it is constant. | ||
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) linear: since it's unsorted, will have to go through the entire array until the smallest value is found. | ||
# Space complexity: O(1) memory usage does not change for this method, it is constant. | ||
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.
👍
lib/using_restricted_array.rb
Outdated
# Time complexity: O(n) execute in linear time as compared to the size of the input | ||
# Space complexity: O(1), since it is in place. New memory is not needed to store the reversed array. | ||
# Amount of memory used does not change as the size of the input array changes. | ||
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.
👍
7fdb99e
to
52d9edc
Compare
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.
Nice
# Time complexity: O(log n), the data set size affects the efficiency of the algorithm in a logarithmic fashion | ||
# Space complexity: O(1), memory used does not change as the size of the input array changes | ||
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.
👍
No description provided.