-
Notifications
You must be signed in to change notification settings - Fork 29
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
base: master
Are you sure you want to change the base?
Angela #10
Conversation
There was a problem hiding this 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.
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 |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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.
No description provided.