Skip to content

Branches - Erika#46

Open
emaust wants to merge 1 commit into
Ada-C12:masterfrom
emaust:master
Open

Branches - Erika#46
emaust wants to merge 1 commit into
Ada-C12:masterfrom
emaust:master

Conversation

@emaust

@emaust emaust commented Sep 18, 2019

Copy link
Copy Markdown

No description provided.

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

@CheezItMan CheezItMan left a comment

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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)

# The restricted_array is terminated by 'nil' i.e. array[length] = nil
# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n) - constant

Copy link
Copy Markdown

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!

def print_array(array)
raise NotImplementedError
index = 0
array.length.times do

Copy link
Copy Markdown

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


# For an unsorted array, searches for 'value_to_find'.
# Returns true if found, false otherwise.
# Time complexity: ?

Copy link
Copy Markdown

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

# Space complexity: ?
def find_largest(array, length)
raise NotImplementedError
current = 0

Copy link
Copy Markdown

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]

# Space complexity: ?
def find_smallest(array, length)
raise NotImplementedError
current = array[0]

Copy link
Copy Markdown

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]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever!

# Returns true if found, false otherwise.
# Time complexity: ?
# Space complexity: ?
def binary_search(array, length, value_to_find)

Copy link
Copy Markdown

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


# For an array sorted in ascending order, searches for 'value_to_find'.
# Returns true if found, false otherwise.
# Time complexity: ?

Copy link
Copy Markdown

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