-
Notifications
You must be signed in to change notification settings - Fork 49
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
Branches - Erika #46
base: master
Are you sure you want to change the base?
Branches - Erika #46
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. Check my implementation of Binary Search and see if you can see what's different in yours. Also check some of your methods for time and space complexity.
# Time complexity: ? | ||
# Space complexity: ? | ||
# Time complexity: O(n) - constant | ||
# Space complexity: O(n) |
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.
Since you are not building a new array this space complexity is O(1)
@@ -6,56 +6,102 @@ | |||
|
|||
# Calculates the length of the restricted array. All values are integers. | |||
# The restricted_array is terminated by 'nil' i.e. array[length] = nil | |||
# Time complexity: ? | |||
# Space complexity: ? | |||
# Time complexity: O(n) - constant |
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.
O(n) is linear not constant!
end | ||
|
||
# Prints each integer values in the array | ||
# Time complexity: ? | ||
# Space complexity: ? | ||
def print_array(array) | ||
raise NotImplementedError | ||
index = 0 | ||
array.length.times do |
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.
To use your length method this should be length(array).times
array.length.times do | ||
value = array[index] | ||
print "#{value} " | ||
end | ||
end | ||
|
||
# For an unsorted array, searches for 'value_to_find'. | ||
# Returns true if found, false otherwise. | ||
# Time complexity: ? |
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 times and space complexity??
# Finds and returns the largest integer value the array | ||
# Assumes that the array is not sorted. | ||
# Time complexity: ? | ||
# Space complexity: ? | ||
def find_largest(array, length) | ||
raise NotImplementedError | ||
current = 0 |
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.
What if the array holds negative numbers?
I suggest starting current at array[0]
end | ||
|
||
# Finds and returns the smallest integer value in the array | ||
# Assumes that the array is not sorted. | ||
# Time complexity: ? | ||
# Space complexity: ? | ||
def find_smallest(array, length) | ||
raise NotImplementedError | ||
current = array[0] |
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.
See above
f_index = 0 | ||
b_index = length - 1 | ||
while f_index < b_index | ||
array[f_index], array[b_index] = array[b_index], array[f_index] |
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.
Clever!
f_index += 1 | ||
b_index -= 1 | ||
end | ||
return array | ||
end | ||
|
||
# For an array sorted in ascending order, searches for 'value_to_find'. | ||
# Returns true if found, false otherwise. | ||
# Time complexity: ? | ||
# Space complexity: ? | ||
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.
This does may work, but it is not binary search. Check out my implementation of Binary Search
f_index += 1 | ||
b_index -= 1 | ||
end | ||
return array | ||
end | ||
|
||
# For an array sorted in ascending order, searches for 'value_to_find'. | ||
# Returns true if found, false otherwise. | ||
# Time complexity: ? |
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 time and space complexity.
No description provided.