Skip to content

Comments

WestMidlands| SDC NOV 2025 |Sara Tahir| Sprint 2 | Improve with caches#119

Open
SaraTahir28 wants to merge 3 commits intoCodeYourFuture:mainfrom
SaraTahir28:feature/Improvecaches
Open

WestMidlands| SDC NOV 2025 |Sara Tahir| Sprint 2 | Improve with caches#119
SaraTahir28 wants to merge 3 commits intoCodeYourFuture:mainfrom
SaraTahir28:feature/Improvecaches

Conversation

@SaraTahir28
Copy link

@SaraTahir28 SaraTahir28 commented Feb 21, 2026

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Improved the performance of both the fibonacci and making_change functions by adding caching (memoisation) to avoid recalculating the same subproblems.

Questions

I dont have any questions.

@github-actions

This comment has been minimized.

@SaraTahir28 SaraTahir28 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 21, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 21, 2026
@github-actions

This comment has been minimized.

@SaraTahir28 SaraTahir28 changed the title WestMidlands | SDC Nov 2025 | Sara Tahir | Sprint 2 | Feature/Improvecaches WestMidlands| SDC NOV 2025 |Sara Tahir| Sprint 2 | Improvecaches Feb 21, 2026
@github-actions

This comment has been minimized.

@SaraTahir28 SaraTahir28 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 21, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 21, 2026
@SaraTahir28 SaraTahir28 changed the title WestMidlands| SDC NOV 2025 |Sara Tahir| Sprint 2 | Improvecaches WestMidlands| SDC NOV 2025 |Sara Tahir| Sprint 2 | Improve with caches Feb 21, 2026
@SaraTahir28 SaraTahir28 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 21, 2026
Copy link

@cjyuan cjyuan Feb 22, 2026

Choose a reason for hiding this comment

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

Array creation is a relatively costly operation.

From line 42, we know coins can only be one of the following 9 arrays:

[200, 100, 50, 20, 10, 5, 2, 1]
[100, 50, 20, 10, 5, 2, 1]
[50, 20, 10, 5, 2, 1]
...
[1]
[]

We could further improve the performance if we can

  • avoid repeatedly creating the same sub-arrays at line 42 (e.g. use another cache), and
  • create key as (total, a_unique_integer_identifying_the_subarray) instead of as (total, tuple of coins)
    • There are only a small number of different subarrays. We can easily assign each subarray a unique integer.

Copy link
Author

Choose a reason for hiding this comment

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

  1. Thanks for the suggestion . I’ve updated the implementation so I no longer slice the coins list. Instead, I pass a start_index through the recursion, which avoids creating new subarrays entirely.
  2. I also switched the cache key to (total, start_index) rather than (total, tuple(coins)). This gives each of the 9 possible sub‑arrays a unique integer “identity” automatically, without needing a separate mapping
  3. This keeps the logic the same but removes the repeated list allocations and makes the memoisation faster and cheaper.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 22, 2026
@SaraTahir28 SaraTahir28 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 22, 2026
@cjyuan
Copy link

cjyuan commented Feb 22, 2026

Changes look good.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants