Repository navigation
London | 26-SDC-March | Jamal Laqdiem| Sprint 2 | Improve code with caches - #214
jamallaqdiem wants to merge 4 commits into
Conversation
| ways_to_make_change_helper(total - current_coin, coins, coin_index) + | ||
| ways_to_make_change_helper(total, coins, coin_index + 1) |
There was a problem hiding this comment.
The original "loop" version and your "without loop" version differ in terms of how deep the recursion can go, which affects the amount of stack space required at runtime. For a large total, the program may exceed the available stack space and fail.
Could you update your code to match the original approach as much as possible?
Notes:
- Supposedly, one level of loop is enough.
- When there is only one coin left to consider, there is a much quicker way to figure out if there is 0 or 1 way to make the change.
There was a problem hiding this comment.
@cjyuan thanks for the review, I've updated the code to use a single loop for the current coin and added a quick shortcut check when only one coin is left to prevent deep recursion.
|
Your PR didn't include a Task ID in its description. Make sure you have put the correct Task ID in its description. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
|
Changes look good. |
|
Your PR didn't include a Task ID in its description. Make sure you have put the correct Task ID in its description. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
1 similar comment
|
Your PR didn't include a Task ID in its description. Make sure you have put the correct Task ID in its description. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
Self checklist
Changelist
Optimised both exercises using local function caches and index-based tracking to eliminate global scope variables and slow array allocations