{"base":{"id":"cs11-06","subject":"Programming","title":"Standard algorithms: totals, max, min, average, counting","scene":"mix","steps":[{"use":"py10","mode":"total","eyebrow":"Totalling","title":"A running total","body":"Start at 0 and add each value.","actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"use":"py10","mode":"count","eyebrow":"Counting","title":"Count what matches","body":"Add 1 each time a value meets a condition.","controls":[{"id":"pass","label":"Pass mark","min":5,"max":20,"step":1,"value":15}],"actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"use":"py10","mode":"avgmax","eyebrow":"Average and maximum","title":"One pass through the data","body":"Track the total and the largest value as you go.","actions":[{"id":"step","label":"Step"},{"id":"run","label":"Run"},{"id":"reset","label":"Reset"}]},{"use":"code9","mode":"maxcmp","eyebrow":"Efficiency","title":"One pass or sort first?","body":"To find the maximum, one pass is faster than sorting.","controls":[{"id":"n","label":"List size","min":5,"max":100,"step":5,"value":20}]},{"use":"py10","mode":"quiz","look":"avgmax","eyebrow":"Check yourself","title":"Minimum","body":"To find the smallest value, what should min start as?","question":"Choose the safest choice.","options":["0","The first item in the list","1000"],"answer":1,"right":"Correct: starting at 0 fails if all values are positive.","wrong":"Not quite."}],"more":[{"type":"cards","id":"worked","eyebrow":"Worked examples","title":"Step by step","items":[{"tag":"Total","title":"Pseudocode","body":"total ← 0\nFOR i ← 0 TO n − 1\n    total ← total + data[i]\nNEXT i","code":true},{"tag":"Count","title":"Condition","body":"IF data[i] >= 50 THEN count ← count + 1","code":true},{"tag":"Max and min","title":"One pass","body":"max ← data[0]; min ← data[0]\nFOR i ← 1 TO n − 1\n  IF data[i] > max THEN max ← data[i]\n  IF data[i] < min THEN min ← data[i]\nNEXT i","code":true},{"tag":"Average","title":"After the loop","body":"average ← total / n","code":true}]},{"type":"cards","id":"mistakes","eyebrow":"Common mistakes","title":"Watch out for these","items":[{"tag":"Mistake","title":"Initialising max to 0","body":"If all values are negative the answer is wrong. Start with the first item."},{"tag":"Mistake","title":"Dividing inside the loop","body":"Work out the average after the loop."},{"tag":"Mistake","title":"Resetting the total inside the loop","body":"Set it to 0 once, before the loop."}]},{"type":"cards","id":"deeper","eyebrow":"Go deeper","title":"More than the lesson","items":[{"tag":"Big data","title":"Streaming","body":"For millions of values, these one-pass algorithms let computers calculate totals and maximums without storing everything."},{"tag":"Statistics","title":"Running averages","body":"Fitness trackers show moving averages of heart rate using the same totalling idea."}]},{"type":"cards","id":"challenge","eyebrow":"Challenge yourself","title":"Stretch your brain","intro":"Try each one on paper before opening the card.","items":[{"tag":"Challenge","title":"Write","body":"Find the position (index) of the largest value.\n\nAnswer: track maxIndex; when data[i] > data[maxIndex], set maxIndex ← i.","code":true},{"tag":"Challenge","title":"Combine","body":"Count how many values are above the average.\n\nAnswer: first loop for total and average; second loop counts values > average."}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Try it yourself","items":[{"title":"Weather stats","time":"25 minutes","need":["Python","A week of temperatures"],"steps":["Store 7 temperatures in a list.","Calculate total, average, max, min and count of days above 20 °C."],"why":"You use all five standard algorithms on real data.","safety":"None."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Eight more questions","questions":[{"question":"A running total starts at…","options":["1","the last value","0"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"Average =","options":["total ÷ count","max − min","count ÷ total"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"Counting adds…","options":["the value each time","1 when a condition is met","nothing"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"max should start as…","options":["0","−1","the first item"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"Data [4, 9, 2]: max =","options":["9","4","2"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"Data [4, 9, 2]: average =","options":["15","5","3"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"Finding max needs how many passes?","options":["Two","n²","One"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"Count values ≥ 50 in [30, 50, 70]:","options":["2","1","3"],"answer":0,"right":"Correct.","wrong":"Not quite."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can…","items":["write totalling, counting, max, min and average algorithms","initialise variables correctly","combine algorithms in one pass","explain efficiency of one-pass algorithms"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"Totalling","meaning":"Adding values into a running total."},{"word":"Counting","meaning":"Adding 1 when a condition is met."},{"word":"Initialise","meaning":"Give a starting value."},{"word":"One pass","meaning":"Visiting each item once."}]},{"type":"sources","id":"sources","title":"Sources","items":["Raspberry Pi Foundation, Isaac Computer Science: standard algorithms","Python documentation: built-in functions max, min, sum","BBC Bitesize, GCSE Computer Science: algorithms","Khan Academy: algorithms"]}]},"overlay":null}