-
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
Arrays exercise submission @ Water class-Hanh Solo #36
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 Hahn, you hit the learning goals here. Nice work.
# Time complexity: There is only one while loop where we iterate over each | ||
# element of the array. Time complexity will be O(n) time where n is how many | ||
# times the loop will execute. | ||
# Space complexity: The method used one local integer variable | ||
# no matter the input size, so the space complexity is constant or O(1). | ||
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: There is only one while loop where we iterate over each | ||
# element of the array. Time complexity will be n time where n is how many | ||
# times the loop will execute. | ||
# Space complexity: constant or O(1) | ||
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) There is only one while loop where we iterate over each | ||
# element of the array. Time complexity will be n time where n is how many | ||
# times the loop will execute. | ||
# Space complexity: constant or O(1) | ||
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:This method will iterate through the entire array. Thus if the | ||
# array size doubles the loop will take twice as long. So the time complexity is O(n) | ||
# Space complexity: This method only creates two additional variables, | ||
# index and max which does not change no matter how large the array gets. | ||
# Therefore the space complexity does not change as the size of the array increases. | ||
# This means the space complexity is O(1). | ||
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: This method will iterate through the entire array. Thus if the | ||
# array size doubles the loop will take twice as long. So the time complexity is O(n) | ||
# Space complexity: This method only creates two additional variables, | ||
# index and min which does not change no matter how large the array gets. | ||
# Therefore the space complexity does not change as the size of the array increases. | ||
# This means the space complexity is O(1). | ||
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(n) this method only iterate through half of the array however | ||
# it is depends on the size of the input. The longer the array, the longer it takes or | ||
# linear complexity. | ||
# Space complexity: constant | ||
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.
👍
# Time complexity: Log2 n means at each step the value reduces by half of the remaining. | ||
# It also means that as the size of the array doubles, | ||
# the number of iterations only increases by 1. | ||
# The main loop in binary search runs log2 n number of times where | ||
# n is the number of elements in the input array. | ||
# Space complexity: constant | ||
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.