Subtopic 3 of 7
9.3Loop optimisations
Code motion (hoist loop-invariant code), induction-variable elimination and strength reduction (multiplication → addition), loop unrolling.
while (i < n) {loopx = y * zLOOP-INVARIANT: y and z never change insidea[i] = x + i; i++ }
Hoist x = y * z before the loop: computed once instead of n times.
Previous year questions: Code Optimisation & Data-Flow (3)
PYQs are grouped by topic, so this is the full set for Code Optimisation & Data-Flow; try the ones that match this subtopic. Open all 3 on the topic page.