โ† Back to subjects
โญ 0
OCR A-level Computer Science (H446) ยท Elements of computational thinking
Mini-Lesson

Elements of computational thinking

This mini-lesson covers OCR 2.1 โ€” Elements of computational thinking: the five habits of mind that OCR examines directly, and that underpin the whole of Component 02.

  • Thinking abstractly โ€” models, and what to leave out
  • Thinking ahead โ€” inputs, outputs, preconditions, caching, reusable components
  • Thinking procedurally โ€” decomposition and top-down design
  • Thinking logically โ€” decision points
  • Thinking concurrently โ€” the real costs and benefits of parallelism

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.

2.1.1 ยท Abstractly

Thinking abstractly

Abstraction is the deliberate removal of detail that does not matter, so that what does matter can be reasoned about.

  • Representational abstraction โ€” a model that throws detail away on purpose. The London Underground map is geographically wrong, and that is precisely why it works: it keeps the order of the stops and the interchanges, and discards distance and direction, which a passenger does not need.
  • Abstraction by generalisation โ€” grouping things by shared characteristics, as a superclass does.
  • Procedural abstraction โ€” a subroutine you can call without knowing its internals.
  • Data abstraction โ€” an ADT defined by its operations, not its storage.

Every abstraction is a choice about what to lose. The skill lies in knowing which details are safe to discard: a flight simulator that abstracts away turbulence is a fine game and a dangerous training tool.

Reality vs an abstraction of reality: a model is never the thing itself. A road-network graph with weights for distance cannot answer questions about roadworks unless you built that in. When a model gives a stupid answer, the fault is usually in what the abstraction omitted.

2.1.2 ยท Ahead

Thinking ahead

Deciding in advance what a program will need and what it must guarantee.

  • Inputs and outputs โ€” identify them before writing anything. What arrives, in what form, and what must come out?
  • Preconditions โ€” what must already be true for a subroutine to work? A binary search has the precondition that the list is sorted. Stating it means the caller is responsible for it, and the routine need not waste time re-checking.
  • Caching โ€” store the result of an expensive operation in case it is needed again. A browser caches images; a program memoises a recursive function so f(3) is computed once, not fifty times.
  • Reusable components โ€” write a general subroutine once, use it everywhere, and fix a bug in one place rather than twenty.

The cost of caching is not zero: cached data can become stale โ€” the cached page is no longer what the server holds โ€” and the cache consumes memory. You trade space for time, and you accept the risk of serving something out of date. Naming that trade-off is what earns the marks.

Calculate

Your turn โ€” caching a recursion

1The naive Fibonacci function f(n) = f(nโˆ’1) + f(nโˆ’2) makes 9 calls to compute f(5). With memoisation (caching each result the first time it is computed), how many distinct values of f must actually be calculated?
values
Hint: Once cached, each distinct subproblem is only ever computed once. List the distinct arguments needed: f(5), f(4), and so on down.
2.1.3 ยท Procedurally

Thinking procedurally

Decomposition breaks a problem into sub-problems, and those into sub-problems, until each piece is small enough to solve directly. This is top-down design, and it is what a structure chart shows.

Why it works:

  • each subroutine can be written, tested and debugged independently;
  • work can be shared between programmers;
  • modules can be reused in other projects;
  • the order of execution can be reasoned about clearly.

Thinking logically means identifying every decision point โ€” every place the flow of a program can branch โ€” and being certain what happens in each case, including the ones you did not expect. Every unhandled branch is a bug waiting to happen.

The order of the sub-problems matters. Decomposition is not just chopping the problem up; it is working out which pieces depend on which. You cannot sort before you have read the data, and you cannot validate before you know the rules.

2.1.5 ยท Concurrently

Thinking concurrently

Concurrent processing interleaves tasks so they appear simultaneous โ€” on a single core, the OS rapidly switches between them. Parallel processing runs them genuinely at the same time on multiple cores.

BenefitCost
More work completed in the same timeNot every task can be parallelised โ€” some steps depend on earlier ones
The program stays responsive while waiting for I/OShared data must be protected: race conditions and deadlock
Independent work can be split across cores or machinesCoordination overhead, and much harder debugging โ€” bugs may not be reproducible
Worked example โ€” the limit of parallelism

A task takes 100 s. 80% of it can be parallelised; the other 20% cannot.

