IGCSE Computer Science 0478 Paper 2 mock: 10 questions, 100 marks, 105 minutes, covering trace tables for pseudocode, Boolean truth tables and simplification, linear and binary search comparisons, sequential file blocking, bubble sort, a weighted modulo 11 check digit, array averages, SQL queries, recursion call counts, and conversion of seconds to hours, minutes and seconds, with marking notes.
| # |
Question |
Answer and marking notes |
| 1 |
A teacher uses the following pseudocode algorithm on the integers 1 to 6.
SET total = 0
SET n = 1
WHILE n <= 6
IF n MOD 2 = 0 THEN
total = total + n * n
ELSE
total = total + 2 * n
ENDIF
n = n + 1
ENDWHILE
OUTPUT total
(a) Complete a trace table showing the value of n and total at the end of each iteration. (b) State the final value of total, the number of loop iterations and the final value of n. (c) If the condition is changed to n < 6, what is total? Explain your answer.
|
Marking notes: (a) 1 mark per row, 6 rows: n=1 total=2; n=2 total=6; n=3 total=12; n=4 total=28; n=5 total=38; n=6 total=74. (b) total = 74 (1 mark); 6 iterations (1 mark); final n = 7 (1 mark). (c) With n < 6 the loop runs 5 times, so the even branch for n = 6 is skipped; that iteration adds 6 x 6 = 36, so total = 74 – 36 = 38 (2 marks: expression and reason). Answers without a trace table score at most half marks.
|
| 2 |
A burglar alarm output X is controlled by three sensors A, B and C: X = (A AND NOT B) OR (B AND C).
(a) Complete the 8-row truth table. (b) State how many rows give X = 1. (c) Show that X can also be written as (A OR B) AND (NOT B OR C), using one row as an example.
|
Marking notes: (a) Eight rows, 0.5 mark each (4 marks); X in order is 0, 0, 0, 1, 1, 1, 0, 1. (b) Four rows give X = 1 (2 marks). (c) A. NOT B + B.C = (A + B).(NOT B + C) (2 marks), with row-by-row substitution (2 marks). Example: A=0, B=1, C=1 gives (0 AND 0) OR (1 AND 1) = 1 and (0 OR 1) AND (0 OR 1) = 1. A simplification without verification scores at most 3 marks.
|
| 3 |
A sorted array of 1,000 elements is searched with binary search; a separate unsorted array of 2,000 elements is searched with linear search. Assume 10,000 comparisons per second.
(a) State the number of comparisons for linear search in the worst and average cases. (b) State the maximum number of comparisons for binary search in the worst case and explain using powers of 2. (c) Calculate the worst-case run time in milliseconds for both and compare them.
|
Marking notes: (a) Worst 2,000, average 1,000 (1 mark each). (b) At most 10 comparisons (2 marks): 2^9 = 512 < 1,001 <= 2^10 = 1,024, and each comparison halves the search space, so at most 10 (2 marks for the explanation). (c) Linear: 2,000 / 10,000 = 0.2 s = 200 ms (2 marks); binary: 10 / 10,000 = 0.001 s = 1 ms (2 marks); 200 times faster, but the data must be sorted (2 marks). No marks for a claim that binary search is faster without the numbers.
|
| 4 |
A sequential file holds 2,400 records of 48 bytes each; the disk block size is 4,096 bytes.
(a) How many complete records fit in one block? (b) How many blocks does the whole file need? (c) How many bytes are wasted per block, and what is the total internal fragmentation? (d) Which block must be read to access record 2,000 directly?
|
Marking notes: (a) 4,096 / 48 = 85.33, so 85 records (2 marks, division must be shown). (b) 2,400 / 85 = 28.24, rounded up to 29 blocks (3 marks). (c) 4,096 – 85 x 48 = 4,096 – 4,080 = 16 bytes per block (2 marks); 29 x 16 = 464 bytes in total (2 marks). (d) (2,000 – 1) / 85 = 23.51, so block 24 (1 mark). Block 23 ends at record 1,955 and block 24 holds records 1,956 to 2,040. Deduct 1 mark for treating 85.33 as a valid record count: records cannot be split.
|
| 5 |
Eight numbers are sorted ascending with bubble sort: 34, 7, 61, 19, 85, 3, 42, 28. Each pass compares adjacent elements left to right and swaps when the left value is larger.
(a) Write the sequence after the first pass. (b) State the number of comparisons and swaps in the first pass. (c) What is the total number of comparisons in the worst case for n = 8? (d) What does a pass with no swaps tell you, and how does it affect efficiency?
|
Marking notes: (a) 7, 34, 19, 61, 3, 42, 28, 85 (3 marks; deduct 1 per wrong position). (b) 7 comparisons (2 marks) and 5 swaps (2 marks). (c) 8 x 7 / 2 = 28 comparisons (2 marks). (d) No swaps means the list is already sorted, so the algorithm can exit early; the best case falls from O(n^2) to O(n) with only 7 comparisons (1 mark each). If the first pass is traced right to left, re-mark against that direction; a wrong direction scores 0 for the question.
|
| # |
Question |
Answer and marking notes |
| 6 |
An 11-digit code uses a weighted modulo 11 check digit: the first 10 digits are multiplied left to right by weights 10 down to 1, the sum is divided by 11 to give remainder r, and the check digit is (11 – r) MOD 11 (remainder 10 is written as X).
(a) Calculate the weighted sum, the remainder and the check digit for the digits 0 3 5 4 2 1 6 9 8 7. (b) Write the complete 11-digit code. (c) Explain whether this check digit detects the transposition of two adjacent digits, using the swap of 3 and 5 as an example.
|
Marking notes: (a) Weighted sum = 0x10 + 3×9 + 5×8 + 4×7 + 2×6 + 1×5 + 6×4 + 9×3 + 8×2 + 7×1 = 0 + 27 + 40 + 28 + 12 + 5 + 24 + 27 + 16 + 7 = 186 (3 marks); 186 / 11 = 16 remainder 10 (2 marks); check digit = (11 – 10) MOD 11 = 1 (2 marks). (b) 03542169871 (1 mark). (c) After the swap the sum is 188, a difference of 2, and 2 MOD 11 is not 0, so the check digit changes and the error is detected (2 marks). Adjacent weights differ by 1, so swapping two different digits can never give a multiple of 11.
|
| 7 |
Ten students’ marks are stored in an array: marks = [58, 72, 45, 91, 66, 83, 54, 77, 69, 88].
(a) Write pseudocode to calculate the mean mark, including total, count and output. (b) Calculate the mean to one decimal place. (c) Write pseudocode that outputs how many students scored above the mean. (d) Explain why integer division must not be used for the mean.
|
Marking notes: (a) Correct initialisation total = 0, count = 0; loop adds each item; mean = total / count (3 marks; deduct 1 each for missing initialisation or no zero-division guard). (b) Total 703, so 703 / 10 = 70.3 (3 marks). (c) Inside the loop, IF marks[i] > average THEN count_above = count_above + 1 (2 marks); the answer is 5 students: 72, 91, 83, 77, 88 (2 marks). (d) Integer division gives 70 and discards 0.3, so comparisons involving 69 and 70 go wrong; a real (floating point) variable keeps the decimal part (1 mark each).
|
| 8 |
A database table students has columns student_id, name, class and score with six records: S01 5A 78; S02 5A 92; S03 5B 65; S04 5B 88; S05 5A 54; S06 5B 71.
(a) Write SQL to list the name and score of class 5A students scoring above 60, highest first. (b) Write SQL to find the mean score of class 5B. (c) State how many rows (a) returns and list them. (d) Explain the difference between a primary key and a foreign key.
|
Marking notes: (a) SELECT name, score FROM students WHERE class = ‘5A’ AND score > 60 ORDER BY score DESC; (4 marks: SELECT, WHERE, AND condition, ORDER BY DESC). (b) SELECT AVG(score) FROM students WHERE class = ‘5B’; (2 marks), result 74.67 (1 mark). (c) Two rows: S02 92 and S01 78 (2 marks). (d) A primary key uniquely identifies each record and cannot repeat or be null; a foreign key is a primary key of another table used to link tables and enforce referential integrity (1 mark each). A missing DESC scores 3 marks at most.
|
| 9 |
Consider the recursive function below.
FUNCTION fact(n)
IF n <= 1 THEN
RETURN 1
ELSE
RETURN n * fact(n - 1)
ENDIF
ENDFUNCTION
(a) State the value returned by fact(6) and the arguments of each call. (b) State the total number of calls made when evaluating fact(6). (c) Explain the purpose of the base case and what happens without it. (d) Compare recursion and iteration in terms of memory use.
|
Marking notes: (a) 720 (2 marks); calls in order fact(6), fact(5), fact(4), fact(3), fact(2), fact(1) (3 marks, outermost first). (b) Six calls in total (2 marks). (c) The base case returns 1 when n <= 1 and stops the recursion (2 marks); without it the function calls fact(0), fact(-1) and so on until the stack overflows (2 marks). (d) Each recursive call occupies a stack frame, so depth n uses O(n) memory; iteration uses a fixed number of variables, O(1) (2 marks).
|
| 10 |
A program converts a passenger’s journey time in seconds into hours, minutes and seconds, using integer division DIV and remainder MOD.
(a) Write the pseudocode, which must output three values. (b) Complete three test cases: 3,725 seconds, 59 seconds and 7,380 seconds. (c) Explain why integer division is used instead of rounding. (d) State one boundary value and explain why it is tested.
|
Marking notes: (a) hours = seconds DIV 3600; minutes = (seconds MOD 3600) DIV 60; secs = seconds MOD 60; output all three (4 marks: 1 per line plus 1 for output). (b) 3,725 s gives 1 h 2 min 5 s (2 marks); 59 s gives 0 h 0 min 59 s (2 marks); 7,380 s gives 2 h 3 min 0 s (2 marks). (c) Time is measured in whole units, so rounding could produce an impossible 60 seconds and the parts would not add back to the input (1 mark each). (d) Boundary values such as 0 s or 3,600 s (exactly one hour, so minutes and seconds must be 0) check that DIV and MOD handle a zero remainder (1 mark each). Any other value for 3,725 seconds scores 0 for that part.
|
A TutorZone practice paper; original questions and passages, not publisher material.