Cambridge IAS-Level · PastPaper.sampleTitle

MetadataPastPaper.sampleTitle

Thinka Nov 2025 (V3) Cambridge International A Level-Style Mock — Computer Science (9618)

150 PastPaper.marks210 PastPaper.minutes2025
An original Thinka practice paper modelled on the structure and difficulty of the Nov 2025 (V3) Cambridge International A Level Computer Science (9618) paper. Not affiliated with or reproduced from Cambridge.

Paper 1 (Theory Fundamentals)

Answer all questions. Calculators must not be used.
14 PastPaper.question · 57 PastPaper.marks
PastPaper.question 1 · Recall
4.5 PastPaper.marks
An 8-bit register stores signed integers using two's complement representation. Describe how arithmetic overflow can occur during the addition of two numbers in this register, and explain how the system detects this error. Provide a specific binary addition example that demonstrates overflow.
PastPaper.showAnswers

PastPaper.workedSolution

1. Overflow happens because the range of an 8-bit signed integer is restricted to \([-128, 127]\). If a calculation results in a value outside this interval, the hardware cannot represent it. 2. Detection occurs because adding two positive numbers yields a negative result, or adding two negative numbers yields a positive result. This can also be monitored by comparing the carry-in and carry-out of the most significant bit (MSB). 3. Example: 127 is 01111111 and 1 is 00000001. Adding them yields 10000000, which represents \(-128\) in two's complement.

PastPaper.markingScheme

1.5 marks for explaining the range limit of 8-bit signed two's complement and why overflow occurs. 1.5 marks for explaining the detection mechanism (opposite sign result or mismatched carry in/out). 1.5 marks for a correct binary addition example demonstrating overflow (inputs, working, and result with incorrect sign).
PastPaper.question 2 · Short Answer
4.5 PastPaper.marks
Describe the fundamental differences between client-side scripting and server-side scripting in web applications. Include one appropriate task that must be executed for each type of scripting.
PastPaper.showAnswers

PastPaper.workedSolution

1. Execution Location: Client-side scripting is executed by the browser engine (e.g., JavaScript) on the client machine, while server-side scripting is executed by the web server (e.g., PHP, Python) before sending the HTML page to the client. 2. Performance and Security: Client-side script execution reduces server load but is visible to users and less secure. Server-side script is hidden from the client, secure, and has direct access to database engines and file systems. 3. Client task: Form field validation or interactive animations. 4. Server task: Accessing database records, user login authentication, or generating dynamic session data.

PastPaper.markingScheme

1.5 marks for accurate distinction of execution locations (client browser vs web server). 1.5 marks for explaining the difference in access capabilities and security (visibility of source code and database connection privileges). 1.5 marks for providing one valid example task for each scripting type.
PastPaper.question 3 · Short Answer
4.5 PastPaper.marks
In the context of assembly language addressing modes, define 'immediate addressing' and 'direct addressing'. Explain why immediate addressing does not require an additional memory read cycle to fetch the data operand.
PastPaper.showAnswers

PastPaper.workedSolution

