Question Simulator

O Level Computer Science (2210)

Algorithm design and problem-solving Banker

42 questions · about 20% of the marks we indexed · examined in 8 of 8 sessions.

Questions by year

2026

  • 2026 May/June · Paper 22 · Q3 (a(i), a(ii), b, c)11 marksValidation and verification
  • 2026 May/June · Paper 22 · Q46 marksProgram development life cycle, decomposition and design methods
  • 2026 May/June · Paper 22 · Q5 (a, b, c)10 marksFinding and correcting errors in algorithms · Standard methods (totalling, counting, max/min, linear search, bubble sort)
  • 2026 May/June · Paper 22 · Q6 (a, b)7 marksTrace tables · Writing, completing and explaining algorithms and flowcharts

2025

  • 2025 Oct/Nov · Paper 22 · Q2 (a, c(i), c(ii))9 marksFinding and correcting errors in algorithms · Standard methods (totalling, counting, max/min, linear search, bubble sort)
  • 2025 Oct/Nov · Paper 22 · Q36 marksTest data
  • 2025 Oct/Nov · Paper 22 · Q4 (a)1 markValidation and verification
  • 2025 Oct/Nov · Paper 22 · Q5 (a, b)9 marksTrace tables · Writing, completing and explaining algorithms and flowcharts
  • 2025 May/June · Paper 22 · Q11 markProgram development life cycle, decomposition and design methods
  • 2025 May/June · Paper 22 · Q23 marksProgram development life cycle, decomposition and design methods
  • 2025 May/June · Paper 22 · Q34 marksTest data
  • 2025 May/June · Paper 22 · Q4 (a, b)7 marksValidation and verification
  • 2025 May/June · Paper 22 · Q5 (a, c)9 marksFinding and correcting errors in algorithms · Standard methods (totalling, counting, max/min, linear search, bubble sort)
  • 2025 May/June · Paper 22 · Q6 (a, b, c)10 marksTrace tables · Writing, completing and explaining algorithms and flowcharts
  • 2025 May/June · Paper 22 · Q7 (a)6 marksWriting, completing and explaining algorithms and flowcharts

2024

  • 2024 Oct/Nov · Paper 22 · Q11 markProgram development life cycle, decomposition and design methods
  • 2024 Oct/Nov · Paper 22 · Q3 (a, b)10 marksWriting, completing and explaining algorithms and flowcharts
  • 2024 Oct/Nov · Paper 22 · Q4 (a, b)8 marksFinding and correcting errors in algorithms · Standard methods (totalling, counting, max/min, linear search, bubble sort)
  • 2024 Oct/Nov · Paper 22 · Q5 (a, b)4 marksProgram development life cycle, decomposition and design methods
  • 2024 Oct/Nov · Paper 22 · Q62 marksValidation and verification
  • 2024 Oct/Nov · Paper 22 · Q7 (a, b, c)8 marksTrace tables · Writing, completing and explaining algorithms and flowcharts
  • 2024 Oct/Nov · Paper 22 · Q84 marksTest data
  • 2024 May/June · Paper 22 · Q11 markProgram development life cycle, decomposition and design methods
  • 2024 May/June · Paper 22 · Q33 marksProgram development life cycle, decomposition and design methods
  • 2024 May/June · Paper 22 · Q4 (a, b(i), b(ii))10 marksValidation and verification
  • 2024 May/June · Paper 22 · Q6 (a, b)8 marksStandard methods (totalling, counting, max/min, linear search, bubble sort)
  • 2024 May/June · Paper 22 · Q7 (b)3 marksFinding and correcting errors in algorithms
  • 2024 May/June · Paper 22 · Q9 (a, b)7 marksStandard methods (totalling, counting, max/min, linear search, bubble sort) · Trace tables

2023

  • 2023 Oct/Nov · Paper 22 · Q11 markValidation and verification
  • 2023 Oct/Nov · Paper 22 · Q2 (a, b, c)7 marksTest data · Validation and verification
  • 2023 Oct/Nov · Paper 22 · Q3 (b)4 marksStandard methods (totalling, counting, max/min, linear search, bubble sort)
  • 2023 Oct/Nov · Paper 22 · Q4 (a, b)9 marksFinding and correcting errors in algorithms · Writing, completing and explaining algorithms and flowcharts
  • 2023 Oct/Nov · Paper 22 · Q6 (a, b)7 marksTrace tables · Writing, completing and explaining algorithms and flowcharts
  • 2023 May/June · Paper 22 · Q11 markProgram development life cycle, decomposition and design methods
  • 2023 May/June · Paper 22 · Q33 marksProgram development life cycle, decomposition and design methods
  • 2023 May/June · Paper 22 · Q4 (a, b(i), b(ii))7 marksValidation and verification
  • 2023 May/June · Paper 22 · Q7 (b, c)7 marksFinding and correcting errors in algorithms · Validation and verification
  • 2023 May/June · Paper 22 · Q9 (a, b)7 marksStandard methods (totalling, counting, max/min, linear search, bubble sort) · Trace tables

2022

  • 2022 Oct/Nov · Paper 22 · Q33 marksValidation and verification
  • 2022 Oct/Nov · Paper 22 · Q42 marksTest data
  • 2022 Oct/Nov · Paper 22 · Q5 (a, b)8 marksFinding and correcting errors in algorithms · Writing, completing and explaining algorithms and flowcharts
  • 2022 Oct/Nov · Paper 22 · Q65 marksTrace tables

References only, not question text. Open Official paper ↗ where Cambridge publishes the paper, or see the official Cambridge past-papers page; for other papers, ask your school. “Paper 42” means Paper 4, variant 2.

Practice questions

Original questions written by HomiLabs in the style of the exam, with answers and mark schemes. They are not Cambridge past paper questions and have not been reviewed by Cambridge. Try each one before opening the answer.

Q1Validation and verification · Core · Paper 2 style · 4 marks
  1. (a) Name the validation check described by each statement.(i) Checks that a value is between a lower and an upper limit.(ii) Checks that data has been entered and the field is not left empty.(iii) Checks that the data is a whole number and not text.(iv) Checks that data follows a set pattern, such as two letters followed by four digits. [4]
Show answer
  1. (a) (i) Range check (ii) Presence check (iii) Type check (iv) Format check
    1 mark for each.
Q2Validation and verification · Core · Paper 2 style · 4 marks
  1. (a) Explain the difference between validation and verification. [2]
  2. (b) Describe two methods of verification that could be used when a new customer's details are typed into a shop's computer. [2]
Show answer
  1. (a) Validation is an automatic check by the computer that data is reasonable/sensible and meets set rules before it is accepted; verification checks that data has been accurately copied or entered, i.e. it matches the original source. (Verification does not check that the data is sensible.)
    1 mark for validation, 1 mark for verification.
  2. (b) Double entry: the data is entered twice and the computer compares the two entries, accepting it only if they match. Visual check: the user (or customer) reads the data on screen and compares it with the original document before confirming.
    1 mark for each method described.
Q3Validation and verification · Standard · Paper 2 style · 4 marks
  1. (a) A program asks the user to enter a month number. The month must be a whole number from 1 to 12. Write pseudocode that repeatedly asks for the month until a valid value is entered, and outputs a suitable message each time an invalid value is entered. [4]
Show answer
  1. (a) DECLARE Month : INTEGEROUTPUT "Enter month number (1 to 12)"INPUT MonthWHILE Month < 1 OR Month > 12 DO OUTPUT "Invalid. Enter a whole number from 1 to 12" INPUT MonthENDWHILE(or an equivalent REPEAT … UNTIL loop)
    1 mark: prompt and INPUT. 1 mark: correct loop structure that repeats until valid. 1 mark: correct condition (< 1 OR > 12, or >= 1 AND <= 12 for UNTIL). 1 mark: error message inside the loop with re-input.
Q4Validation and verification · Standard · Paper 2 style · 5 marks
  1. (a) A warehouse uses 4-digit product codes followed by a check digit. The check digit is calculated as follows:- multiply the 1st, 2nd, 3rd and 4th digits by 4, 3, 2 and 1 respectively- add the results- the check digit is the remainder when the total is divided by 10.Calculate the check digit for the code 3706. Show your working. [2]
  2. (b) A worker types the code 52816. Show whether this code is valid. [2]
  3. (c) The worker meant to type 52186. Explain how the check digit detects this kind of error. [1]
Show answer
  1. (a) 4×3 + 3×7 + 2×0 + 1×6 = 12 + 21 + 0 + 6 = 39; 39 MOD 10 = 9. Check digit = 9 (full code 37069).
    M1 for correct weighted sum 39, A1 for 9.
  2. (b) 4×5 + 3×2 + 2×8 + 1×1 = 20 + 6 + 16 + 1 = 43; 43 MOD 10 = 3, but the check digit entered is 6, so the code is invalid.
    M1 for weighted sum 43 and remainder 3, A1 for stating invalid because 3 ≠ 6.
  3. (c) Two digits (1 and 8) were swapped (transposition error). For the correct code 5218 the weighted sum is 4×5 + 3×2 + 2×1 + 1×8 = 36, giving check digit 6, which matches. Because the digits have different weights, swapping them changes the total to 43 and the calculated check digit to 3, which does not match the 6 entered, so the error is detected.
    1 mark: swapped digits are multiplied by different weights, so the calculated check digit changes and no longer matches the one entered.
Q5Validation and verification · Challenge · Paper 2 style · 6 marks
  1. (a) A games website requires a username that:- is not empty- is between 6 and 12 characters long (inclusive)- starts with an upper-case letter A to Z.Write pseudocode that inputs a username and keeps asking until it meets all three rules. Output a message saying which rule was broken each time the username is rejected. Use the functions LENGTH() and SUBSTRING(). [6]
