Skip to content

water - mackenzie #19

Open
mvlofthus wants to merge 3 commits intoAda-C14:masterfrom
mvlofthus:master
Open

water - mackenzie #19
mvlofthus wants to merge 3 commits intoAda-C14:masterfrom
mvlofthus:master

Conversation

@mvlofthus
Copy link

No description provided.

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.

Your largest subarray works, but isn't using dynamic programming and has a pretty bad runtime. See my comments and let me know if you have questions or need help working through it.

We can review it if needed.

Comment on lines +21 to +27
while i < nums.length do
max_ending_here = max_ending_here + nums[i]
if (max_so_far < max_ending_here)
max_so_far = max_ending_here
end
i+=1
end

Choose a reason for hiding this comment

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

You can do this without the nested loop. Think about how you could use same saved values, like the largest subarray so far and the largest ending at the current index and how that could work.

Comment on lines +2 to 4
# Time Complexity: O(n!)? You only go throught the each with index n times, but the inner loop completes decrementing number of loops...
# Space Complexity: O(1), no additional data structures created outside of 2 variables each times
def max_sub_array(nums)

Choose a reason for hiding this comment

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

⚠️ I think this is O(n^2) due to the tested loop. You can do it without the inner loop, and just with some if-else statements.

Comment on lines +3 to 10
# Time complexity: O(n)
# Space Complexity: O(n), always creating 1 array num + 1 length long and 1 string proprtionate to n
# P(1) = 1
# P(2) = 1
# for all n > 2
# P(n) = P(P(n - 1)) + P(n - P(n - 1))
# 1 1 2 2 3 4 4 4 5 6 7 7….
def newman_conway(num)

Choose a reason for hiding this comment

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

👍

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