1. Immediate addressing: The operand is a constant value included directly in the instruction (e.g., ADD #5). 2. Direct addressing: The operand is an address specifying where the data is located in RAM (e.g., ADD 200). 3. Memory cycle explanation: During the fetch-decode-execute cycle, the instruction (including the immediate operand) is already loaded into the Instruction Register (IR). Since the operand is inside the instruction, no further memory access is needed. Direct addressing requires reading the address from the instruction first, then performing another memory read to get the actual value from that address.

PastPaper.markingScheme

1.5 marks for defining immediate addressing (operand is part of the instruction payload). 1.5 marks for defining direct addressing (instruction contains the memory address of the operand). 1.5 marks for explaining why immediate addressing bypasses the additional memory read cycle (operand is fetched during the instruction fetch phase).
PastPaper.question 4 · Recall
4.5 PastPaper.marks
Explain the purpose of a Data Dictionary in a Database Management System (DBMS). List three different types of metadata that are typically stored in a Data Dictionary.
PastPaper.showAnswers

PastPaper.workedSolution

The Data Dictionary serves as a guide or catalog to the database structure. It allows the DBMS to manage access control, enforce integrity constraints, and understand table structures. Metadata stored includes: 1. Schema metadata (table names, relationship constraints). 2. Field metadata (data types, default values, lengths). 3. Access permissions (user roles and privileges for each table).

PastPaper.markingScheme

1.5 marks for explaining the purpose of a Data Dictionary (centralized store of metadata, structure, and constraints used by DBMS to manage database integrity and access). 3 marks for listing three valid metadata items (1 mark for each item, such as table names, field data types, primary/foreign keys, or access privileges).
PastPaper.question 5 · Recall
4.5 PastPaper.marks
Distinguish between open-source software and proprietary (closed-source) software in terms of licensing and access to source code. State one benefit of using open-source software from a developer's perspective.
PastPaper.showAnswers

PastPaper.workedSolution

1. Source Code Access: Open-source provides full access to the source code; proprietary software only provides executable binaries with hidden source code. 2. Licensing: Open-source licenses allow modification and redistribution; proprietary licenses forbid copying, modifying, or redistributing the software. 3. Developer Benefit: Developers can modify the software to fix bugs directly, integrate it into their own projects without paying royalties, or leverage a community for support and collaboration.

PastPaper.markingScheme

1.5 marks for clear distinction on source code access (accessible vs compiled/hidden). 1.5 marks for clear distinction on licensing restrictions (free to modify/redistribute vs protected by copyright and restrictive EULAs). 1.5 marks for a valid benefit for developers (e.g., customization, learning opportunity, community collaboration, no license fees).
PastPaper.question 6 · Short Answer
4.5 PastPaper.marks
Describe the difference between validation and verification in the context of data entry. Provide one distinct example of a verification method and one distinct validation check.
PastPaper.showAnswers

PastPaper.workedSolution

1. Validation: Evaluates data against pre-defined rules (e.g., checking if a date is valid or a number is within range). It does not guarantee accuracy, only compliance with constraints. 2. Verification: Checks if data has been entered correctly from the source document (e.g., comparing user input with the source document). 3. Verification Method: Double data entry or visual check. 4. Validation Check: Range check, format check, length check, presence check, or type check.

PastPaper.markingScheme

1.5 marks for defining validation (automated checks for rules and compliance). 1.5 marks for defining verification (ensuring input matches original source). 0.75 marks for a valid validation check. 0.75 marks for a valid verification method.
PastPaper.question 7 · Short Answer
4.5 PastPaper.marks
In state transition diagrams, systems are represented by states, transitions, and events. Define these three terms in the context of a finite state machine (FSM) for a typical automated system, such as an elevator or a ticket barrier.
PastPaper.showAnswers

PastPaper.workedSolution

1. State: The status or mode of the system at a specific point in time, which determines how it responds to inputs. Example: 'Locked', 'Unlocked'. 2. Transition: The path or change from one state to another, which occurs under specific conditions. 3. Event: An input or trigger from the environment (e.g., button press, sensor input) that causes a transition to occur.

PastPaper.markingScheme

1.5 marks for defining State with a clear example. 1.5 marks for defining Transition as the path/movement between states. 1.5 marks for defining Event as the trigger with a clear example.
PastPaper.question 8 · Short Answer
4.5 PastPaper.marks
Explain the differences between passing a parameter 'by value' and 'by reference' to a subroutine. Describe how each method affects the value of the original variable in the calling program when the parameter is modified inside the subroutine.
PastPaper.showAnswers

PastPaper.workedSolution

1. By Value: A copy of the actual data is made and passed to the local parameter. Changes are local and discarded when the subroutine ends. The original variable remains unchanged. 2. By Reference: The address of the argument is passed. The subroutine accesses the original memory location. Changes are reflected in the original variable immediately. 3. Memory aspect: By value uses more memory for large structures (like arrays) as copies are made; by reference is faster and more memory-efficient as only a pointer is passed.

PastPaper.markingScheme

1.5 marks for explaining By Value and its impact (creates copy, original unchanged). 1.5 marks for explaining By Reference and its impact (passes memory address, original modified). 1.5 marks for comparative points regarding memory consumption, efficiency, or safety aspects.
PastPaper.question 9 · structured
2 PastPaper.marks
A home security system has three sensor inputs: \(A\) (system is armed), \(B\) (window sensor is triggered), and \(C\) (motion sensor is triggered). The alarm output \(X\) is activated (output value 1) only when the system is armed AND at least one of the sensors (window or motion) is triggered. Write the Boolean expression that represents this system.
PastPaper.showAnswers

PastPaper.workedSolution

1. Identify the logic operation for the sensors: 'at least one of the sensors (window or motion) is triggered' represents an OR gate. This is written as \((B + C)\) or \((B \text{ OR } C)\).
2. Identify the logic operation combining this with the armed state: 'system is armed AND at least one sensor triggered' represents an AND gate combining \(A\) with the result of the OR gate.
This is written as \(A \cdot (B + C)\) or \(A \text{ AND } (B \text{ OR } C)\).

PastPaper.markingScheme

1 mark for writing the correct OR operation: \((B + C)\) / \((B \text{ OR } C)\).
1 mark for writing the correct AND operation combining \(A\) with the rest of the expression: \(X = A \cdot (B + C)\) / \(X = A \text{ AND } (B \text{ OR } C)\).
Note: Accept alternative notations (e.g., boolean logic symbols or text representation).
PastPaper.question 10 · structured
2 PastPaper.marks
Simplify the following Boolean expression using Boolean algebra laws. Show your working.

\(X = A \cdot \overline{B} + A \cdot B\)
PastPaper.showAnswers

PastPaper.workedSolution

Step 1: Apply the distributive law to factor out \(A\):
\(X = A \cdot (\overline{B} + B)\)

Step 2: Apply the inverse/complement law, where \(\overline{B} + B = 1\):
\(X = A \cdot 1\)

Step 3: Apply the identity law, where \(A \cdot 1 = A\):
\(X = A\)

PastPaper.markingScheme

1 mark for showing the factorization step: \(X = A \cdot (\overline{B} + B)\).
1 mark for the correct final simplified expression: \(X = A\) (with working).
PastPaper.question 11 · short_answer
4.5 PastPaper.marks
A company database stores information about its staff and structure in two tables:

`tblEmployee(EmployeeID, FirstName, LastName, JobTitle, DepartmentID, Salary)`
`tblDepartment(DepartmentID, DepartmentName, Location)`

Write an SQL query to display the `FirstName`, `LastName`, and `DepartmentName` of all employees who work in the department located in 'Chicago' and earn a `Salary` of more than 55000.
PastPaper.showAnswers

PastPaper.workedSolution

To retrieve the requested fields, we write an SQL query:
1. Specify the fields to retrieve: `SELECT FirstName, LastName, DepartmentName`
2. Specify the source tables and join them using their common field (`DepartmentID`): `FROM tblEmployee INNER JOIN tblDepartment ON tblEmployee.DepartmentID = tblDepartment.DepartmentID`
3. Filter the records using the conditions for Location and Salary: `WHERE Location = 'Chicago' AND Salary > 55000`

PastPaper.markingScheme

- 1 mark: `SELECT FirstName, LastName, DepartmentName` (Must have all three fields, no extras).
- 1 mark: Joining both tables using `FROM tblEmployee INNER JOIN tblDepartment` (or equivalent implicit join `FROM tblEmployee, tblDepartment`).
- 1 mark: Correct join condition `ON tblEmployee.DepartmentID = tblDepartment.DepartmentID` (or equivalent `WHERE` clause constraint).
- 1 mark: Filter for location: `Location = 'Chicago'`.
- 0.5 marks: Filter for salary: `Salary > 55000` connected with `AND`.
PastPaper.question 12 · short_answer
4.5 PastPaper.marks
A car rental company needs to create a table to store data about its fleet.

Write a database definition SQL statement (DDL) to create a table named `tblVehicle` with the following requirements:
- `VehicleID`: a fixed-length alphanumeric code of exactly 7 characters, which serves as the primary key.
- `Make`: a variable-length text field (up to 30 characters) that must always have a value provided.
- `DateRegistered`: a field storing the date the vehicle was officially registered.
- `DailyRate`: a decimal field representing the daily cost to rent, with up to 3 digits before the decimal point and exactly 2 decimal places (e.g. 999.99).
PastPaper.showAnswers

PastPaper.workedSolution

To define the table using SQL DDL:
1. Start with `CREATE TABLE tblVehicle (`
2. Define `VehicleID` using `CHAR(7)` because it is a fixed length of 7 characters, and mark it as the `PRIMARY KEY`.
3. Define `Make` using `VARCHAR(30)` to accommodate variable-length text up to 30 characters, and add `NOT NULL` to ensure it is never empty.
4. Define `DateRegistered` using the `DATE` data type.
5. Define `DailyRate` using `DECIMAL(5,2)` or `NUMERIC(5,2)` (5 total digits, with 2 after the decimal point allowing up to 999.99).
6. Close with `);`

PastPaper.markingScheme

- 1 mark: Correct structure `CREATE TABLE tblVehicle ( ... );`.
- 1 mark: `VehicleID CHAR(7) PRIMARY KEY` (Accept `VARCHAR(7)` as an alternative, but must declare it as PRIMARY KEY).
- 1 mark: `Make VARCHAR(30) NOT NULL` (Must include NOT NULL constraint).
- 1 mark: `DateRegistered DATE` and `DailyRate DECIMAL(5,2)` (Accept `NUMERIC(5,2)`).
- 0.5 marks: Correct syntax throughout including commas separating field definitions.
PastPaper.question 13 · Trace & Explanation
4 PastPaper.marks
An assembly language program is executed with the following initial states:
- The Accumulator (ACC) contains 0.
- The Index Register (IX) contains 1.
- Memory address 200 contains the decimal value 12.
- Memory address 201 contains the decimal value 4.
- Memory address 202 contains the decimal value 0.

Trace the execution of the following assembly code segment:

```assembly
LDD 200
SUB 201
STO 202
LDX 200
ADD 202
CMP 200
```

Show the changes to the Accumulator (ACC), memory location 202, and explain the state of the comparison flag after the final instruction executes.
PastPaper.showAnswers

PastPaper.workedSolution

Let's trace the instructions step-by-step:

1. `LDD 200`: Loads the value from memory address 200 directly into the Accumulator. ACC becomes **12**.
2. `SUB 201`: Subtracts the value in address 201 (4) from the Accumulator. ACC becomes \(12 - 4 = 8\).
3. `STO 202`: Stores the contents of the Accumulator into memory address 202. Memory address 202 now contains **8**.
4. `LDX 200`: Loads a value into the Accumulator using indexed addressing. The address is calculated as \(200 + \text{IX} = 200 + 1 = 201\). The value at memory address 201 is 4, so ACC becomes **4**.
5. `ADD 202`: Adds the value at address 202 (8) to the Accumulator. ACC becomes \(4 + 8 = 12\).
6. `CMP 200`: Compares the value in the Accumulator (12) with the value at memory address 200 (12). Since they are equal, the Comparison Flag is set to **Equal** (or **True**).

PastPaper.markingScheme

Marks are awarded as follows:
- **1 Mark**: Correctly tracing ACC value changes up to instruction 3 (ACC transitions from 12 to 8) AND memory location 202 updated to 8.
- **1 Mark**: Correctly demonstrating indexed addressing on `LDX 200` to load the value 4 into ACC (recognizing that address \(200 + 1 = 201\) is used).
- **1 Mark**: Correctly showing ACC updated to 12 after the `ADD 202` instruction.
- **1 Mark**: Correctly identifying that the Comparison Flag is set to Equal (True) with an explanation that the final ACC value (12) matches the value stored at address 200 (12).
PastPaper.question 14 · Trace & Explanation
4 PastPaper.marks
Consider the following pseudocode algorithm:

```pseudocode
FUNCTION ProcessString(InputStr : STRING) RETURNS STRING
DECLARE ResultStr : STRING
DECLARE i, Length : INTEGER
DECLARE Char : CHAR

ResultStr <- ""
Length <- LENGTH(InputStr)

FOR i <- 1 TO Length
Char <- MID(InputStr, i, 1)
IF Char >= "A" AND Char <= "Z" THEN
ResultStr <- ResultStr & LCASE(Char)
ELSE
ResultStr <- LCASE(Char) & ResultStr
ENDIF
NEXT i
RETURN ResultStr
ENDFUNCTION
```

Trace the execution of this function when called with `ProcessString("PaS")` by tracing the values of the variables `i`, `Char`, and `ResultStr` for each iteration of the loop, and state the final returned value.
PastPaper.showAnswers

PastPaper.workedSolution

Let's perform the trace step-by-step for `InputStr = "PaS"` (Length = 3):

- **Initial State**:
`ResultStr` is initialized to `""`.

- **Iteration 1 (i = 1)**:
- `Char` is set to `"P"` (the 1st character of "PaS").
- Condition check: `"P"` is uppercase (between "A" and "Z"), so the `THEN` block executes.
- `ResultStr <- ResultStr & LCASE("P")` which translates to `"" & "p"` = `"p"`.

- **Iteration 2 (i = 2)**:
- `Char` is set to `"a"` (the 2nd character of "PaS").
- Condition check: `"a"` is lowercase, so the `ELSE` block executes.
- `ResultStr <- LCASE("a") & ResultStr` which translates to `"a" & "p"` = `"ap"`.

- **Iteration 3 (i = 3)**:
- `Char` is set to `"S"` (the 3rd character of "PaS").
- Condition check: `"S"` is uppercase, so the `THEN` block executes.
- `ResultStr <- ResultStr & LCASE("S")` which translates to `"ap" & "s"` = `"aps"`.

- **Output**:
The loop terminates. The function returns `"aps"`.

PastPaper.markingScheme

Marks are awarded as follows:
- **1 Mark**: Correct values for `i`, `Char`, and `ResultStr` in the first iteration (`i = 1`, `Char = "P"`, `ResultStr = "p"`).
- **1 Mark**: Correct values for `i`, `Char`, and `ResultStr` in the second iteration (`i = 2`, `Char = "a"`, `ResultStr = "ap"`).
- **1 Mark**: Correct values for `i`, `Char`, and `ResultStr` in the third iteration (`i = 3`, `Char = "S"`, `ResultStr = "aps"`).
- **1 Mark**: Correctly stating the final returned string `"aps"` and explaining that lowercase input characters are prepended to the start of the result while uppercase input characters are converted to lowercase and appended to the end.

Paper 2 (Fundamental Problem-solving)

Answer all questions. Refer to the insert for standard pseudocode functions.
12 PastPaper.question · 61 PastPaper.marks
PastPaper.question 1 · Theoretical Application
3.5 PastPaper.marks
Consider the following pseudocode algorithm:

PROCEDURE Modify(BYREF a : INTEGER, BYVAL b : INTEGER)
a <- a * 2
b <- b + a
a <- b - 3
ENDPROCEDURE

// Main program
DECLARE X : INTEGER
DECLARE Y : INTEGER
X <- 4
Y <- 6
Modify(X, Y)

Explain the final values of variables X and Y after the execution of the main program, demonstrating your understanding of parameter passing methods.
PastPaper.showAnswers

PastPaper.workedSolution

Initial values before procedure call: X = 4, Y = 6.
When Modify(X, Y) is executed:
1. The parameter 'a' points to the same memory location as 'X' (BYREF).
2. The parameter 'b' is allocated a separate memory location containing a copy of 'Y''s value, which is 6 (BYVAL).

Trace inside the procedure:
1. a <- a * 2: Since 'a' references 'X', X is updated to 4 * 2 = 8.
2. b <- b + a: 'b' is updated to 6 + 8 = 14.
3. a <- b - 3: Since 'a' references 'X', X is updated to 14 - 3 = 11.

After the procedure completes, the local variable 'b' is discarded. The value of 'Y' remains unchanged. Hence, X = 11 and Y = 6.

PastPaper.markingScheme

1.0 Mark: Correct final value of X is 11.
1.0 Mark: Correct final value of Y is 6.
1.0 Mark: Accurate explanation of BYREF (changes to parameter 'a' affect the original variable 'X' because they share the same memory location).
0.5 Marks: Accurate explanation of BYVAL (changes to parameter 'b' do not affect 'Y' because a local copy of the value is created).
PastPaper.question 2 · Theoretical Application
3.5 PastPaper.marks
A binary search algorithm is used to find the value 30 in a sorted 1D array of integers named 'DataList' with indices 1 to 7 containing: [3, 8, 12, 15, 22, 30, 40].

The algorithm uses the variables 'Low' (initialized to 1) and 'High' (initialized to 7). During each iteration of the loop, the midpoint is calculated using: Mid <- (Low + High) DIV 2.

Describe the values of 'Low', 'High', and 'Mid' at each iteration of the loop, and state whether the search succeeds.
PastPaper.showAnswers

PastPaper.workedSolution

1. Initial state: Low = 1, High = 7.
2. Iteration 1:
- Mid is calculated as (1 + 7) DIV 2 = 4.
- DataList[4] is checked, which contains 15.
- Since 15 is less than the target value 30, the search range shifts to the upper half. Low is updated to Mid + 1, which is 5.
3. Iteration 2:
- Mid is calculated as (5 + 7) DIV 2 = 6.
- DataList[6] is checked, which contains 30.
- Since 30 is equal to the target value, the search succeeds and the loop terminates.

PastPaper.markingScheme

1.5 Marks: Correct trace of Iteration 1 (identifying Mid = 4, evaluating DataList[4] = 15, and correctly updating Low to 5).
1.5 Marks: Correct trace of Iteration 2 (identifying Mid = 6, evaluating DataList[6] = 30).
0.5 Marks: Explicitly stating that the target is found at index 6 and the search successfully terminates.
PastPaper.question 3 · Theoretical Application
3.5 PastPaper.marks
A computer science program uses a 2D array named 'StudentGrades' declared as:
DECLARE StudentGrades : ARRAY[1..30, 1..5] OF INTEGER

This array stores scores for 30 students across 5 different assignments.

(a) State the total number of storage locations allocated for this array.
(b) Write a single pseudocode statement to assign the grade of the 12th student's 4th assignment to a variable named 'TargetGrade'.
PastPaper.showAnswers

PastPaper.workedSolution

(a) The array size is determined by multiplying the number of rows by the number of columns: 30 rows * 5 columns = 150 storage locations.
(b) To access a specific cell in a 2D array, the correct indices must be supplied in row-column order. The 12th student corresponds to the row index 12, and the 4th assignment corresponds to the column index 4. The assignment statement in pseudocode is: TargetGrade <- StudentGrades[12, 4].

PastPaper.markingScheme

1.0 Mark: Correct calculation of total storage locations (150).
1.5 Marks: Correct pseudocode statement 'TargetGrade <- StudentGrades[12, 4]' (Award 0.75 marks for left-hand side and assignment operator '<-', and 0.75 marks for the correct array indexing syntax '[12, 4]').
1.0 Mark: Correctly identifying the structure of the indices (row index 12 represents the student, and column index 4 represents the assignment).
PastPaper.question 4 · Theoretical Application
3.5 PastPaper.marks
An algorithm validates a user's age input. The input must be an integer between 18 and 65 inclusive.

Define 'Normal test data', 'Boundary (Extreme) test data', and 'Invalid test data' in this context, and provide one specific integer example for each type.
PastPaper.showAnswers

PastPaper.workedSolution

1. Normal test data: Data that is valid and expected, falling well within the defined boundaries. Example: 25 (any integer between 19 and 64 is acceptable).
2. Boundary / Extreme test data: Data that is on the absolute limits of acceptability, which should still be accepted. Examples: 18 or 65.
3. Invalid test data: Data that is outside the acceptable range and should be rejected by the validation rules. Examples: 17, 66 (or negative integers).

PastPaper.markingScheme

1.0 Mark: Correct definition and integer example of Normal test data (e.g., any integer from 19 to 64).
1.0 Mark: Correct definition and integer example of Boundary test data (must use exactly 18 or 65).
1.0 Mark: Correct definition and integer example of Invalid test data (must use values < 18 or > 65).
0.5 Marks: Explicitly demonstrating the distinction between valid data that is accepted (Normal and Boundary) and invalid data that is rejected.
PastPaper.question 5 · Trace & Verification
5 PastPaper.marks
An algorithm is designed to compress a string by counting adjacent identical characters.

The function `Compress` is defined as follows:

```pseudocode
FUNCTION Compress(Word : STRING) RETURNS STRING
DECLARE OutStr : STRING
DECLARE Count : INTEGER
DECLARE i : INTEGER

OutStr <-- ""
Count <-- 1
i <-- 1
WHILE i < LENGTH(Word)
IF SUBSTRING(Word, i, 1) = SUBSTRING(Word, i + 1, 1) THEN
Count <-- Count + 1
ELSE
IF Count > 1 THEN
OutStr <-- OutStr + NUM_TO_STR(Count) + SUBSTRING(Word, i, 1)
ELSE
OutStr <-- OutStr + SUBSTRING(Word, i, 1)
ENDIF
Count <-- 1
ENDIF
i <-- i + 1
ENDWHILE

IF Count > 1 THEN
OutStr <-- OutStr + NUM_TO_STR(Count) + SUBSTRING(Word, i, 1)
ELSE
OutStr <-- OutStr + SUBSTRING(Word, i, 1)
ENDIF

RETURN OutStr
ENDFUNCTION
```

Complete the trace table below for the function call `Compress("BBAADDD")`. Write a new line in the trace table only when the variable `i` changes its value.

| `i` | `Count` | `SUBSTRING(Word, i, 1) = SUBSTRING(Word, i + 1, 1)` | `OutStr` |
|---|---|---|---|
| (initial) | 1 | | "" |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
PastPaper.showAnswers

PastPaper.workedSolution

Let's trace the function execution with `Word = "BBAADDD"`:
- Initial state: `OutStr` is `""`, `Count` is `1`.
- **`i = 1`**: `SUBSTRING(Word, 1, 1)` is 'B' and `SUBSTRING(Word, 2, 1)` is 'B'. They are equal, so comparison is `TRUE`. `Count` becomes `2`. `i` becomes `2`.
- **`i = 2`**: `SUBSTRING(Word, 2, 1)` is 'B' and `SUBSTRING(Word, 3, 1)` is 'A'. Not equal, comparison is `FALSE`. `Count` is `2` (> 1), so `OutStr` becomes `"2B"`. `Count` reset to `1`. `i` becomes `3`.
- **`i = 3`**: 'A' = 'A' -> `TRUE`. `Count` becomes `2`. `i` becomes `4`.
- **`i = 4`**: 'A' = 'D' -> `FALSE`. `Count` is `2` (> 1), so `OutStr` becomes `"2B2A"`. `Count` reset to `1`. `i` becomes `5`.
- **`i = 5`**: 'D' = 'D' -> `TRUE`. `Count` becomes `2`. `i` becomes `6`.
- **`i = 6`**: 'D' = 'D' -> `TRUE`. `Count` becomes `3`. `i` becomes `7`.
- Loop terminates as `i < LENGTH(Word)` (7 < 7) is `FALSE`.
- After loop: `Count` is `3` (> 1), so `OutStr` becomes `"2B2A" + "3" + "D" = "2B2A3D"`.

### Completed Trace Table

| `i` | `Count` | `SUBSTRING(Word, i, 1) = SUBSTRING(Word, i + 1, 1)` | `OutStr` |
|---|---|---|---|
| (initial) | 1 | | "" |
| 1 | 2 | TRUE | |
| 2 | 1 | FALSE | "2B" |
| 3 | 2 | TRUE | |
| 4 | 1 | FALSE | "2B2A" |
| 5 | 2 | TRUE | |
| 6 | 3 | TRUE | |
| 7 | | | "2B2A3D" |

PastPaper.markingScheme

- 1 mark for correct initialization and row 1 (`i = 1`, `Count = 2`, comparison `TRUE`).
- 1 mark for row 2 (`i = 2`, `Count = 1`, comparison `FALSE`, `OutStr = "2B"`).
- 1 mark for rows 3 & 4 (correct transitions for index 3 and 4, updating `OutStr` to `"2B2A"`).
- 1 mark for rows 5 & 6 (correct transitions for index 5 and 6, showing `Count` reaching 3).
- 1 mark for final row outside loop (`i = 7` with final `OutStr = "2B2A3D"`).
PastPaper.question 6 · Trace & Verification
5 PastPaper.marks
A programmer is designing a subprogram to filter an array of integers by removing values that exceed a specified threshold. The remaining values are shifted to the front of the array, and any remaining trailing positions are filled with `-1`.

The procedure `CleanArray` is defined as follows:

```pseudocode
PROCEDURE CleanArray(BYREF Values : ARRAY OF INTEGER, Limit : INTEGER)
DECLARE ReadPos : INTEGER
DECLARE WritePos : INTEGER
DECLARE Size : INTEGER

Size <-- 6
WritePos <-- 1
FOR ReadPos <-- 1 TO Size
IF Values[ReadPos] <= Limit THEN
Values[WritePos] <-- Values[ReadPos]
WritePos <-- WritePos + 1
ENDIF
NEXT ReadPos

WHILE WritePos <= Size
Values[WritePos] <-- -1
WritePos <-- WritePos + 1
ENDWHILE
ENDPROCEDURE
```

Trace the execution of `CleanArray(Values, 10)` where the initial state of the 1-indexed array is:
`Values = [12, 5, 18, 9, 22, 4]`

Complete the trace table below. You should only write values in cells when their values change.

| `ReadPos` | `WritePos` | `Values[ReadPos] <= Limit` | `Values[1]` | `Values[2]` | `Values[3]` | `Values[4]` | `Values[5]` | `Values[6]` |
|---|---|---|---|---|---|---|---|---|
| (initial) | 1 | | 12 | 5 | 18 | 9 | 22 | 4 |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
PastPaper.showAnswers

PastPaper.workedSolution

Let's perform the dry run step-by-step:
- Initial: `WritePos = 1`, `Values = [12, 5, 18, 9, 22, 4]`
- **`ReadPos = 1`**: `Values[1] = 12`. `12 <= 10` is `FALSE`. No change.
- **`ReadPos = 2`**: `Values[2] = 5`. `5 <= 10` is `TRUE`. `Values[WritePos]` (which is `Values[1]`) becomes `5`. `WritePos` incremented to `2`.
- **`ReadPos = 3`**: `Values[3] = 18`. `18 <= 10` is `FALSE`. No change.
- **`ReadPos = 4`**: `Values[4] = 9`. `9 <= 10` is `TRUE`. `Values[WritePos]` (which is `Values[2]`) becomes `9`. `WritePos` incremented to `3`.
- **`ReadPos = 5`**: `Values[5] = 22`. `22 <= 10` is `FALSE`. No change.
- **`ReadPos = 6`**: `Values[6] = 4`. `4 <= 10` is `TRUE`. `Values[WritePos]` (which is `Values[3]`) becomes `4`. `WritePos` incremented to `4`.
- Loop `FOR` ends.
- **`WHILE` loop begins** with `WritePos = 4`:
- Iteration 1: `WritePos = 4 <= 6`. `Values[4]` becomes `-1`. `WritePos` becomes `5`.
- Iteration 2: `WritePos = 5 <= 6`. `Values[5]` becomes `-1`. `WritePos` becomes `6`.
- Iteration 3: `WritePos = 6 <= 6`. `Values[6]` becomes `-1`. `WritePos` becomes `7`.
- Loop terminates because `WritePos = 7` is greater than `Size` (6).

### Completed Trace Table

| `ReadPos` | `WritePos` | `Values[ReadPos] <= Limit` | `Values[1]` | `Values[2]` | `Values[3]` | `Values[4]` | `Values[5]` | `Values[6]` |
|---|---|---|---|---|---|---|---|---|
| (initial) | 1 | | 12 | 5 | 18 | 9 | 22 | 4 |
| 1 | | FALSE | | | | | | |
| 2 | 2 | TRUE | 5 | | | | | |
| 3 | | FALSE | | | | | | |
| 4 | 3 | TRUE | | 9 | | | | |
| 5 | | FALSE | | | | | | |
| 6 | 4 | TRUE | | | 4 | | | |
| | 5 | | | | | -1 | | |
| | 6 | | | | | | -1 | |
| | 7 | | | | | | | -1 |

PastPaper.markingScheme

- 1 mark for correct trace of `ReadPos = 1` and `ReadPos = 2` (showing condition is `TRUE`, `Values[1]` changes to `5`, and `WritePos` changes to `2`).
- 1 mark for correct trace of `ReadPos = 3` and `ReadPos = 4` (showing condition is `TRUE`, `Values[2]` changes to `9`, and `WritePos` changes to `3`).
- 1 mark for correct trace of `ReadPos = 5` and `ReadPos = 6` (showing condition is `TRUE`, `Values[3]` changes to `4`, and `WritePos` changes to `4`).
- 1 mark for correctly tracing the `WHILE` loop overwriting `Values[4]`, `Values[5]`, and `Values[6]` to `-1`.
- 1 mark for tracing `WritePos` incrementing correctly step-by-step up to its final value of `7`.
PastPaper.question 7 · Algorithm & Design (Structure Chart/Diagrams)
4.5 PastPaper.marks
In software design, structure charts are used to show the decomposition of a system into sub-modules and the flow of data between them.

Consider a module ManageInventory that calls two sub-modules: CheckStock and ReorderItem.

- ManageInventory passes ItemID to CheckStock.
- CheckStock returns a boolean flag LowStock to ManageInventory.
- If LowStock is True, ManageInventory calls ReorderItem.

Describe how the following elements of this design are represented in a standard structure chart:

1. The parameter ItemID passed from ManageInventory to CheckStock.
2. The parameter LowStock passed from CheckStock to ManageInventory.
3. The conditional execution of ReorderItem.
PastPaper.showAnswers

PastPaper.workedSolution

1. ItemID representation:
- Direction: An arrow pointing downwards from the calling module (ManageInventory) to the called module (CheckStock).
- Circle style: An open (unfilled/empty) circle at the end/tail of the arrow.
- Name: Data couple.

2. LowStock representation:
- Direction: An arrow pointing upwards from the called module (CheckStock) to the calling module (ManageInventory).
- Circle style: A filled (solid black) circle at the end/tail of the arrow.
- Name: Control couple (or flag).

3. Conditional execution representation:
- Symbol: A small diamond is placed at the intersection point/root of the module lines beneath ManageInventory, indicating that the call to ReorderItem is decided by a conditional statement (selection).

PastPaper.markingScheme

Total Marks: 4.5

- Part 1 (ItemID representation): 1.5 Marks
* 0.5 marks for identifying the arrow direction (from ManageInventory to CheckStock).
* 0.5 marks for specifying the open/unfilled circle.
* 0.5 marks for correctly naming it a 'data couple'.

- Part 2 (LowStock representation): 1.5 Marks
* 0.5 marks for identifying the arrow direction (from CheckStock to ManageInventory).
* 0.5 marks for specifying the filled/solid circle.
* 0.5 marks for correctly naming it a 'control couple' or 'flag'.

- Part 3 (Conditional execution): 1.5 Marks
* 1.0 mark for correctly identifying the 'diamond' symbol.
* 0.5 marks for explaining its location on the junction line indicating selection/conditional calling.
PastPaper.question 8 · Algorithm & Design (Structure Chart/Diagrams)
4.5 PastPaper.marks
A software developer designs a program using a structure chart. The module CalculateSalary is a higher-level module that calls two sub-modules: GetHoursWorked and ApplyTaxRate.

- A curved arrow is drawn across the lines connecting CalculateSalary to both sub-modules.
- CalculateSalary receives HoursWorked (an integer) from GetHoursWorked.
- CalculateSalary passes GrossPay (a real number) to ApplyTaxRate and receives back a boolean flag TaxExempt.

Explain how the following aspects of this structure chart represent the design:

1. The significance and appearance of the curved arrow.
2. The difference in representation (arrows and circles) between GrossPay and TaxExempt.
3. The directional hierarchy of the modules (identifying the calling and called modules).
PastPaper.showAnswers

PastPaper.workedSolution

1. Curved Arrow:
- Significance: Indicates iteration/repetition. It means that the calls to GetHoursWorked and ApplyTaxRate are executed repeatedly inside a loop within CalculateSalary.
- Appearance: A curved line with an arrowhead spanning across the vertical connection lines leading to the sub-modules.

2. GrossPay vs. TaxExempt:
- GrossPay: Represented by a straight arrow pointing down (from parent to child) with an open (unfilled) circle. This represents a data couple (passing actual data to be processed).
- TaxExempt: Represented by a straight arrow pointing up (from child to parent) with a filled (solid black) circle. This represents a control couple or flag (passing state or status information).

3. Directional Hierarchy:
- CalculateSalary is the parent module situated at the top of the connection lines, making it the calling module.
- GetHoursWorked and ApplyTaxRate are child modules situated below, meaning they are the called modules (subroutines).

PastPaper.markingScheme

Total Marks: 4.5

- Part 1 (Curved arrow): 1.5 Marks
* 1.0 mark for identifying that it represents iteration / repetition / a loop.
* 0.5 marks for stating it is drawn across/looping over the connection lines.

- Part 2 (GrossPay vs TaxExempt): 2.0 Marks
* 1.0 mark for describing GrossPay: data couple, arrow pointing down, open/unfilled circle.
* 1.0 mark for describing TaxExempt: control couple / flag, arrow pointing up, filled/solid circle.

- Part 3 (Hierarchy): 1.0 Mark
* 0.5 marks for identifying CalculateSalary as the calling (parent) module.
* 0.5 marks for identifying the sub-modules as the called (child) modules.
PastPaper.question 9 · Pseudocode Program Construction
7 PastPaper.marks
An array `ScoreList` contains `NumItems` integer exam scores. Write a pseudocode function `FilterScores` that takes three parameters:
1. The array `ScoreList` (indexed from 1 to 100)
2. The actual number of active scores in the array `NumItems`
3. An integer `Threshold`

The function must calculate and return the average (as a real number) of all scores that are strictly greater than the `Threshold`. If no scores in the array exceed the threshold, the function must return -1.0.
PastPaper.showAnswers

PastPaper.workedSolution

```
FUNCTION FilterScores(ScoreList : ARRAY OF INTEGER, NumItems : INTEGER, Threshold : INTEGER) RETURNS REAL
DECLARE Sum : INTEGER
DECLARE Count : INTEGER
DECLARE Index : INTEGER
Sum <- 0
Count <- 0
FOR Index <- 1 TO NumItems
IF ScoreList[Index] > Threshold THEN
Sum <- Sum + ScoreList[Index]
Count <- Count + 1
ENDIF
ENDFOR
IF Count > 0 THEN
RETURN Sum / Count
ELSE
RETURN -1.0
ENDIF
ENDFUNCTION
```

PastPaper.markingScheme

1 Mark: Correct function header with all parameters and return type (`RETURNS REAL`).
1 Mark: Declaring and initializing accumulation variables (`Sum` and `Count`) to 0.
1 Mark: Correct loop from 1 to `NumItems` to traverse array.
1 Mark: Correct comparison check (`ScoreList[Index] > Threshold`).
1 Mark: Accumulating sum and incrementing count within the `IF` scope.
1 Mark: Checking `Count > 0` before division to prevent division-by-zero errors.
1 Mark: Returning the calculated average when valid, or returning `-1.0` when no items met the criteria, with matching `ENDFUNCTION`.
PastPaper.question 10 · Pseudocode Program Construction
7 PastPaper.marks
Write a pseudocode procedure `ExtractDomain` that accepts an email address as a string parameter. The procedure must locate the '@' character. If the string contains exactly one '@' character (and it is not at the very start or the very end of the string), the procedure must output the domain part of the email address (everything after the '@' character). Otherwise, the procedure must output 'INVALID'.

You should assume standard pseudocode string functions are available:
- `LENGTH(String : STRING) RETURNS INTEGER`
- `MID(String : STRING, Start : INTEGER, Length : INTEGER) RETURNS STRING`
PastPaper.showAnswers

PastPaper.workedSolution

```
PROCEDURE ExtractDomain(Email : STRING)
DECLARE Length : INTEGER
DECLARE Index : INTEGER
DECLARE AtCount : INTEGER
DECLARE AtPos : INTEGER
Length <- LENGTH(Email)
AtCount <- 0
AtPos <- 0
FOR Index <- 1 TO Length
IF MID(Email, Index, 1) = "@" THEN
AtCount <- AtCount + 1
AtPos <- Index
ENDIF
ENDFOR
IF AtCount = 1 AND AtPos > 1 AND AtPos < Length THEN
OUTPUT MID(Email, AtPos + 1, Length - AtPos)
ELSE
OUTPUT "INVALID"
ENDIF
ENDPROCEDURE
```

PastPaper.markingScheme

1 Mark: Correct procedure header taking a string parameter.
1 Mark: Initializing counting variables (`AtCount` to 0) and declaring necessary trackers.
1 Mark: Loop through the length of the string from 1 to `LENGTH(Email)`.
1 Mark: Isolating each character using `MID(Email, Index, 1)` and comparing to "@".
1 Mark: Tracking total count of '@' characters and storing the position of the '@'.
1 Mark: Checking that `AtCount = 1` and validation of location (not index 1 and not last character).
1 Mark: Correctly outputting the substring using `MID` for domain extract, and outputting 'INVALID' on fail.
PastPaper.question 11 · Pseudocode Program Construction
7 PastPaper.marks
A text file named `Inventory.txt` contains product stock data. Each line of the file is formatted as a product code (a string) and an integer stock level, separated by a comma (e.g., `"PROD01,45"`).

Write a pseudocode procedure `SearchProduct` that takes a single string parameter `SearchID`. The procedure must open the file, search for a line with a matching product code, and output the associated stock level as a string. If the end of the file is reached and no match is found, it must output `"Not Found"`. The file must be closed before the procedure ends.

You should use standard pseudocode file handling operations:
- `OPENFILE FOR READ`
- `READFILE , `
- `CLOSEFILE `
- `EOF()`
PastPaper.showAnswers

PastPaper.workedSolution

```
PROCEDURE SearchProduct(SearchID : STRING)
DECLARE Line : STRING
DECLARE FileID : STRING
DECLARE CommaPos : INTEGER
DECLARE Found : BOOLEAN
Found <- FALSE
OPENFILE "Inventory.txt" FOR READ
WHILE NOT EOF("Inventory.txt") AND Found = FALSE
READFILE "Inventory.txt", Line
FOR CommaPos <- 1 TO LENGTH(Line)
IF MID(Line, CommaPos, 1) = "," THEN
FileID <- MID(Line, 1, CommaPos - 1)
IF FileID = SearchID THEN
OUTPUT MID(Line, CommaPos + 1, LENGTH(Line) - CommaPos)
Found <- TRUE
ENDIF
ENDIF
ENDFOR
ENDWHILE
CLOSEFILE "Inventory.txt"
IF Found = FALSE THEN
OUTPUT "Not Found"
ENDIF
ENDPROCEDURE
```

PastPaper.markingScheme

1 Mark: Opening 'Inventory.txt' for READ and ensuring CLOSEFILE is present at the end.
1 Mark: Initialising a boolean variable `Found` to FALSE.
1 Mark: Using a loop controlled by both `NOT EOF("Inventory.txt")` and `Found = FALSE`.
1 Mark: Correctly calling `READFILE "Inventory.txt", Line` inside the loop.
1 Mark: Using a nested loop or find function to isolate the position of the comma.
1 Mark: Correctly splitting and extracting the product code, checking if it matches `SearchID`.
1 Mark: Extracting and outputting the stock level portion of the string and outputting 'Not Found' if not found.
PastPaper.question 12 · Pseudocode Program Construction
7 PastPaper.marks
Write a pseudocode procedure `SortNames` to perform an optimized bubble sort on a 1D array. The procedure takes two parameters:
1. `Names` - an array of strings containing names to be sorted in ascending alphabetical order. This array must be passed by reference so that changes are reflected in the calling program.
2. `N` - the number of elements in the array to sort, passed by value.

Your solution must be optimized so that the algorithm terminates early if a complete pass is made through the array without any elements being swapped.
PastPaper.showAnswers

PastPaper.workedSolution

```
PROCEDURE SortNames(BYREF Names : ARRAY OF STRING, N : INTEGER)
DECLARE Temp : STRING
DECLARE Swapped : BOOLEAN
DECLARE Limit : INTEGER
DECLARE Index : INTEGER
Swapped <- TRUE
Limit <- N - 1
WHILE Swapped = TRUE AND Limit > 0
Swapped <- FALSE
FOR Index <- 1 TO Limit
IF Names[Index] > Names[Index + 1] THEN
Temp <- Names[Index]
Names[Index] <- Names[Index + 1]
Names[Index + 1] <- Temp
Swapped <- TRUE
ENDIF
ENDFOR
Limit <- Limit - 1
ENDWHILE
ENDPROCEDURE
```

PastPaper.markingScheme

1 Mark: Correct procedure header specifying `BYREF` for the array and `BYVAL` (implicit or explicit) for parameter `N`.
1 Mark: Set up outer loop controlled by `Swapped` flag and decreasing limit boundary.
1 Mark: Re-setting the `Swapped` flag to FALSE before the inner pass begins.
1 Mark: Inner loop running from 1 up to `Limit` (where limit is decremented on each pass).
1 Mark: Correctly comparing adjacent array elements (`Names[Index] > Names[Index + 1]`).
1 Mark: Correct three-line swap using a temporary variable.
1 Mark: Setting `Swapped` to TRUE when a swap occurs to ensure optimization logic works.

PastPaper.sampleCTATitle

PastPaper.sampleCTADescription

PastPaper.sampleStickyMessage

PastPaper.stickyCtaText