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

Angela #10

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

Angela #10

wants to merge 1 commit into from

Conversation

AngelaOh
Copy link

@AngelaOh AngelaOh commented Oct 6, 2019

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.

You didn't take a dynamic programming approach to these solutions at all. Take a look at my notes and when we review this in class. Memoization as an approach can greatly improve the time complexity of these algorithms.

Comment on lines +12 to +24
while i < size
max_ending_here = 0
j = i
while j < size
max_ending_here = max_ending_here + nums[j]
if max_so_far < max_ending_here
max_so_far = max_ending_here
end
j += 1
end
i += 1
end
return max_so_far

Choose a reason for hiding this comment

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

Think about how you could use a dynamic programming approach (saving max subarrays) to avoid having this inner loop.

Comment on lines +23 to 26
def newman_conway_helper(num)
return 1 if num == 1 || num == 2
return newman_conway_helper( newman_conway_helper(num - 1)) + newman_conway_helper(num - newman_conway_helper(num - 1))
end

Choose a reason for hiding this comment

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

This is exactly the same problem as fibonacci. Please re-read the textbook curriculum on this. Your solution is O(3n), which is much worse than the linear time solution.

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