Reusing pure results without changing the total

A shop calculates an order quote using a pure function: it returns the same result for the same input and produces no observable side effects. For a positive integer quantity qq, its quote in dollars is


quote⁡(q)=6q+4.\operatorname{quote}(q)=6q+4.


The application adds the quotes for three separate orders by evaluating


Plain text
quote(4) + quote(4) + quote(9)


Compare two implementations. Without a cache, every call evaluates the function body. With memoization, previously computed results are stored by input: a repeated call returns the stored result without evaluating the body again. The cache is initially empty, and calls are processed from left to right.


Complete the table with exact integers. Count function-body evaluations, not additions or cache lookups. Each order still contributes its full quote to the total.

ImplementationTotal quote (dollars)Function-body evaluations (count)
Without a cache
With memoization

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Procedural, Functional, Logical and Object-Oriented Paradigms Questions: