Skip to content

Conversation

@AliQassab
Copy link

@AliQassab AliQassab commented Oct 18, 2025

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

Added memoization caching to improve performance:

  • Fibonacci: Added global cache to avoid O(2^n) recursive calls → O(n) time complexity
  • Making Change: Added cache for (total, coins) combinations to avoid redundant calculations
    Both functions now run significantly faster while maintaining correct results.

Questions

Ready for review! All tests pass.

@AliQassab AliQassab added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Complexity The name of the module. labels Oct 18, 2025
Copy link

@OracPrime OracPrime left a comment

Choose a reason for hiding this comment

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

There are some serious inefficiencies with this attempt to make the code more efficient - worth revisiting to improve the efficiency

return 0

# Create cache key from current state
cache_key = (total, tuple(coins))

Choose a reason for hiding this comment

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

converting the list to a tuple every time is going to be expensive. Also at each stage you're creating a new list, which will also be expensive. The new lists are always the same list, but starting later. Can you think of a way you could refactor the code so that it always uses the same tuple, and the recursion is achieved by passing a parameter indicating where the first usable entry in the tuple is? In that situation, how much can you simplify the key to the cache as well?

result = fibonacci(n - 1) + fibonacci(n - 2)

cache[n] = result
return result

Choose a reason for hiding this comment

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

This file is good.

Copy link
Author

Choose a reason for hiding this comment

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

Refactored to use a single tuple with an coin_index parameter instead of creating new lists via slicing. This eliminates expensive tuple conversions and list slicing, and simplifies the cache key to (total, coin_index).

@OracPrime OracPrime 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 Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Complexity The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants