Skip to the page
Year 10 Β· Computer Science Β· Summer 2 Β· Databases and the Year 10 mock

Revision: Paper 2 topics 7 to 10

Exam practicePresent β–Ά

What this lesson covers

7.7 Trace tables

Cambridge IGCSE Computer Science 0478 Β· Topic 7: Algorithm design and problem-solving Β· Paper 2

7.9 Writing and amending algorithms

Cambridge IGCSE Computer Science 0478 Β· Topic 7: Algorithm design and problem-solving Β· Paper 2

10.3 Expressions and circuits

Cambridge IGCSE Computer Science 0478 Β· Topic 10: Boolean logic Β· Paper 2

You will learn to

  • Complete a trace table, a pseudocode task, a logic circuit and an SQL query under time.
  • Plan time on Paper 2, leaving enough for the 15-mark scenario question.
  • Evaluate your answers with the mark scheme and record why each mark was lost.

Success criteria

  • I can finish four types of Paper 2 question in the time set.
  • I can say how many minutes to spend on a 15-mark question.
  • I can sort my lost marks into 'did not know', 'misread' and 'careless'.
The syllabus points for these sections
  • Explain what a dry run and a trace table are for.
  • Complete a trace table for an algorithm with a loop and selection.
  • Use a trace table to find the output and spot errors.
  • Write algorithms precisely, with the exact comparison the problem needs.
  • Amend a given algorithm to do a new job.
  • Plan and answer a 15-mark scenario question.
  • Explain how the scenario question is marked.
  • Write a logic expression from a problem statement.
  • Draw a logic circuit from an expression, without simplifying.
  • Write a logic expression from a circuit.
  • Write a logic expression from a truth table using the 1 rows.

Key words

Say each word, then read what it means. Every one is in the glossary too.

Algorithm
A precise, ordered set of steps that solves a problem.
Program development life cycle
The four stages of making a program: analysis, design, coding and testing.
Structure diagram
A top-down diagram that shows how a system is split into sub-systems.
Pseudocode
A structured, code-like way of writing an algorithm that is not tied to one language.
Totalling
Adding values into a running total, for example Total ← Total + Value.
Counting
Adding 1 to a counter each time something happens.
Bubble sort
Sorting by comparing neighbouring items and swapping them if they are in the wrong order, pass after pass.
Validation
An automatic check that input data is reasonable and follows set rules.
Check digit
An extra digit calculated from the other digits, used to catch typing errors.
Trace table
A table used in a dry run to record the value of each variable as an algorithm runs.
Logic gate
An electronic component that takes one or two inputs and gives one output by a fixed rule.
Truth table
A table that lists every possible input combination and the output for each one.
Logic circuit
Two or more logic gates joined together to give one output.
Logic expression
A written description of a circuit using gate names, such as X = A AND NOT B.
NOT
A one-input gate whose output is the opposite of its input; also called an inverter.
AND
A gate whose output is 1 only when both inputs are 1.
OR
A gate whose output is 1 when at least one input is 1.
NAND
NOT AND: the output is 0 only when both inputs are 1.
NOR
NOT OR: the output is 1 only when both inputs are 0.
XOR (EOR)
Exclusive OR: the output is 1 when the two inputs are different.
Input
A signal going into a gate or circuit, such as a sensor reading of 1 or 0.
Output
The single result signal that comes out of a gate or circuit.
Working column
An extra truth-table column holding the output of one gate inside a circuit.
Sum of products
An expression made by AND-ing the inputs of each row with output 1, then OR-ing those groups together.

The explanation

Read it here, or open the study page below to go one step at a time with things to try.

What Paper 2 tests

Paper 2 (Algorithms, Programming and Logic) lasts 1 hour 45 minutes. It has 75 marks.

It covers topics 7 to 10. It ends with a 15-mark scenario question, answered in pseudocode or program code.

Question typeHow to get the marks
Trace tableWork one line at a time. Write a value only when it changes. Copy the output exactly.
Write pseudocodeUse the exact comparison the question needs, such as > or >=. Indent inside loops and IFs.
Logic circuitUse the standard gate symbols. Draw the expression as given. Do not simplify it.
SQL queryUse the exact table and field names from the question. One clause per line.
!Watch out

Check the paper length on the current Cambridge 0478 syllabus for the year your pupils sit the exam.

Plan your time

105 minutes Γ· 75 marks = 1.4 minutes per mark. The same rule as Paper 1.

The scenario question: 15 Γ— 1.4 = 21 minutes. Add a few minutes to plan it first.

β˜…Remember

Leave about 25 minutes for the 15-mark scenario question. Do not spend it all on the early questions.

  • Read the scenario. Underline every task it asks for.
  • Write a short plan: inputs, loops, checks, outputs.
  • Then write the code, one task at a time.

Mark it like an examiner

  1. Swap scripts with a partner, or mark your own in a different colour.
  2. Give one tick for each point in the mark scheme. No tick for 'nearly'.
  3. Write the missing point next to each lost mark.
  4. Sort every lost mark into one group from the table.
Why the mark was lostFix for next time
Did not knowAdd it to the RAG list as red. Revise it.
Misread the questionUnderline the command word and the key numbers before answering.
Careless slipLeave 5 minutes at the end to check trace tables and code.
Ran out of timeUse the 1.4 minutes per mark rule. Move on when stuck.
?Why?

Why sort lost marks?

Each group has a different fix. More revision does not help with careless slips.

7.7 Trace tables

What a trace table is

A dry run means working through an algorithm by hand, line by line, without a computer.

A trace table records the dry run. It has one column for each variable, and one for the output.

Write a new value in a column only when that variable changes. Move to a new row when the loop goes round again.

?Why?

A dry run lets you check an algorithm before it is coded. It also shows exactly where a logic error happens.

!Watch out

Do not fill every cell. Cambridge mark schemes usually want a value only where it changes. Copying values down is not wrong but takes time and causes mistakes.

Worked dry run

This algorithm reads numbers until the user types -1. A value that only means 'stop' is called a rogue value.

Input data: 12, 7, 20, 9, -1. Follow each row of the table below and check you agree.

Then use the toy. Pick Counting (WHILE), a similar rogue-value loop, and press Step to run it one line at a time.

ValueTotalCountHighestOUTPUT
000
1212112
7192
2039320
9484
-112 20
e.g.Example
Row 1: the three variables start at 0. Value 12: Total 0 + 12 = 12, Count 1. 12 > 0, so Highest = 12. Value 7: Total 19, Count 2. 7 > 12 is false, so Highest stays 12. Value 20: Total 39, Count 3. 20 > 12, so Highest = 20. Value 9: Total 48, Count 4. 9 > 20 is false. Value -1: the WHILE condition is false, so the loop ends. Output: 48 / 4 = 12, then 20.
DECLARE Value : INTEGER
DECLARE Total : INTEGER
DECLARE Count : INTEGER
DECLARE Highest : INTEGER
Total ← 0
Count ← 0
Highest ← 0
INPUT Value
WHILE Value <> -1 DO
  Total ← Total + Value
  Count ← Count + 1
  IF Value > Highest
    THEN
      Highest ← Value
  ENDIF
  INPUT Value
ENDWHILE
OUTPUT Total / Count, " ", Highest
total = 0
count = 0
highest = 0
value = int(input())
while value != -1:
    total = total + value
    count = count + 1
    if value > highest:
        highest = value
    value = int(input())
print(total / count, highest)
!Watch out

The rogue value -1 is not added to the total. The loop checks the value before using it. That is why there is an `INPUT` before the loop and another at the end of it.

There is something to try for this step in the IGCSE library.

7.9 Writing and amending algorithms

Be precise, and amend with care

An algorithm must say exactly what to do. 'More than 50' is `> 50`. '50 or more' is `>= 50`. These give different results for 50.

Set every total, counter, highest and lowest to a start value before the loop. Use meaningful names like `PassCount`, not `x`, and `//` comments.

An amend question asks you to change a given algorithm. Find the line that controls the behaviour and change only that line.

Example: to make the bubble sort give descending order (largest first), change `>` to `<` in the comparison.

Words in the questionPseudocode
over 18 / more than 18`Age > 18`
18 or over / at least 18`Age >= 18`
under 18 / less than 18`Age < 18`
between 1 and 21 inclusive`Days >= 1 AND Days <= 21`
not equal to -1`Value <> -1`
e.g.Example
7, 3, 9, 2, 5 sorted with the amended line: Output: 9, 7, 5, 3, 2
// Original: sorts into ascending order (smallest first)
IF Numbers[Index] > Numbers[Index + 1]

// Amended: sorts into descending order (largest first)
IF Numbers[Index] < Numbers[Index + 1]
numbers = [7, 3, 9, 2, 5]
top = 5
swap = True
while swap == True and top > 1:
    swap = False
    for index in range(top - 1):
        # amended: < instead of > gives descending order
        if numbers[index] < numbers[index + 1]:
            temp = numbers[index]
            numbers[index] = numbers[index + 1]
            numbers[index + 1] = temp
            swap = True
    top = top - 1
print(numbers)
?Why?

Rewriting the whole algorithm wastes time and can add new errors. The examiner is looking for the one or two key changes.

!Watch out

`Days >= 1 AND <= 21` is wrong. Write the variable on both sides: `Days >= 1 AND Days <= 21`.

The 15-mark scenario question: plan first

The last question on Paper 2 is a scenario worth 15 marks. Allow about 30 minutes. You may answer in pseudocode, Python, Visual Basic or Java.

Read the scenario twice. Underline every task. Make a numbered checklist and tick each item as you code it.

Sample scenario: a teacher records three tests for each of 30 students. Each test is out of 50. Names are already in `StudentName[1:30]`.

e.g.Example
Tasks in the sample scenario: 1. Input three marks per student and store them in StudentMark[1:30, 1:3]. 2. Validate each mark: 0 to 50. 3. Calculate and store each student's total in StudentTotal[1:30]. 4. Calculate each student's average, rounded to 1 decimal place. 5. Output each name with total and average. 6. Count and output the students with a total of 120 or more (a merit). 7. Output the class average total and the name of the student with the highest total. All inputs and outputs need suitable messages.
?Why?

Marks are given for meeting each requirement. A checklist stops you forgetting one, which is the most common way to lose marks here.

Model answer in pseudocode and Python

The model answer uses two nested `FOR` loops: one for students, one for tests. It reuses validation, totalling, counting, maximum and average.

Read the comments. They say what each part does, which also earns marks.

Python lists start at index 0, so the Python loops use `range(30)` and `range(3)`.

The first Python line is a stand-in for the names, so the program can run. In the exam you do not write it, because the names are already stored.

e.g.Example
If one student scores 45, 40 and 38: Total = 45 + 40 + 38 = 123. Average = 123 Γ· 3 = 41.0 123 >= 120, so MeritCount goes up by 1. If 123 is more than TopTotal, TopTotal becomes 123 and TopStudent becomes this student's index. Python sample run: Enter mark for test 1 for Student 1: 55 Error: a mark must be from 0 to 50. Enter it again: 31
// StudentName[1:30] already holds the 30 names
DECLARE StudentName : ARRAY[1:30] OF STRING
DECLARE StudentMark : ARRAY[1:30, 1:3] OF INTEGER
DECLARE StudentTotal : ARRAY[1:30] OF INTEGER
DECLARE Student : INTEGER
DECLARE Test : INTEGER
DECLARE Mark : INTEGER
DECLARE Total : INTEGER
DECLARE Average : REAL
DECLARE ClassTotal : INTEGER
DECLARE MeritCount : INTEGER
DECLARE TopTotal : INTEGER
DECLARE TopStudent : INTEGER

