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

Branches - Erika #46

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

Branches - Erika #46

wants to merge 1 commit into from

Conversation

emaust
Copy link

@emaust emaust commented Sep 18, 2019

No description provided.

@emaust emaust changed the title Implemented all methods Branches - Erika Sep 18, 2019
Copy link

@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.

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)

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

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

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: ?

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

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]

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]

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)

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: ?

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.

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