Show answer
  1. (a) Example:DECLARE UserName : STRINGDECLARE Valid : BOOLEANDECLARE First : CHARREPEAT Valid ← TRUE OUTPUT "Enter a username" INPUT UserName IF LENGTH(UserName) = 0 THEN OUTPUT "Username must not be empty" Valid ← FALSE ELSE IF LENGTH(UserName) < 6 OR LENGTH(UserName) > 12 THEN OUTPUT "Username must be 6 to 12 characters" Valid ← FALSE ENDIF First ← SUBSTRING(UserName, 1, 1) IF First < "A" OR First > "Z" THEN OUTPUT "Username must start with a capital letter" Valid ← FALSE ENDIF ENDIFUNTIL Valid = TRUE
    1 mark: prompt and input inside a loop. 1 mark: presence check. 1 mark: length check with correct limits 6 and 12 inclusive. 1 mark: extracting the first character with SUBSTRING. 1 mark: checking first character is between "A" and "Z". 1 mark: loop repeats until all rules are met, with a specific message for each broken rule.
Q6Validation and verification · Challenge · Paper 2 style · 5 marks
  1. (a) An online form for a college in Peshawar collects these fields. For each field, identify one suitable validation check and explain why it is suitable.(i) Date of birth(ii) National identity card number, written as 5 digits, a hyphen, 7 digits, a hyphen and 1 digit(iii) Mobile phone number(iv) Applicant's family name [4]
  2. (b) An applicant enters a date of birth that passes every validation check but is still wrong. Explain how this is possible. [1]
Show answer
  1. (a) (i) Range check – the date must be within a sensible range, e.g. an applicant aged between 15 and 60.(ii) Format check – the entry must match the pattern 99999-9999999-9 (accept length check of 15 characters).(iii) Length check (e.g. exactly 11 digits) or type check (digits only).(iv) Presence check – the name must be entered (accept type check: letters only).
    1 mark for each suitable check with a reason linked to the field.
  2. (b) Validation only checks that data is reasonable/meets the rules, not that it is correct – e.g. 12/03/2008 typed instead of 21/03/2008 is still a sensible date.
    1 mark.
Q7Trace tables · Core · Paper 2 style · 6 marks

Total ← 0Count ← 0INPUT NumWHILE Num <> -1 DO IF Num > 10 THEN Total ← Total + Num Count ← Count + 1 ENDIF INPUT NumENDWHILEOUTPUT Total, " ", Count

  1. (a) Complete a trace table for the algorithm using the input data 12, 5, 30, 10, 18, -1. Use the columns Num, Total, Count and OUTPUT. [4]
  2. (b) State the purpose of the algorithm. [2]
Show answer
  1. (a) Num | Total | Count | OUTPUT | 0 | 0 |12 | 12 | 1 |5 | | |30 | 42 | 2 |10 | | |18 | 60 | 3 |-1 | | | 60 3(Accept values repeated on rows where they do not change.)
    1 mark: Num column 12, 5, 30, 10, 18, -1. 1 mark: Total column 0, 12, 42, 60. 1 mark: Count column 0, 1, 2, 3. 1 mark: OUTPUT 60 3.
  2. (b) It finds the total and the number (count) of the values entered that are greater than 10, stopping when -1 is entered.
    1 mark: total and count of numbers greater than 10. 1 mark: until the rogue value -1 is input.
Q8Trace tables · Standard · Paper 2 style · 6 marks

FOR Index ← 1 TO 4 IF Data[Index] > Data[Index + 1] THEN Temp ← Data[Index] Data[Index] ← Data[Index + 1] Data[Index + 1] ← Temp ENDIFNEXT Index

  1. (a) The array Data contains 27, 14, 35, 9, 20 in elements 1 to 5. Complete a trace table for the algorithm with the columns Index, Temp, Data[1], Data[2], Data[3], Data[4], Data[5]. [4]
  2. (b) State the name of the standard method this algorithm is part of, and explain why it must be repeated to finish the task. [2]
Show answer
  1. (a) Index | Temp | Data[1..5]1 | 27 | 14, 27, 35, 9, 202 | - | 14, 27, 35, 9, 203 | 35 | 14, 27, 9, 35, 204 | 35 | 14, 27, 9, 20, 35
    1 mark: Index column 1 to 4. 1 mark: Temp column 27, 35, 35 (no value when Index = 2). 2 marks: Data columns correct after each step (1 mark if one error).
  2. (b) Bubble sort. One pass only moves the largest value to the end; the pass must be repeated (until no swaps are made) to put all values in ascending order.
    1 mark: bubble sort. 1 mark: one pass does not fully sort / repeat until no swaps.
Q9Trace tables · Standard · Paper 2 style · 6 marks