// set the class totals and counters to their start values
ClassTotal ← 0
MeritCount ← 0
TopTotal ← -1
TopStudent ← 1

FOR Student ← 1 TO 30
  Total ← 0
  FOR Test ← 1 TO 3
    // input one mark and validate it with a range check (0 to 50)
    OUTPUT "Enter mark for test ", Test, " for ", StudentName[Student]
    INPUT Mark
    WHILE Mark < 0 OR Mark > 50 DO
      OUTPUT "Error: a mark must be from 0 to 50. Enter it again"
      INPUT Mark
    ENDWHILE
    // store the valid mark and add it to this student's total
    StudentMark[Student, Test] ← Mark
    Total ← Total + Mark
  NEXT Test
  // store the total, work out the average and output the results
  StudentTotal[Student] ← Total
  Average ← ROUND(Total / 3, 1)
  OUTPUT StudentName[Student], " Total: ", Total, " Average: ", Average
  ClassTotal ← ClassTotal + Total
  // a total of 120 or more earns a merit
  IF Total >= 120
    THEN
      MeritCount ← MeritCount + 1
  ENDIF
  // remember the highest total so far and whose it is
  IF Total > TopTotal
    THEN
      TopTotal ← Total
      TopStudent ← Student
  ENDIF
NEXT Student

// whole-class results
OUTPUT "Class average total: ", ROUND(ClassTotal / 30, 1)
OUTPUT "Number of merits: ", MeritCount
OUTPUT "Highest total: ", StudentName[TopStudent], " with ", TopTotal
# The question says the names are already stored.
# This line is a stand-in so the program can run.
student_name = ["Student " + str(n) for n in range(1, 31)]
student_mark = [[0, 0, 0] for row in range(30)]
student_total = [0] * 30

# set the class totals and counters to their start values
class_total = 0
merit_count = 0
top_total = -1
top_student = 0

for student in range(30):
    total = 0
    for test in range(3):
        # input one mark and validate it with a range check (0 to 50)
        mark = int(input("Enter mark for test " + str(test + 1) + " for " + student_name[student] + ": "))
        while mark < 0 or mark > 50:
            mark = int(input("Error: a mark must be from 0 to 50. Enter it again: "))
        # store the valid mark and add it to this student's total
        student_mark[student][test] = mark
        total = total + mark
    # store the total, work out the average and output the results
    student_total[student] = total
    average = round(total / 3, 1)
    print(student_name[student], "Total:", total, "Average:", average)
    class_total = class_total + total
    # a total of 120 or more earns a merit
    if total >= 120:
        merit_count = merit_count + 1
    # remember the highest total so far and whose it is
    if total > top_total:
        top_total = total
        top_student = student

# whole-class results
print("Class average total:", round(class_total / 30, 1))
print("Number of merits:", merit_count)
print("Highest total:", student_name[top_student], "with", top_total)
?Why?

The Python version was run with 90 test marks, including invalid ones, to check it works. In Python, `round(total / 3, 1)` keeps one decimal place; `//` would cut off the decimals.

!Watch out

Store values in the arrays the question names. Calculating the total but not storing it in StudentTotal loses marks.

How the 15 marks are awarded

Recent mark schemes use levels, not one mark per line. AO2 (applying techniques and data structures) gives up to 9 marks. AO3 (comments, identifiers, logic and accuracy) gives up to 6 marks.

The examiner reads the whole answer and picks the band that fits best. Minor syntax errors are ignored if the logic is clear.

