Three loops in exam notation — Activity 2.12. For each one, count how many times the marked statement runs, for n = 8, then 16, then 32.
Do not run these. Count them. The written response on the exam asks this about your own program, with no computer in the room either.
REPEAT n TIMES { } runs the block n times; NO loop counter is providedREPEAT UNTIL(condition) repeats UNTIL it becomes true; keep your own counter if you need onea ← expression assign the result to aa MOD b remainder: 17 MOD 5 is 2a / b ORDINARY division: 17 / 5 is 3.4There is no for loop on the reference sheet.How many times does <one step> run, for n = 8, 16, and 32?
i ← 1REPEAT UNTIL(i > n){ j ← 1 REPEAT UNTIL(j > n) { <one step> j ← j + 1 } i ← i + 1}Then answer this: the input doubled twice. What happened to the step count each time?
What is displayed, for n = 8, 16, and 32?
left ← nsteps ← 0REPEAT UNTIL(left < 1){ steps ← steps + 1 left ← (left - (left MOD 2)) / 2}DISPLAY(steps)Then answer this: you have seen these three numbers before. Which algorithm from this unit do they belong to, and why is that not a coincidence?
This looks like Problem 1. How many times does <one step> run, for n = 8, 16, and 32?
i ← 1REPEAT UNTIL(i > n){ j ← 1 REPEAT UNTIL(j > 3) { <one step> j ← j + 1 } i ← i + 1}Then answer this: Problems 1 and 3 are both a loop inside a loop, and only one of them grows like n × n. Say in one sentence what in the code decides that.
And this: at n = 2, Problem 3 does more steps than Problem 1. At n = 32 it does far fewer. Work out both, and explain why comparing two algorithms at one small size can mislead you.
This is graded on completion, not accuracy. Show your working — a wrong answer with visible reasoning is worth more to both of us than a right one with none.