Sequential part: 20 s. Parallel part on 4 cores: 80 รท 4 = 20 s.

Total = 20 + 20 = 40 s โ€” a speed-up of 2.5ร—, not 4ร—.

With infinite cores the parallel part shrinks to nothing, but the 20 s sequential part remains. You can never beat 20 s.

That is Amdahl's law, and it is the single most important thing to say about parallelism in an exam. The speed-up is capped by the part of the task that cannot be divided, no matter how many cores you throw at it.

Calculate

Your turn โ€” parallel speed-up

2A task takes 100 seconds. 80% of it can be run in parallel; the remaining 20% is strictly sequential. Running the parallel portion across 4 cores, how many seconds does the whole task now take?
seconds
Hint: The sequential 20 s cannot be sped up at all. Divide only the 80 s parallel part by 4, then add the two together.
Quick check

Concurrency

?Why does doubling the number of cores rarely halve the run time of a real program?
Quick check

Preconditions

?A subroutine binarySearch(list, target) states the precondition the list is sorted in ascending order. What is the point of stating it?
Quick check

Abstraction

?The London Underground map is geographically inaccurate. Why is this a strength rather than a flaw?
2.1.4 ยท Logically

Thinking logically

Thinking logically means finding every point at which the program can branch, and being certain what happens on every path โ€” including the ones you did not plan for.

  • Identify each decision point (every IF, CASE, WHILE condition).
  • Work out the conditions that lead down each branch, and make sure they are exhaustive and mutually exclusive.
  • Ask what happens on the branch you consider impossible. If the answer is "nothing", you have a bug.
IF score > 70 THEN grade โ† "A" ELSE IF score > 50 THEN grade โ† "B" ELSE IF score > 30 THEN grade โ† "C" ENDIF // what if score is 20? grade is never set!

The missing ELSE is a classic: the code above leaves grade undefined for any score of 30 or below. Every chain of conditions needs a final ELSE that catches everything else โ€” even if all it does is raise an error.

2.1.2 ยท Ahead

Reusable components and performance modelling

Reusable components are written once and used many times โ€” a library, a class, a subroutine with well-chosen parameters. The gains are compounding: less code to write, one place to fix a bug, and behaviour you have already tested. The discipline it demands is generality: a routine hard-coded to one file name is not reusable.

Performance modelling simulates how a system will behave before it is built โ€” the load on a server at peak, the length of a supermarket queue, the throughput of a network. It is used where testing the real thing would be too expensive, too slow, or too dangerous (you cannot crash a real aircraft to see what happens).

The limit of any model: it inherits every assumption of the abstraction beneath it. A queue model that assumes customers arrive at random will be badly wrong at 5 p.m. on a Friday. When a model gives an absurd answer, suspect the assumptions, not the arithmetic.

Calculate

Your turn โ€” caching

3A web cache serves 80% of requests from local memory in 5 ms. The other 20% must fetch from the origin server, taking 200 ms. What is the average response time, in milliseconds?
ms
Hint: Take a weighted average: (0.8 ร— 5) + (0.2 ร— 200).
Quick check

Caching

?What is the main risk of caching a value rather than recomputing it?
Sort it

Which element of computational thinking?

Tap the activity, then tap the kind of thinking it shows.

๐ŸŽญ Thinking abstractly

โญ๏ธ Thinking ahead

๐Ÿช“ Thinking procedurally

Match it

Match the idea to its name

Tap an item on the left, then its partner on the right.

Idea
Name
Recap

The big ideas to know

Thinking abstractly: representational ยท generalisation ยท procedural ยท data โ€” every abstraction is a choice about what to lose

Thinking ahead: inputs and outputs ยท preconditions ยท caching (space for time, risk of staleness) ยท reusable components

Thinking procedurally: decomposition ยท top-down design ยท order of dependency between sub-problems

Thinking logically: identify every decision point and know what happens in every branch

Thinking concurrently: concurrent (interleaved) vs parallel (simultaneous) ยท race conditions and deadlock ยท Amdahl's law caps the speed-up

That is the whole of OCR 2.1. Press Finish to see your score.

๐Ÿ†

Mini-lesson complete!

โญโญโญ

You've worked through Elements of computational thinking 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.

๐Ÿ“ฃ Smashed it? Share your score

Challenge a mate to beat your stars, or show a parent how you got on.

โ†’ Back to all subjects