Pick the paradigm.

Six original Cambridge-style questions on programming paradigms, including an assembly trace and writing facts and rules, with mark-scheme solutions.

Original questions All questions on this page are original work, written in the Cambridge AS & A Level style. They are not from past papers. They test the same concepts and skills the syllabus rewards.
Keep these straight

How, how, objects, what.

01
Explain
[3 marks]

Explain what is meant by a programming paradigm and describe the main characteristics of the imperative (procedural) paradigm.

  • A paradigm is a style or approach to programming / a way of structuring and thinking about a solution. ✓
  • Imperative: a program is a sequence of statements / commands executed in order that change the program state (values of variables). ✓
  • Code is structured using sequence, selection and iteration and divided into procedures and functions with parameters and local variables. ✓
02
Trace
[4 marks]

Address 200 holds 204, address 201 holds 3, address 202 holds 8, address 203 holds 1 and address 204 holds 6. The index register holds 2. State the value in the accumulator after each instruction is executed separately:

LDM #201   LDD 201   LDI 200   LDX 201

  • LDM #201: 201 (immediate: the operand is the value). ✓
  • LDD 201: 3 (direct: contents of 201). ✓
  • LDI 200: 6 (indirect: 200 holds 204, contents of 204 is 6). ✓
  • LDX 201: 1 (indexed: 201 + 2 = 203, contents of 203 is 1). ✓
03
Write
[4 marks]

The following facts describe a family:

30 parent(rosa, tom).
31 parent(rosa, ivy).
32 parent(tom, max).
33 parent(ivy, zoe).

(a) Write a rule grandparent(X, Y) that is true if X is a grandparent of Y. (b) Write a rule sibling(X, Y) that is true if X and Y have the same parent and are different people. (c) State the result of the goal grandparent(rosa, Y).

  • (a) grandparent(X, Y) IF parent(X, Z) AND parent(Z, Y). ✓
  • (b) sibling(X, Y) IF parent(P, X) AND parent(P, Y) AND NOT(X = Y). ✓
  • (c) Y = max, zoe. ✓
  • Correct use of IF / AND and capital letters for variables throughout. ✓
04
Trace
[3 marks]

Using the clauses in question 3, state the result of each goal: (a) parent(X, zoe) (b) sibling(tom, Y) (c) grandparent(tom, Y).

  • (a) X = ivy. ✓
  • (b) Y = ivy (rosa is the parent of both tom and ivy; tom himself is excluded). ✓
  • (c) false / no result: max has no children recorded, so tom is not a grandparent of anyone. ✓
05
Explain
[4 marks]

Compare the low-level and declarative paradigms.

  • Low-level code uses the processor's instruction set, so it is machine dependent; declarative code is independent of the processor. ✓
  • Low-level code gives every step explicitly (how), working with registers, memory addresses and addressing modes. ✓
  • Declarative code states facts and rules about the problem (what) and does not give the steps. ✓
  • In declarative programming a goal is satisfied by the system searching the knowledge base and backtracking; in low-level code the programmer must write any search themselves. ✓
06
Analysis
[3 marks]

A company wants (a) a driver for a new sensor that must run in very little memory and (b) a system that advises which medicine to give from a set of symptoms. Suggest a suitable paradigm for each and justify your choices.

  • (a) Low-level: direct control of hardware registers and memory addresses; small, fast code. ✓
  • (b) Declarative: the medical knowledge can be written as facts and rules. ✓
  • A goal such as treatment(Patient, Medicine) is satisfied by the system searching the rules, so new knowledge can be added without rewriting the search. ✓

Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.