BandAO2: techniques and data structures (9)AO3: comments, names, accuracy (6)
Top7–9: all tasks covered with the right techniques; arrays store all the data5–6: fully commented, meaningful names, logical and accurate, meets all requirements
Middle4–6: some techniques suit the problem; some data stored correctly3–4: some comments, most names sensible, most requirements attempted
Low1–3: at least one technique used; some data stored, not well1–2: no useful comments, some sensible names, at least one requirement attempted
e.g.Example
The model answer reaches the top bands because it: - inputs with messages and validates every mark (input, iteration, selection) - stores marks in the 2D array and totals in StudentTotal (data structures) - uses totalling, counting, maximum, average and ROUND - outputs every result with a message - has a comment for every section and meaningful names like MeritCount
?Why?

Because marks come in bands, a working answer to every task beats a perfect answer to half of them. Attempt every requirement, even if one part is rough.

10.3 Expressions and circuits

From a statement to an expression

A logic expression describes a circuit in words, like `X = (A AND B) OR NOT C`.

Read the statement and turn each condition into a letter = 1 or letter = 0. "is on" or "is open" means the letter itself. "is off" or "is not" means NOT and the letter.

Join the conditions with the words the statement uses: "and" β†’ AND, "or" β†’ OR. Use brackets to keep each group together.

e.g.Example
Statement: a garden pump P switches on if the soil is dry (D = 1) and it is not raining (R = 0), or if the timer is on (T = 1). soil is dry β†’ D not raining β†’ NOT R timer is on β†’ T Expression: P = (D AND NOT R) OR T
!Watch out

"R = 0" in a statement means you must write NOT R. Writing R on its own is the opposite of what the statement says.

From an expression to a circuit

Draw one gate for every operator in the expression. Start with the brackets, then work outwards to the final gate.

Every NOT is its own gate. NAND, NOR and XOR are drawn as single gates, not built from others.

Draw exactly what is written. Do not simplify, even if you can see a shorter circuit. Label every input and the output.

e.g.Example
X = (A AND B) OR NOT C Operators: AND, NOT, OR β†’ 3 gates 1. A and B go into an AND gate. 2. C goes into a NOT gate. 3. The AND output and the NOT output go into an OR gate. 4. The OR output is X.
?Why?

Cambridge marks one gate at a time, checking each gate has the right inputs. A simplified circuit has different gates, so it loses marks even if it works.

!Watch out

Every gate except NOT needs exactly two inputs. If one input, such as B, feeds two gates, branch its wire and mark the join with a dot.

From a circuit to an expression

Start at the inputs on the left. Write the expression for the first gates' outputs.

Move right one gate at a time. Put each earlier part in brackets and join it with the next gate's name.

Finish at the output on the right.

ABCA NOR BB AND CX
000101
001101
010000
011011
100000
101000
110000
111011
e.g.Example
Circuit: A and B go into a NOR gate. B and C go into an AND gate. Both outputs go into an OR gate, output X. NOR gate β†’ (A NOR B) AND gate β†’ (B AND C) OR gate β†’ X = (A NOR B) OR (B AND C)
!Watch out

Brackets matter. Without them, `A NOR B OR B AND C` could be read in several ways. Always put each gate's output in brackets.

From a truth table to an expression

Look only at the rows where the output is 1.

For each of those rows, write the three inputs joined by AND. Put NOT in front of any input that is 0 in that row.

Then join all these groups with OR. This is called sum of products. It is long, but always correct.

Try the toy: type the final expression for X from the example. Its truth table should match the one below.

ABCX
0000
0010
0100
0111
1000
1011
1101
1110
e.g.Example
Output is 1 in three rows: A=0, B=1, C=1 β†’ (NOT A AND B AND C) A=1, B=0, C=1 β†’ (A AND NOT B AND C) A=1, B=1, C=0 β†’ (A AND B AND NOT C) X = (NOT A AND B AND C) OR (A AND NOT B AND C) OR (A AND B AND NOT C)
?Why?

Each bracket is 1 for exactly one row and 0 for every other row. OR-ing them gives 1 in exactly the rows you need.

There is something to try for this step in the IGCSE library.

Study it

Open the study page and go one step at a time.

Check yourself

One question at a time. The reason shows after each answer.

Saved on this device.