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

C. Gutierrez #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions lib/max_subarray.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@

# Time Complexity: ?
# Space Complexity: ?
def max_sub_array(nums)
return 0 if nums == nil
# Time Complexity: O(n)
## The method iterates over the entire array but does so only once

# Space Complexity: O(1)
## There are a limited number of variables that are constantly being re-assessed, so as the input goes to infitity the space requirements do not grow.

def max_sub_array(number_array)
Comment on lines +2 to +8

Choose a reason for hiding this comment

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

👍

length = number_array.length
if length == 0
return nil
elsif length == 1
return number_array[0]
end

max_so_far = number_array[0]
max_ending_here = 0

i = 0

until i == length do

max_ending_here = max_ending_here + number_array[i]

if max_so_far < max_ending_here
max_so_far = max_ending_here
i += 1
elsif max_ending_here < 0
max_ending_here = 0
i += 1
else
i+= 1
end
end

return max_so_far

raise NotImplementedError, "Method not implemented yet!"
end
42 changes: 39 additions & 3 deletions lib/newman_conway.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@


# Time complexity: ?
# Space Complexity: ?
# Time complexity: O(n)
## As the number goes to infinity, its values have to be assessed relative to whatever's already in the array, but because it's based on an array, the look-up cost is very low given that an index value is being passed in.
# Space Complexity: O(n)
## As the number goes to infinity, the amount of space will grow at the same rate

def newman_conway(num)
Comment on lines +3 to 8

Choose a reason for hiding this comment

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

👍 Awesome work 😃

raise NotImplementedError, "newman_conway isn't implemented"

if num == 0 || num == nil
raise ArgumentError
elsif num == 1
return "1"
elsif num == 2
return "1 1"
end

if num >= 3
return_array = [1, 1]
end

i = 3

until i > num do

# P(n) = P(P(n - 1)) + P(n - P(n - 1))

temp_a = return_array[(return_array[i-2])-1]

temp_b = return_array[(i-(return_array[i-2]))-1]

temp = temp_a + temp_b

i += 1

return_array.push temp
end

return_string = return_array.join(" ")

return return_string

end