cs-134 — The Sliding Sensor Window

FieldValue
idcs-134
difficultyAdvanced
topicsalgorithm selection, trade-offs, anomalies
lecturelecture-18
estimated time5-minute attempt + 10-minute discussion
prerequisiteslecture-09 (aggregation), lecture-17 (linear scans)
objectivechoose between two implementations of the same rule using computed cost, not intuition
solutionheld by the instructor; discussed after the attempt

Problem

A weather station posts one reading per minute. The dashboard must flag any minute whose value exceeds the average of the previous three minutes (the three before it, not counting itself) by more than 10. Minutes with an incomplete window are never flagged.

Today's first twelve readings:

index:  0  1  2  3   4  5   6   7   8   9  10  11
value:  5  6  7  8  30  9  10  11  45  12  13  14

Two colleagues proposed implementations:

Your deliverables:

  1. The flagged indices and values for the twelve readings, computed by hand (method A logic).
  2. The per-minute cost of A and B, and the total operation count for a full day (n = 1440, k = 3) for each.
  3. Which you would ship, and why — one sentence.
  4. The input that breaks both methods, or makes their output undefined without an extra rule.

If the problem is ambiguous anywhere, state the assumption you are making and carry on — a stated assumption is part of a good answer.

Examples

Solve for the worked instance first. Then ask what would change if one number, name, or condition were replaced by something stranger.

What to notice

Discussion starter

After the solution is revealed, the class spends five minutes on this prompt: "The station upgrades to one reading per second (n = 86,400, k = 180). Re-count the operations. Does your ship decision change, and at what k would it flip?"

Constraints and assumptions

Hints and extension