{"base":{"id":"cs9-11","subject":"Algorithms","title":"Comparing two algorithms","scene":"code9","steps":[{"mode":"sumcmp","eyebrow":"Same answer, different work","title":"Adding 1 to n","body":"Algorithm A adds the numbers one by one. Algorithm B uses a formula. Both are correct. Change n and compare how many steps each needs.","controls":[{"id":"n","label":"n","min":10,"max":1000,"step":10,"value":100}]},{"mode":"maxcmp","eyebrow":"Finding the largest","title":"One pass or sort first?","body":"To find the largest number, A checks each number once; B sorts the whole list first. Change the list size and compare the comparisons.","controls":[{"id":"n","label":"List size","min":5,"max":100,"step":5,"value":20}]},{"mode":"criteria","eyebrow":"Choosing","title":"Correct, efficient, clear","body":"Compare two algorithms that test whether a number is prime. First check both are correct, then compare steps and clarity.","actions":[{"id":"c0","label":"Look at A"},{"id":"c1","label":"Look at B"}]},{"mode":"quiz","eyebrow":"Check yourself","title":"Efficiency","body":"Both algorithms give the right answer. A takes 1000 steps, B takes 10 steps.","question":"Which is more efficient?","options":["A","B","Neither"],"answer":1,"right":"Correct. Fewer steps for the same correct result.","wrong":"Not quite. Efficient means less work.","look":"sumcmp"}],"more":[{"type":"cards","id":"ideas","eyebrow":"Popular idea vs science","title":"Common mix-ups","items":[{"tag":"Popular idea","title":"\"The shortest algorithm is always best.\"","body":"It must first be correct; then consider steps and clarity."},{"tag":"Popular idea","title":"\"If two algorithms give the same answer they are equally good.\"","body":"One may take far more steps or be harder to understand."},{"tag":"Popular idea","title":"\"Efficiency only matters for supercomputers.\"","body":"Phones and websites handle huge amounts of data; efficient algorithms save time and battery."}]},{"type":"cards","id":"code","eyebrow":"Pseudocode","title":"Two solutions","items":[{"tag":"A: loop","title":"Sum 1 to n","body":"total ← 0\nFOR i ← 1 TO n\n    total ← total + i\nNEXT i","code":true},{"tag":"B: formula","title":"Sum 1 to n","body":"total ← n × (n + 1) ÷ 2","code":true}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Card race","items":[{"title":"Find the highest card","time":"15 minutes","need":["A pack of cards","A timer"],"steps":["Shuffle 20 cards. Method A: look at each card once, keeping the highest so far.","Method B: sort all 20 into order, then take the last.","Time each method and count your steps.","Which method is better for this task?"],"why":"Comparing methods on the same input shows which does less work.","safety":"No safety risks."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Six more questions","questions":[{"question":"What should you check first when comparing algorithms?","options":["That both are correct","Which is shorter","Which looks nicer"],"answer":0,"right":"Correct. A fast wrong answer is useless.","wrong":"Not quite. Correctness first."},{"question":"Sum 1 to 50 with a loop: how many additions?","options":["3","1","50"],"answer":2,"right":"Correct. One per number.","wrong":"Not quite. One addition per pass."},{"question":"Why compare algorithms on the same inputs?","options":["To make the comparison fair","To save paper","Inputs don't matter"],"answer":0,"right":"Correct. Different inputs could change step counts.","wrong":"Not quite. Fair test."},{"question":"Which is usually easier to maintain?","options":["A clear, well-structured algorithm","A very clever but confusing one","The longest one"],"answer":0,"right":"Correct. Others need to understand it.","wrong":"Not quite. Think of fixing it later."},{"question":"To find the largest of n numbers, one pass needs about…","options":["n² comparisons","n − 1 comparisons","1 comparison"],"answer":1,"right":"Correct. Compare each with the biggest so far.","wrong":"Not quite. Each number once."},{"question":"Algorithm A: 20 steps, correct. B: 5 steps, wrong for some inputs. Choose…","options":["B","Either","A"],"answer":2,"right":"Correct. B gives wrong answers.","wrong":"Not quite. Correctness matters most."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can explain…","items":["how to check two algorithms are both correct","how to compare the number of steps","why clarity matters","how to choose the best algorithm for a task"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"efficiency","meaning":"How much work an algorithm needs."},{"word":"correctness","meaning":"Giving the right answer for every valid input."},{"word":"maintainability","meaning":"How easy code is to understand and change."},{"word":"comparison","meaning":"Checking two values against each other."},{"word":"trace","meaning":"Following an algorithm step by step."}]},{"type":"sources","id":"sources","title":"Sources","items":["BBC Bitesize KS3 Computer Science","Raspberry Pi Foundation, Computing curriculum resources"]}]},"overlay":null}