This mini-lesson covers OCR 2.2 — Problem solving and programming: the techniques you write code with, the computational methods that make hard problems solvable, and the three paradigms OCR examines.
Work through each screen, answer the questions as you go (some are recall, some are calculations you must actually work out) and collect ⭐ stars. Press Start when you're ready.
Three constructs express any computable algorithm: sequence, selection (IF, CASE) and iteration — definite (FOR: a known number of repeats) or indefinite (WHILE, REPEAT).
Modularity means building the program from subroutines:
Scope: a local variable is created when its subroutine is called and destroyed when it returns — it cannot be seen outside. A global is visible everywhere for the whole run.
Prefer locals. Any subroutine can silently modify a global, so a bug can originate anywhere in the program. Locals keep subroutines self-contained, which is what makes them independently testable and reusable.
An IDE earns its keep through: syntax highlighting and auto-complete, breakpoints and single-stepping, a watch window showing variable values as the program runs, an integrated translator, and refactoring tools. Debugging by inserting print statements is what you do when you have not learned the debugger.
| By value | By reference |
|---|---|
| A copy of the value is passed | The memory address is passed |
| Changes inside the subroutine are lost on return | Changes persist in the caller |
| Safe; expensive for large data | Efficient for large arrays; risks unintended side effects |
A recursive subroutine calls itself. It needs a base case, a general case, and arguments that move towards the base case — or you get infinite recursion and a stack overflow.
Each call pushes a stack frame holding the return address, parameters and locals; the frames unwind in reverse as each call returns.
The trade-off: recursion is elegant for naturally recursive problems (tree traversal, quicksort, Towers of Hanoi) but uses more memory and is slower than iteration. Any recursive routine can be rewritten iteratively, using an explicit stack if necessary.
OCR expects you to name and explain these:
Why heuristics are not cheating: for an intractable problem the exact algorithm is worse than useless — it may run for longer than the age of the universe. A heuristic that gets within 5% of optimal in a second is not a compromise; it is the only answer that exists.
LMC is a teaching model of a von Neumann machine: 100 mailboxes (memory), one accumulator, a program counter, and this instruction set:
| Instruction | Effect |
|---|---|
| INP | Read a value into the accumulator |
| OUT | Output the accumulator |
| LDA x | Load the contents of mailbox x into the accumulator |
| STA x | Store the accumulator into mailbox x |
| ADD x / SUB x | Add / subtract the contents of mailbox x |
| BRA x | Branch always to x |
| BRZ x / BRP x | Branch if the accumulator is zero / is positive |
| HLT / DAT | Stop / declare a data location |
Note LDA and STA carefully. LDA copies memory into the accumulator; STA copies the accumulator into memory. Getting them the wrong way round is the single commonest LMC mistake, and it destroys the trace.
A class is a blueprint defining attributes (data) and methods (behaviour). An object is an instance of it, created by instantiation — the constructor runs and sets the initial state.
Favour composition over inheritance. A Car has an Engine (composition); a Circle is a Shape (inheritance). Deep inheritance hierarchies are brittle — a change near the top breaks everything below it. Ask "is-a or has-a?" before you inherit.
BankAccount class holds balance as a private attribute, with a public Deposit() method that rejects negative amounts. What does making it private achieve?Tap the description, then tap the computational method.
Tap an item on the left, then its partner on the right.
Techniques: sequence, selection, iteration · procedure vs function · locals over globals · IDE breakpoints and watches
Parameters: by value = copy, changes lost · by reference = address, changes persist
Recursion: base case + general case + progress towards it · stack frames · slower and hungrier than iteration
Methods: divide and conquer · backtracking · heuristics · data mining · performance modelling · pipelining · visualisation
LMC: INP, OUT, LDA, STA, ADD, SUB, BRA, BRZ, BRP, HLT, DAT — LDA loads from memory, STA stores to it
OOP: class, object, instantiation · encapsulation · inheritance (is-a) · polymorphism via overriding · favour composition
That is the whole of OCR 2.2. Press Finish to see your score.
You've worked through Problem solving & programming for OCR A-level Computer Science (H446). 🎉
Your stars: 0 / 0
Next: test yourself in the Evaluate stage Confidence Quiz, then lock it in with Verify.