DECLARE Number, Sum, Digits : INTEGERINPUT NumberSum ← 0Digits ← 0REPEAT Sum ← Sum + MOD(Number, 10) Number ← DIV(Number, 10) Digits ← Digits + 1UNTIL Number = 0OUTPUT Digits, " ", Sum

  1. (a) Complete a trace table for the algorithm when the input is 40725. Use the columns Number, Sum, Digits and OUTPUT. [4]
  2. (b) Explain what the functions MOD and DIV do in this algorithm. [2]
Show answer
  1. (a) Number | Sum | Digits | OUTPUT40725 | 0 | 0 |4072 | 5 | 1 |407 | 7 | 2 |40 | 14 | 3 |4 | 14 | 4 |0 | 18 | 5 | 5 18
    1 mark: Number column 4072, 407, 40, 4, 0. 1 mark: Sum column 5, 7, 14, 14, 18. 1 mark: Digits column 1 to 5. 1 mark: OUTPUT 5 18.
  2. (b) MOD(Number, 10) gives the remainder when Number is divided by 10, i.e. the last digit; DIV(Number, 10) gives the whole-number result of dividing by 10, i.e. removes the last digit.
    1 mark for each.
Q10Trace tables · Challenge · Paper 2 style · 7 marks

Run ← 0Longest ← 0FOR Day ← 1 TO 8 IF Rain[Day] > 0 THEN Run ← Run + 1 IF Run > Longest THEN Longest ← Run ENDIF ELSE Run ← 0 ENDIFNEXT DayOUTPUT Longest

  1. (a) The array Rain[1:8] holds the daily rainfall in mm for one week and a day in Murree: 0, 4, 7, 0, 2, 3, 5, 0. Complete a trace table with the columns Day, Run, Longest and OUTPUT. [4]
  2. (b) State the purpose of the algorithm. [1]
  3. (c) Explain what would happen if the line Run ← 0 inside the ELSE were removed. [2]
Show answer
  1. (a) Day | Run | Longest | OUTPUT(start) | 0 | 0 |1 | 0 | 0 |2 | 1 | 1 |3 | 2 | 2 |4 | 0 | 2 |5 | 1 | 2 |6 | 2 | 2 |7 | 3 | 3 |8 | 0 | 3 |OUTPUT: 3
    1 mark: Day 1 to 8. 1 mark: Run column 0,1,2,0,1,2,3,0. 1 mark: Longest column 0,1,2,2,2,2,3,3. 1 mark: OUTPUT 3.
  2. (b) It finds the greatest number of consecutive days on which there was rain.
    1 mark.
  3. (c) Run would never reset when a dry day occurs, so it would count the total number of rainy days rather than the longest run; for this data the output would be 5 instead of 3.
    1 mark: Run not reset / counts all rainy days. 1 mark: output 5 for this data.
Q11Trace tables · Challenge · Paper 2 style · 6 marks

REPEAT Swapped ← FALSE FOR Index ← 1 TO 3 IF Data[Index] > Data[Index + 1] THEN Temp ← Data[Index] Data[Index] ← Data[Index + 1] Data[Index + 1] ← Temp Swapped ← TRUE ENDIF NEXT IndexUNTIL Swapped = FALSE

  1. (a) The array Data holds 8, 3, 6, 1 in elements 1 to 4. Complete a trace table for the algorithm with the columns Swapped, Index, Temp, Data[1], Data[2], Data[3], Data[4]. Show each value of Swapped when it is set. [5]
  2. (b) State how many times the REPEAT loop is executed for this data. [1]
Show answer
  1. (a) Swapped | Index | Temp | Data[1..4]FALSE | - | - | 8, 3, 6, 1 (start of pass)TRUE | 1 | 8 | 3, 8, 6, 1TRUE | 2 | 8 | 3, 6, 8, 1TRUE | 3 | 8 | 3, 6, 1, 8FALSE | - | - | 3, 6, 1, 8 (start of pass)FALSE | 1 | - | 3, 6, 1, 8TRUE | 2 | 6 | 3, 1, 6, 8TRUE | 3 | - | 3, 1, 6, 8FALSE | - | - | 3, 1, 6, 8 (start of pass)TRUE | 1 | 3 | 1, 3, 6, 8TRUE | 2 | - | 1, 3, 6, 8TRUE | 3 | - | 1, 3, 6, 8FALSE | - | - | 1, 3, 6, 8 (start of pass)FALSE | 1 | - | 1, 3, 6, 8FALSE | 2 | - | 1, 3, 6, 8FALSE | 3 | - | 1, 3, 6, 8Final: 1, 3, 6, 8
    1 mark: pass 1 correct (8 moves to Data[4]). 1 mark: pass 2 correct. 1 mark: pass 3 correct. 1 mark: final pass with no swaps and Swapped stays FALSE. 1 mark: Temp column correct.
  2. (b) 4
    1 mark.
Q12Writing, completing and explaining algorithms and flowcharts · Core · Paper 2 style · 4 marks
  1. (a) State the purpose of each flowchart symbol.(i) A rounded rectangle (terminator)(ii) A rectangle(iii) A diamond(iv) A parallelogram [4]
Show answer
  1. (a) (i) Start or end (stop) of the algorithm.(ii) A process, e.g. a calculation or assignment.(iii) A decision – a question with Yes/No (True/False) outcomes, used for selection or loops.(iv) Input or output of data.
    1 mark for each.
Q13Writing, completing and explaining algorithms and flowcharts · Core · Paper 2 style · 4 marks

This algorithm inputs five temperatures in degrees Celsius and outputs each one converted to degrees Fahrenheit using F = C × 9 ÷ 5 + 32.DECLARE Celsius, Fahrenheit : REALDECLARE Count : INTEGERFOR Count ← 1 TO 5 OUTPUT "Enter temperature in Celsius" ....(1).... Celsius Fahrenheit ← Celsius * ....(2).... + 32 OUTPUT "Fahrenheit: ", ....(3)........(4).... Count

  1. (a) Complete the pseudocode by writing the missing items (1) to (4). [4]
Show answer
  1. (a) (1) INPUT (2) 9 / 5 (accept * 1.8) (3) Fahrenheit (4) NEXT
    1 mark for each correct item.
Q14Writing, completing and explaining algorithms and flowcharts · Standard · Paper 2 style · 4 marks

DECLARE Amount : REALDECLARE Years : INTEGERINPUT AmountYears ← 0WHILE Amount < 200000 DO Amount ← Amount * 1.08 Years ← Years + 1ENDWHILEOUTPUT Years

  1. (a) State the purpose of the algorithm. [2]
  2. (b) State the output when the input is 100000. [1]
  3. (c) Explain why the output would be 0 if the input were 250000. [1]
Show answer
  1. (a) It calculates how many years it takes for an amount of money growing by 8% each year to reach (at least) 200 000.
    1 mark: number of years. 1 mark: for the amount to reach 200 000 at 8% growth per year.
  2. (b) 10
    1 mark.
  3. (c) The WHILE condition is checked before the loop body; 250000 is not less than 200000, so the loop never runs and Years stays 0.
    1 mark: pre-condition loop not entered.
Q15Writing, completing and explaining algorithms and flowcharts · Standard · Paper 2 style · 6 marks
  1. (a) A new user of a library system must set a password. Write pseudocode that:- asks the user to enter a new password- asks the user to enter the password again- if the two entries match, outputs "Password set"- if they do not match, outputs "Passwords do not match" and asks for both entries again, until they match. [5]
  2. (b) State the name of this method of verification. [1]
Show answer
  1. (a) DECLARE Password1, Password2 : STRINGREPEAT OUTPUT "Enter new password" INPUT Password1 OUTPUT "Enter password again" INPUT Password2 IF Password1 <> Password2 THEN OUTPUT "Passwords do not match" ENDIFUNTIL Password1 = Password2OUTPUT "Password set"
    1 mark: declarations/two different variables. 1 mark: both prompts and inputs. 1 mark: comparison of the two entries. 1 mark: loop repeating until they match. 1 mark: both messages output in the correct places. Do not credit extra checks (e.g. length) that were not asked for.
  2. (b) Double entry (verification)
    1 mark.
Q16Writing, completing and explaining algorithms and flowcharts · Challenge · Paper 2 style · 6 marks
  1. (a) An email address is accepted only if it contains exactly one "@" character and at least one "." after the "@". Write pseudocode that inputs an email address, checks it using these rules, and keeps asking until a valid address is entered. Use the functions LENGTH() and SUBSTRING(). [6]
Show answer
  1. (a) Example:DECLARE Email : STRINGDECLARE Pos, AtCount, AtPos, DotAfter : INTEGERDECLARE Ch : CHARREPEAT OUTPUT "Enter email address" INPUT Email AtCount ← 0 AtPos ← 0 DotAfter ← 0 FOR Pos ← 1 TO LENGTH(Email) Ch ← SUBSTRING(Email, Pos, 1) IF Ch = "@" THEN AtCount ← AtCount + 1 AtPos ← Pos ENDIF IF Ch = "." AND AtPos > 0 THEN DotAfter ← DotAfter + 1 ENDIF NEXT Pos IF AtCount <> 1 OR DotAfter = 0 THEN OUTPUT "Invalid email address" ENDIFUNTIL AtCount = 1 AND DotAfter > 0OUTPUT "Email accepted"
    1 mark: input inside a loop that repeats until valid. 1 mark: loop through every character using LENGTH. 1 mark: extract each character with SUBSTRING. 1 mark: count the @ characters. 1 mark: detect a . after the @. 1 mark: correct final condition (exactly one @ and at least one . after it) with suitable messages.
Q17Finding and correcting errors in algorithms · Core · Paper 2 style · 4 marks

01 DECLARE Total : INTEGER02 DECLARE Mark : INTEGER03 DECLARE Count : INTEGER04 DECLARE Average : INTEGER05 Total ← 006 FOR Count ← 1 TO 1007 OUTPUT Mark08 Total ← Total + Mark09 NEXT Count10 Average ← Total / 511 OUTPUT "Average mark is ", Average

  1. (a) The algorithm should input 10 test marks and output their average, but it contains three errors. Identify the line number of each error and write the corrected line. [3]
  2. (b) Explain why the data type on line 04 needed to be changed. [1]
Show answer
  1. (a) Line 04: DECLARE Average : REALLine 07: INPUT MarkLine 10: Average ← Total / 10
    1 mark for each error identified with a correct correction.
  2. (b) The average may not be a whole number (e.g. 67.5), so it must be stored as REAL.
    1 mark.
Q18Finding and correcting errors in algorithms · Standard · Paper 2 style · 4 marks

01 DECLARE Age : STRING02 OUTPUT "Enter your age (16 to 60)"03 REPEAT04 INPUT Age05 IF Age < 16 AND Age > 60 THEN06 OUTPUT "Invalid age, try again"07 ENDIF08 NEXT09 OUTPUT "Age accepted"

  1. (a) The algorithm should keep asking for an age until a whole number from 16 to 60 inclusive is entered. Identify the three errors, giving the line number and the correction for each. [3]
  2. (b) Explain why the original line 05 would never output the message. [1]
Show answer
  1. (a) Line 01: DECLARE Age : INTEGERLine 05: IF Age < 16 OR Age > 60 THENLine 08: UNTIL Age >= 16 AND Age <= 60
    1 mark for each error identified with its correction.
  2. (b) No number can be both less than 16 and greater than 60 at the same time, so the AND condition is always FALSE.
    1 mark.
Q19Finding and correcting errors in algorithms · Standard · Paper 2 style · 5 marks

01 DECLARE Temps : ARRAY[1:20] OF REAL02 DECLARE Highest : REAL03 DECLARE Day : INTEGER04 DECLARE HotDay : INTEGER05 Highest ← 006 FOR Day ← 1 TO 1907 IF Temps[Day] < Highest THEN08 Highest ← Temps[Day]09 HotDay ← Highest10 ENDIF11 NEXT Day12 OUTPUT "Highest: ", Highest, " on day ", HotDay

  1. (a) The array Temps[1:20] already holds 20 winter temperatures recorded at a hill station, some of them below zero. The algorithm should output the highest temperature and the day on which it occurred. Identify the four errors, giving the line number and the correction for each. [4]
  2. (b) Explain why setting Highest to 0 could give a wrong result for this data. [1]
Show answer
  1. (a) Line 05: Highest ← Temps[1] (or a very low value such as -100)Line 06: FOR Day ← 1 TO 20Line 07: IF Temps[Day] > Highest THENLine 09: HotDay ← Day
    1 mark for each error identified with its correction.
  2. (b) If every temperature is below 0, none would be greater than 0, so Highest would stay 0, which is not one of the readings (and HotDay would never be set).
    1 mark.
Q20Finding and correcting errors in algorithms · Challenge · Paper 2 style · 6 marks

01 DECLARE Names : ARRAY[1:50] OF STRING02 DECLARE Target : STRING03 DECLARE Index : INTEGER04 DECLARE Found : BOOLEAN05 OUTPUT "Enter the name to find"06 INPUT Target07 Found ← TRUE08 Index ← 009 WHILE Index <= 50 OR Found = FALSE DO10 IF Names[Index] = Target THEN11 Found ← TRUE12 ELSE13 Index ← Index + 114 ENDIF15 ENDIF16 IF Found = TRUE THEN17 OUTPUT Target, " found at position ", Index18 ELSE19 OUTPUT Index, " not found"20 ENDIF

  1. (a) The array Names[1:50] already holds 50 student names. The algorithm should search for a name entered by the user and output its position, or a message if it is not found. Identify the five errors, giving the line number and the correction for each. [5]
  2. (b) State the name of this standard searching method. [1]
Show answer
  1. (a) Line 07: Found ← FALSELine 08: Index ← 1Line 09: WHILE Index <= 50 AND Found = FALSE DOLine 15: ENDWHILELine 19: OUTPUT Target, " not found"
    1 mark for each error identified with its correction.
  2. (b) Linear search
    1 mark.
Q21Standard methods (totalling, counting, max/min, linear search, bubble sort) · Core · Paper 2 style · 4 marks
  1. (a) Name the standard method shown in each pseudocode fragment.(i) Total ← Total + Price[Item](ii) IF Score[P] > 50 THEN Passes ← Passes + 1 ENDIF(iii) IF Height[K] > Tallest THEN Tallest ← Height[K] ENDIF(iv) IF Code[J] = SearchCode THEN Found ← TRUE ENDIF [4]
