Designing within an arithmetic-operation budget

A temperature logger must report a rolling mean of its latest eight readings. It produces its first result after reading eight and another result after every subsequent reading. All readings are valid.


Two algorithm designs produce the same results:

  • Recompute: for each result, start a total at zero and add all eight readings in the current group.
  • Reuse: form the first total by starting at zero and adding the first eight readings. For each subsequent reading, subtract the outgoing reading from the stored total and add the incoming reading.


Two consecutive groups of eight readings share the middle seven readings.


For this comparison, each addition or subtraction counts as one operation, including adding a reading to zero. Ignore divisions, comparisons, storage, and all other work. Each design has a budget of at most 240 counted operations for the entire run.


Find the maximum total number of readings each design can process while producing every required result. Also find how many counted operations reuse saves in a separate 100-reading benchmark with no budget limit. Give all three answers as exact integers.

Your answers

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 Algorithm Development Questions: