Skip to content

Restricted Arrays#33

Open
hn4ever wants to merge 2 commits intoAda-C14:masterfrom
hn4ever:master
Open

Restricted Arrays#33
hn4ever wants to merge 2 commits intoAda-C14:masterfrom
hn4ever:master

Conversation

@hn4ever
Copy link

@hn4ever hn4ever commented Sep 22, 2020

Restricted arrays solution

Copy link
Collaborator

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

Well done, you hit all the learning goals here. Take a look at my comment about reverse. Otherwise nice work!

Comment on lines +9 to 11
# Time complexity: O(n)
# Space complexity: O(1)
def length(array)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines +22 to 24
# Time complexity: O(n)
# Space complexity: O(1)
def print_array(array)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines +35 to 39
# Time complexity:
# sorted: O(n)
# unsorted: O(n)
# Space complexity: O(1)
def search(array, length, value_to_find)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines +55 to 59
# Time complexity:
# sorted: O(1)
# unsorted: O(n)
# Space complexity: O(1)
def find_largest(array, length)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 Actually this algorithm is always O(n) in time complexity

Comment on lines +80 to 84
# Time complexity:
# sorted: O(1)
# unsorted: O(n)
# Space complexity: O(1)
def find_smallest(array, length)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines +103 to 105
# Time complexity: O(n)
# Space complexity: O(1)
def reverse(array, length)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 , this works but since you're making an auxiliary array it has O(n) space complexity.

Can you think of a way to do this without the other array?

Comment on lines 125 to 127
# Time complexity: ?
# Space complexity: ?
def binary_search(array, length, value_to_find)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@hn4ever
Copy link
Author

hn4ever commented Sep 23, 2020

Thank you Chris

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