Show answer
  1. (a) (i) Totalling (ii) Counting (iii) Finding the maximum (iv) Linear search
    1 mark for each.
Q22Standard methods (totalling, counting, max/min, linear search, bubble sort) · Standard · Paper 2 style · 5 marks

The array List[1:10] holds 10 names.Last ← 9REPEAT Swap ← FALSE FOR J ← 1 TO Last IF List[J] > List[J + 1] THEN Temp ← List[J] List[J] ← List[J + 1] List[J + 1] ← Temp Swap ← TRUE ENDIF NEXT J Last ← Last - 1UNTIL Swap = FALSE OR Last = 0

  1. (a) State the purpose of the algorithm. [2]
  2. (b) Explain the purpose of the variable Swap in this algorithm. [2]
  3. (c) Explain why the value of Last is reduced by 1 after each pass. [1]
Show answer
  1. (a) It sorts the names in the array List into alphabetical (ascending) order, using a bubble sort.
    1 mark: sorts List. 1 mark: alphabetical/ascending order.
  2. (b) Swap is a flag set to TRUE whenever two names are exchanged during a pass; if a whole pass finishes with Swap still FALSE, the list is sorted, so the loop stops early instead of doing unnecessary passes.
    1 mark: records whether any swap happened in a pass. 1 mark: loop ends when a pass has no swaps / avoids unnecessary passes.
  3. (c) After each pass the largest remaining name is in its correct place at the end, so it does not need to be compared again.
    1 mark.
Q23Standard methods (totalling, counting, max/min, linear search, bubble sort) · Standard · Paper 2 style · 6 marks
  1. (a) The array Sales[1:30] holds the daily sales, in rupees, of a bakery in Lahore for one month. Write pseudocode to:- calculate the total sales for the month- count the number of days on which sales were more than 50000- output the total, the count and the average daily sales. [6]
Show answer
  1. (a) DECLARE Total : REALDECLARE Average : REALDECLARE BigDays : INTEGERDECLARE Day : INTEGERTotal ← 0BigDays ← 0FOR Day ← 1 TO 30 Total ← Total + Sales[Day] IF Sales[Day] > 50000 THEN BigDays ← BigDays + 1 ENDIFNEXT DayAverage ← Total / 30OUTPUT "Total sales: ", TotalOUTPUT "Days over 50000: ", BigDaysOUTPUT "Average daily sales: ", Average
    1 mark: initialise Total and counter to 0. 1 mark: loop for 30 days. 1 mark: totalling inside loop. 1 mark: correct condition > 50000 and count. 1 mark: average = Total / 30 calculated after the loop. 1 mark: all three values output with messages.
Q24Standard methods (totalling, counting, max/min, linear search, bubble sort) · Challenge · Paper 2 style · 6 marks
  1. (a) The array Cities[1:10] holds the names of 10 cities. Write pseudocode for an efficient bubble sort that puts the names into alphabetical order. The sort must stop as soon as a pass is completed with no swaps. [6]
Show answer
  1. (a) DECLARE Cities : ARRAY[1:10] OF STRINGDECLARE Temp : STRINGDECLARE Index, Top : INTEGERDECLARE Swapped : BOOLEANTop ← 9REPEAT Swapped ← FALSE FOR Index ← 1 TO Top IF Cities[Index] > Cities[Index + 1] THEN Temp ← Cities[Index] Cities[Index] ← Cities[Index + 1] Cities[Index + 1] ← Temp Swapped ← TRUE ENDIF NEXT Index Top ← Top - 1UNTIL Swapped = FALSE OR Top = 0
    1 mark: outer loop. 1 mark: inner loop over adjacent pairs without going past element 10. 1 mark: correct comparison of adjacent elements. 1 mark: swap using a temporary variable. 1 mark: flag set to FALSE at start of each pass and TRUE on a swap. 1 mark: outer loop ends when no swaps (accept also reducing the range each pass).
Q25Program development life cycle, decomposition and design methods · Core · Paper 2 style · 3 marks
  1. (a) State the four stages of the program development life cycle, in order. [2]
  2. (b) Give one task that is carried out during the analysis stage. [1]
Show answer
  1. (a) Analysis, design, coding, testing
    2 marks for all four in the correct order; 1 mark for all four in the wrong order or three in the correct order.
  2. (b) Any one, e.g. abstraction; decomposition of the problem; identifying the requirements of the system; identifying the inputs, processes, outputs and storage needed.
    1 mark.
Q26Program development life cycle, decomposition and design methods · Standard · Paper 2 style · 5 marks
  1. (a) A school canteen in Rawalpindi wants a program that lets students order lunch on a tablet. Decompose the system by identifying one input, one process, one output and one item of storage it needs. [4]
  2. (b) Name one design method that could show how the canteen system is broken down into sub-systems. [1]
Show answer
  1. (a) Input: e.g. student ID, choice of meal, quantity. Process: e.g. calculate the total cost, check the item is in stock, deduct from the student's balance. Output: e.g. order confirmation/receipt, total price, order sent to kitchen screen. Storage: e.g. menu and prices, student account balances, list of orders.
    1 mark for each component suitably applied to the canteen.
  2. (b) Structure diagram
    1 mark (accept flowchart/pseudocode only if linked to showing sub-systems – structure diagram is expected).
Q27Program development life cycle, decomposition and design methods · Challenge · Paper 2 style · 6 marks
  1. (a) A team is writing software for a parcel-delivery company. Explain why the team decomposes the problem into sub-systems before coding. [3]
  2. (b) The team uses a structure diagram, a flowchart and pseudocode during design. Describe what each of these shows. [3]
Show answer
  1. (a) Each sub-system is a smaller, simpler problem that is easier to understand and solve; different programmers can work on different sub-systems at the same time; each part can be tested separately, making errors easier to find; sub-programs/modules can be reused.
    1 mark each for any three points.
  2. (b) Structure diagram: the system broken down hierarchically into sub-systems and smaller modules. Flowchart: the steps of an algorithm and the order/flow between them using standard symbols and arrows. Pseudocode: the algorithm written in structured English-like statements, close to program code but not in a specific language.
    1 mark for each description.
Q28Test data · Core · Paper 2 style · 5 marks
  1. (a) A program for a minibus booking system accepts the number of passengers as a whole number from 1 to 18 inclusive. Give one example of each type of test data.(i) Normal data(ii) Extreme data(iii) Abnormal data [3]
  2. (b) Give the two boundary values tested at the upper end of the range. [2]
Show answer
  1. (a) (i) Any whole number from 2 to 17, e.g. 9. (ii) 1 or 18. (iii) Any value that should be rejected and is not next to a limit, e.g. 25, -3, 7.5, "ten".
    1 mark for each correct example. In (iii) do not credit 0 or 19, which are boundary data.
  2. (b) 18 (accepted) and 19 (rejected)
    1 mark for each value.
Q29Test data · Standard · Paper 2 style · 4 marks
  1. (a) A program checks that a new password is between 8 and 20 characters long, inclusive. Complete a test plan by giving, for each type of test data, an example password length and the expected result.(i) Normal(ii) Extreme(iii) Boundary (the rejected value at the lower end)(iv) Abnormal [4]
Show answer
  1. (a) (i) e.g. 12 characters – accepted. (ii) 8 or 20 characters – accepted. (iii) 7 characters – rejected. (iv) e.g. 0 characters (empty) or 25 characters – rejected.
    1 mark for each row with a suitable length and correct expected result.
Q30Test data · Challenge · Paper 2 style · 5 marks
  1. (a) A weather station program accepts temperatures from −10.0 °C to 45.0 °C inclusive, given to one decimal place. State the type of test data (normal, abnormal, extreme or boundary) for each value and whether it should be accepted or rejected.(i) 23.4(ii) −10.0(iii) 45.1(iv) hot [4]
  2. (b) Explain why boundary testing uses values on both sides of each limit. [1]
Show answer
  1. (a) (i) Normal – accepted. (ii) Extreme (accept boundary) – accepted. (iii) Boundary – rejected. (iv) Abnormal – rejected.
    1 mark for each row with type and outcome both correct.
  2. (b) To check that the condition uses the correct comparison (e.g. >= rather than >), so the largest/smallest accepted value is accepted and the next value outside the limit is rejected.
    1 mark.

Similar questions

Questions that test the same subtopic in different years, grouped so you can work on one skill at a time.

References only: find each question in its paper (official link where available, otherwise through your school).

Validation and verification Banker10 questions · 8/8 sessions
Trace tables Banker8 questions · 8/8 sessions
Writing, completing and explaining algorithms and flowcharts 9 questions · 6/8 sessions
Finding and correcting errors in algorithms Banker8 questions · 8/8 sessions
Standard methods (totalling, counting, max/min, linear search, bubble sort) Banker8 questions · 7/8 sessions
Program development life cycle, decomposition and design methods 9 questions · 5/8 sessions
Test data 5 questions · 5/8 sessions

Subtopics

Our analysis of how often each subtopic was examined and how many marks it carried, 2022 to May/June 2026.

SubtopicMarks indexedSessions
Validation and verification Banker498/8
Trace tables Banker438/8
Writing, completing and explaining algorithms and flowcharts 386/8
Finding and correcting errors in algorithms Banker338/8
Standard methods (totalling, counting, max/min, linear search, bubble sort) Banker337/8
Program development life cycle, decomposition and design methods 235/8
Test data 205/8

← All Computer Science topics