An original Thinka practice paper modelled on the structure and difficulty of the Nov 2024 (V2) Cambridge International A Level Computer Science (9618) paper. Not affiliated with or reproduced from Cambridge.
Paper 12: Theory Fundamentals
Answer all questions. Calculators must not be used in this paper.
28 PastPaper.question · 84 PastPaper.marks
PastPaper.question 1 · Short Answer
2 PastPaper.marks
Explain one advantage of representing signed integers in two's complement format rather than sign and magnitude format.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
In sign and magnitude, there are two distinct binary representations for the value zero (+0 and -0), which wastes a combination and complicates comparisons. Two's complement has only a single representation for zero. Furthermore, two's complement arithmetic allows subtraction to be performed using standard addition circuits (by adding a negative number), which simplifies the ALU hardware design.
PastPaper.markingScheme
1 mark for identifying a valid advantage (e.g., only one representation of zero, or subtraction can be performed using addition circuits). 1 mark for expanding on how this simplifies hardware design or prevents representation wastage.
PastPaper.question 2 · Short Answer
2 PastPaper.marks
State the difference between bit rate and baud rate in data transmission.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Bit rate measures the amount of binary data (bits) transmitted over a channel per second. Baud rate measures the number of times the physical signal carrier changes state (or symbols sent) per second. If a signal change represents multiple bits (e.g., using QAM), the bit rate can be higher than the baud rate.
PastPaper.markingScheme
1 mark for defining bit rate as the number of bits transmitted per second. 1 mark for defining baud rate as the number of signal or state changes per second.
PastPaper.question 3 · Short Answer
2 PastPaper.marks
State two benefits of using a capacitive touchscreen instead of a resistive touchscreen.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Capacitive screens utilize the electrostatic field of the human body, allowing multiple simultaneous touches (multi-touch) to be registered. Because they do not require flexible plastic layers that flex to touch, they use high-quality glass which offers superior optical clarity and durability compared to resistive screens.
PastPaper.markingScheme
1 mark for each valid benefit (up to 2). Accepted: multi-touch support, higher image clarity/brightness, more durable/scratch-resistant glass surface, more sensitive to light touch.
PastPaper.question 4 · Short Answer
2 PastPaper.marks
Describe the function of the Program Counter (PC) register during the Fetch stage of the Fetch-Execute cycle.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
At the start of the Fetch stage, the address currently stored in the Program Counter (PC) is copied to the Memory Address Register (MAR). Immediately after, or during this cycle, the PC is incremented by one so that it points to the address of the next sequential instruction.
PastPaper.markingScheme
1 mark for stating that the PC holds the address of the next instruction and copies it to the MAR. 1 mark for stating that the PC is incremented to point to the next instruction.
PastPaper.question 5 · Short Answer
2 PastPaper.marks
Describe how disk defragmentation software improves the performance of a hard disk drive (HDD).
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Over time, files stored on a hard disk drive become fragmented, meaning parts of a single file are scattered across different non-contiguous physical sectors. Defragmentation software moves these segments so that each file is stored in contiguous blocks, and aggregates free space together. This minimizes the movement of the HDD's mechanical read/write arm, leading to faster file access and load times.
PastPaper.markingScheme
1 mark for explaining that fragments of the same file are reorganized to be contiguous (or free space is consolidated). 1 mark for linking this to reduced physical movement of the read/write head / faster access times.
PastPaper.question 6 · Short Answer
2 PastPaper.marks
Explain the difference between data validation and data verification.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Data validation is an automated check performed by software to ensure that the input data is reasonable, sensible, and within certain parameters (e.g., range check, type check). Data verification is a process to ensure that the entered data is completely accurate to the original source data (e.g., visual check, double entry check).
PastPaper.markingScheme
1 mark for explaining validation (checks logic/rules/reasonableness). 1 mark for explaining verification (checks completeness/accuracy against source).
PastPaper.question 7 · Short Answer
2 PastPaper.marks
Distinguish between open-source software and shareware.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Open-source software is licensed to allow users to inspect, modify, and redistribute its underlying source code freely. Shareware is copyrighted, proprietary software that is distributed free of charge on a trial basis (often with limited features or an expiration date) to encourage purchase; users do not get access to the source code.
PastPaper.markingScheme
1 mark for defining open-source software (access to source code, modifiable). 1 mark for defining shareware (proprietary, trial period, no source code access).
PastPaper.question 8 · Short Answer
2 PastPaper.marks
Explain how a primary key and a foreign key are used to link two tables in a relational database.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
In a relational database, tables are linked together to represent relationships. A primary key uniquely identifies each record in the parent table. A foreign key is a field (or collection of fields) in a child table that refers to the primary key of the parent table. By populating the foreign key with matching primary key values, a link is established, ensuring referential integrity.
PastPaper.markingScheme
1 mark for explaining that the primary key uniquely identifies a record. 1 mark for explaining that the foreign key in the other table references/contains the value of this primary key to establish the link.
PastPaper.question 9 · Short Answer
2 PastPaper.marks
Describe the difference between immediate addressing and direct addressing in Assembly language.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
In Assembly language, addressing modes determine how the operand of an instruction is interpreted: - **Immediate Addressing**: The operand field contains the actual data or constant value to be used in the instruction (for example, `LDM #45` loads the value 45 directly into the accumulator). - **Direct Addressing**: The operand field contains the memory address where the actual data or value is stored (for example, `LDD 45` loads the contents of memory location 45 into the accumulator).
PastPaper.markingScheme
1 mark for a clear description of immediate addressing (e.g., operand is the actual value/constant). 1 mark for a clear description of direct addressing (e.g., operand is the memory address where the data is stored).
PastPaper.question 10 · Short Answer
2 PastPaper.marks
State the difference between data validation and data verification.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Although both processes are used to safeguard data quality, they serve distinct purposes: - **Data Validation**: An automatic computer check to ensure that the input data is reasonable, sensible, and conforms to predefined rules (such as range, type, or length checks). - **Data Verification**: A check to ensure that the data has been accurately copied or transferred from a source document to the computer system without any transcription or transmission errors (using methods like double-entry or visual checks).
PastPaper.markingScheme
1 mark for defining data validation (e.g., checking data is sensible/reasonable/conforms to rules). 1 mark for defining data verification (e.g., checking data is identical to the original/entered correctly).
PastPaper.question 11 · Short Answer
2 PastPaper.marks
Explain how Run-Length Encoding (RLE) is used to compress data.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Run-Length Encoding (RLE) is a lossless data compression algorithm. It operates by: 1. Scanning a file to identify sequences of consecutive, identical data elements (referred to as 'runs'). 2. Replacing each run with a single copy of the data value along with a count representing the number of times it repeats consecutively (e.g., the string "AAAAABBB" is compressed to "5A3B").
PastPaper.markingScheme
1 mark for identifying consecutive/repeated data values or characters. 1 mark for explaining that it replaces these runs with the data value and its frequency count.
PastPaper.question 12 · Short Answer
2 PastPaper.marks
Define the term 'referential integrity' in the context of a relational database.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Referential integrity is a database constraint that ensures relationships between tables remain consistent. It dictates that every foreign key value in a child table must have a corresponding, matching primary key value in the referenced parent table, or otherwise be set to null. This prevents the occurrence of 'orphaned records' and guarantees data consistency.
PastPaper.markingScheme
1 mark for stating it ensures data consistency/accuracy across linked/related tables. 1 mark for explaining that a foreign key value must match an existing primary key value in the parent table (or be null/preventing orphaned records).
PastPaper.question 13 · structured
2 PastPaper.marks
A logic circuit has three inputs, \(A\), \(B\), and \(C\). The output \(X\) is represented by the following Boolean expression:
\(X = (\text{NOT } A \text{ AND } B) \text{ OR } (B \text{ AND } \text{NOT } C)\)
Determine the output value of \(X\) for each of the following input combinations:
1. \(A = 1, B = 1, C = 1\) 2. \(A = 1, B = 1, C = 0\)
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Substitute the inputs into the Boolean expression:
1. For \(A = 1, B = 1, C = 1\): \(X = (\text{NOT } 1 \text{ AND } 1) \text{ OR } (1 \text{ AND } \text{NOT } 1)\) \(X = (0 \text{ AND } 1) \text{ OR } (1 \text{ AND } 0)\) \(X = 0 \text{ OR } 0\) \(X = 0\)
2. For \(A = 1, B = 1, C = 0\): \(X = (\text{NOT } 1 \text{ AND } 1) \text{ OR } (1 \text{ AND } \text{NOT } 0)\) \(X = (0 \text{ AND } 1) \text{ OR } (1 \text{ AND } 1)\) \(X = 0 \text{ OR } 1\) \(X = 1\)
PastPaper.markingScheme
1 mark for correctly identifying the output \(X = 0\) for combination 1. 1 mark for correctly identifying the output \(X = 1\) for combination 2.
PastPaper.question 14 · structured
2 PastPaper.marks
An automated greenhouse irrigation system monitors three sensors: \(P\) (soil moisture level is low), \(Q\) (temperature is high), and \(R\) (water tank is empty).
The system triggers the water pump output \(S = 1\) when: - The soil moisture level is low (\(P = 1\)) AND the temperature is NOT high (\(Q = 0\)) - OR - The temperature is high (\(Q = 1\)) AND the water tank is NOT empty (\(R = 0\))
Write the Boolean expression that represents the output \(S\) in terms of inputs \(P\), \(Q\), and \(R\). Use the operators \(\text{AND}\), \(\text{OR}\), and \(\text{NOT}\).
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
To construct the expression: 1. The first condition 'soil moisture level is low AND the temperature is NOT high' translates to: \(P \text{ AND } \text{NOT } Q\). 2. The second condition 'temperature is high AND water tank is NOT empty' translates to: \(Q \text{ AND } \text{NOT } R\). 3. These two alternative conditions are combined using the \(\text{OR}\) operator: \(S = (P \text{ AND } \text{NOT } Q) \text{ OR } (Q \text{ AND } \text{NOT } R)\)
PastPaper.markingScheme
1 mark for the correct term: \(P \text{ AND } \text{NOT } Q\) (or equivalent, e.g. \(P \cdot \bar{Q}\)). 1 mark for the correct term: \(Q \text{ AND } \text{NOT } R\) combined with the OR operator (or equivalent, e.g. \(Q \cdot \bar{R}\)). Accept algebraic notation: \(S = P\bar{Q} + Q\bar{R}\) or \(S = P \cdot \text{NOT } Q + Q \cdot \text{NOT } R\).
A school library database is designed with two tables: a Borrower table, where BorrowerID is the primary key, and a BookLoan table, where BorrowerID is a foreign key. Explain how referential integrity is enforced by the Database Management System (DBMS) when a librarian attempts to delete a borrower's record or add a new book loan.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
1. Referential integrity ensures that any foreign key value in the BookLoan table must have a corresponding, matching primary key value in the Borrower table. 2. When a librarian attempts to add a new book loan, the DBMS checks the BorrowerID field. If the ID does not exist in the Borrower table, the DBMS blocks the insertion. 3. When a librarian attempts to delete a borrower record, the DBMS checks if there are any related BookLoan records. 4. To prevent orphaned records, the DBMS will either block the deletion of that borrower or cascade the deletion by removing all associated loans.
PastPaper.markingScheme
1 mark: State that referential integrity ensures a foreign key value must match an existing primary key value (no orphaned records). 1 mark: Explain that adding a loan with a non-existent BorrowerID will be blocked. 1 mark: Explain that deleting a borrower who has active loans will be detected. 1 mark: Explain the consequence (deletion is blocked or cascade-deleted to maintain database consistency).
A medical clinic transmits confidential patient reports to a central hospital. The administrator wants to use digital signatures. Explain how a digital signature is created by the clinic and verified by the hospital to ensure both the integrity and authenticity of a patient report.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
1. The clinic applies a hashing algorithm to the patient report to produce a unique message digest. 2. This message digest is encrypted using the clinic's private key to generate the digital signature. 3. The digital signature is sent along with the patient report to the hospital. 4. The hospital decrypts the digital signature using the clinic's public key to retrieve the original digest, hashes the received report, and compares the two. If they match, the report has not been altered (integrity) and indeed came from the clinic (authenticity).
PastPaper.markingScheme
1 mark: Hash algorithm applied to patient report to create a message digest. 1 mark: Digest encrypted using the sender's (clinic's) private key to create the digital signature. 1 mark: Signature transmitted alongside the report. 1 mark: Receiver decrypts the signature with the sender's public key and compares the calculated hash with the decrypted hash to verify integrity/authenticity.
During the execution of a user program, the processor receives an interrupt signal from a hardware device. Explain the sequence of operations the CPU must perform immediately after receiving this signal, before the Interrupt Service Routine (ISR) can begin executing.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
1. The CPU finishes executing the instruction currently in the Fetch-Decode-Execute cycle. 2. The current state of the registers (such as the Program Counter (PC), Accumulator, and status register) is saved onto the system stack. 3. The CPU identifies the source of the interrupt (using the interrupt vector table). 4. The starting address of the corresponding Interrupt Service Routine (ISR) is loaded into the Program Counter (PC), allowing the processor to branch to the interrupt handler.
PastPaper.markingScheme
1 mark: CPU completes the current instruction execution cycle. 1 mark: Saves the current register contents (PC, Accumulator, Status Register, etc.) onto the stack. 1 mark: CPU identifies the interrupt source/type. 1 mark: Loads the address of the corresponding ISR into the Program Counter (PC).
An office of fifteen employees is deciding whether to install a client-server network or a peer-to-peer (P2P) network. Explain two operational differences between these two network models regarding file storage and security administration.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
1. File Storage: In a client-server model, files and shared resources are stored centrally on a dedicated server. In a peer-to-peer model, files are distributed across individual workstations (peers), which act as both client and server, sharing files directly. 2. Security and Administration: In a client-server network, user accounts, access permissions, and backups are managed centrally from the server. In a P2P network, there is no central control; security and backups must be configured and managed individually on each workstation.
PastPaper.markingScheme
1 mark: Client-server has centralized file storage on a dedicated server. 1 mark: P2P has decentralized storage where files are stored on individual peer machines. 1 mark: Client-server security/backups are managed centrally by a network administrator. 1 mark: P2P security/backups are managed individually by each user on their own machine.
Over several months, a software developer has been creating, modifying, and deleting large source files on a computer with a Hard Disk Drive (HDD), leading to a slow system response. Explain how file fragmentation occurs on an HDD and how running a disk defragmenter utility helps restore system performance.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
1. When files are deleted, they leave empty blocks on the hard drive. 2. When new or modified files are written, they may be too large for a single continuous block, so the operating system splits the file and stores the segments in non-contiguous gaps across the disk. 3. Reading a fragmented file requires the HDD's read/write head to physically move to different tracks and sectors, which increases disk latency. 4. A defragmentation utility rearranges the fragments so that all parts of each file are stored in contiguous sectors and consolidates free space, minimizing read/write head movement and speeding up file access.
PastPaper.markingScheme
1 mark: Deleting files leaves gaps on the hard drive. 1 mark: New/modified files are split and written into these non-contiguous gaps (fragmentation). 1 mark: Reading fragmented files requires the physical HDD read/write head to travel to multiple locations, increasing access time (latency). 1 mark: The defragmentation utility rearranges segments into contiguous sectors, reducing head movement and improving read speeds.
A startup is launching a new software product. They must decide between releasing it under a commercial proprietary license or an open-source license. Explain two key differences between these licensing models from the perspective of the end-user's rights to the software.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
1. Access to and modification of source code: An open-source license grants the user the right to view, modify, and improve the underlying source code. A commercial proprietary license keeps the source code closed (hidden), and users only receive the compiled machine code, with no legal right to alter it. 2. Redistribution and duplication rights: Open-source licenses allow users to copy and redistribute the software (sometimes with modifications) to others without paying fees. Proprietary licenses restrict usage to a specified number of installations, requiring license keys, and explicitly forbid users from redistributing or copying the software.
PastPaper.markingScheme
1 mark: Open-source permits users to view, edit, and compile the source code. 1 mark: Proprietary license restricts source code access (only executable code is provided) and legally forbids modification. 1 mark: Open-source allows free copying and redistribution of the software. 1 mark: Proprietary license restricts redistribution, often enforcing this with product keys, activation servers, or legal penalties.
A sound engineer is recording an acoustic performance. They need to choose the sampling rate and sampling resolution. Explain how the choices made for these two settings affect both the quality of the recorded audio and the resulting file size.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
1. Sampling rate determines how often the analog sound wave is measured per second. A higher sampling rate accurately captures higher frequencies (up to half the sampling rate, Nyquist limit) and reduces distortion. 2. Sampling resolution (bit depth) determines the number of bits used to store the amplitude of each sample. A higher resolution provides more precision, increasing the dynamic range and reducing quantization error/noise. 3. Increasing either parameter means more data points are captured per unit of time. 4. Consequently, the quality of the recording is significantly improved, but the total file size increases because more bytes are required to store each second of audio.
PastPaper.markingScheme
1 mark: Higher sampling rate captures higher frequencies more accurately, improving fidelity. 1 mark: Higher sampling resolution increases dynamic range and reduces quantization noise/errors. 1 mark: Increasing either setting results in more binary data points being stored per second of audio. 1 mark: Explains the trade-off: higher quality results in a larger file size.
A team is developing a new mobile banking application. They must choose between the Waterfall lifecycle model and an Iterative/Agile development model. Explain why the Iterative/Agile model is more suitable than the Waterfall model for this project, given that the application must adapt to frequent user feedback and security updates.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
1. Mobile banking applications exist in a dynamic environment where user feedback, mobile operating system updates, and security threats change rapidly. 2. The Iterative/Agile model develops the application in short, manageable cycles (sprints), producing a working software increment at the end of each cycle. 3. This allows user feedback to be gathered and implemented immediately in subsequent sprints, whereas the Waterfall model is rigid and sequential, making it difficult to go back and make changes once a stage is completed. 4. Emerging security vulnerabilities can be prioritized and patched in the very next sprint, ensuring the application remains secure, which would be impossible in a long-term Waterfall schedule where testing occurs only at the end.
PastPaper.markingScheme
1 mark: Identify that a mobile banking app operates in a rapidly changing environment (new OS features, security vulnerabilities, user preferences). 1 mark: Explain that Agile develops software in short, iterative cycles (sprints), producing working prototypes regularly. 1 mark: Explain that feedback can be gathered and acted upon in subsequent sprints (unlike Waterfall's rigid linear phase transitions). 1 mark: Explain that urgent security updates or changes can be easily prioritized and deployed in the next cycle rather than waiting for the entire project life cycle to finish.
PastPaper.question 23 · practical
4 PastPaper.marks
A database contains two tables to manage a book rental service: - `tblBook(BookID, Title, Author, Genre)` where `BookID` is the primary key. - `tblLoan(LoanID, BookID, MemberID, DateDue, Returned)` where `LoanID` is the primary key and `BookID` is a foreign key. The field `Returned` stores boolean values (TRUE/FALSE).
Write an SQL query to retrieve the `Title` of the book and the `DateDue` for all loans that have not been returned yet. The results should be ordered so that the earliest due date is shown first.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
To retrieve the required data, a join is necessary between `tblBook` and `tblLoan` using the common attribute `BookID`. The SELECT clause must specify both the `Title` and the `DateDue`. The WHERE clause filters out returned loans by checking `Returned = FALSE` (or `= 0`). Finally, the ORDER BY clause sorts the dates in ascending order (`ASC`) so the earliest due date appears first.
PastPaper.markingScheme
1 mark for correct SELECT clause (`SELECT Title, DateDue` or with table prefixes). 1 mark for correct INNER JOIN syntax (`FROM tblBook INNER JOIN tblLoan ON tblBook.BookID = tblLoan.BookID` or equivalent implicit join in WHERE). 1 mark for correct filter condition (`WHERE Returned = FALSE` or `WHERE Returned = 0` or equivalent). 1 mark for correct ordering clause (`ORDER BY DateDue ASC` or `ORDER BY DateDue`).
PastPaper.question 24 · structured
4 PastPaper.marks
A company database tracks departments, developers, and projects: - A developer belongs to exactly one department. - A department can employ many developers. - A developer can be assigned to many projects, and a project can have many developers assigned to it.
(a) State the relationship type between Department and Developer. [1] (b) Describe how the relationship between Developer and Project is implemented in a relational database. [2] (c) Identify the type of key that uniquely identifies each record in this newly created link table. [1]
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
(a) A department has many developers, but a developer has only one department, making it a one-to-many relationship. (b) Since there is a many-to-many (M:N) relationship between Developer and Project, direct implementation is not possible. A new link table (e.g., DeveloperProject) must be introduced to hold foreign keys referencing both primary tables. (c) The combination of the two foreign keys is used to uniquely identify each record in the link table, forming a composite primary key.
PastPaper.markingScheme
(a) 1 mark for stating 'One-to-many' (or 1:M / 1-to-many). (b) 1 mark for mentioning the creation of a new link/junction/intermediary table; 1 mark for stating that this table contains the primary keys from both Developer and Project tables as foreign keys. (c) 1 mark for identifying the key as a 'composite primary key' (or compound key).
PastPaper.question 25 · practical
4 PastPaper.marks
Write an SQL script to create a database table named `tblProduct` with the following requirements: - `ProductID`: an integer that uniquely identifies each product, designated as the primary key. - `Description`: a text field of up to 100 characters that cannot be empty. - `UnitPrice`: a decimal number to store price values. - `SupplierID`: an integer used to link the product to a supplier. Define this as a foreign key referencing the `SupplierID` field in the table `tblSupplier`.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
The SQL DDL query defines the table and its columns with correct types, constraints, and relationships. It uses standard keywords such as `CREATE TABLE`, `NOT NULL`, `PRIMARY KEY`, and `FOREIGN KEY ... REFERENCES`.
PastPaper.markingScheme
1 mark for correct table creation syntax and appropriate data types (`CREATE TABLE tblProduct` with opening/closing parentheses). 1 mark for declaring `ProductID` as `PRIMARY KEY` (either inline or at table level). 1 mark for declaring `Description` with appropriate varchar/char data type and the `NOT NULL` constraint. 1 mark for declaring `SupplierID` as a `FOREIGN KEY` referencing `tblSupplier(SupplierID)`.
1. `LDD 120` loads the value 5 into ACC. 2. `SUB #2` subtracts 2 from ACC, making ACC = 3. 3. `STO 121` stores the ACC (3) into address 121. Thus, **[ A ] = 3**. 4. `ADD #1` adds 1 to ACC, making ACC = 4. Thus, **[ B ] = 4**. 5. `CMP #2` compares ACC (4) with 2, which is false, so `JPN L1` jumps back to L1. 6. `SUB #2` subtracts 2 from ACC, making ACC = 2. Thus, **[ C ] = 2**. 7. `STO 121` stores ACC (2) into address 121. 8. `ADD #1` makes ACC = 3, and after comparison, the jump is taken again. 9. `SUB #2` makes ACC = 1. 10. `STO 121` stores ACC (1) into address 121. Thus, **[ D ] = 1**. 11. `ADD #1` makes ACC = 2, so the comparison with 2 is true and the loop terminates.
PastPaper.markingScheme
1 mark for each correct value: * **A = 3** (1 mark) * **B = 4** (1 mark) * **C = 2** (1 mark) * **D = 1** (1 mark)
- **[ 1 ]** must jump to label ELSE_L if the comparison of ACC with 0 is false (i.e. not equal to 0). This is `JPN`. - **[ 2 ]** must store the value in ACC (which is 10) back into address 160. This is `STO 160`. - **[ 3 ]** is the start of the else block. We must load the value of address 160 to prepare for adding 2. This is `LDD 160`. - **[ 4 ]** must store the incremented value in ACC back into address 160. This is `STO 160`.
An assembly language program sums three array elements located at memory addresses 200, 201, and 202 using indexed addressing. The Index Register (IX) is initialized to 0, and memory address 150 (Sum) is initialized to 0. Memory address 151 (Counter) is initialized to 3.
```assembly L1: LDX 200 ADD 150 STO 150 INC IX LDD 151 SUB #1 STO 151 CMP #0 JPN L1 ```
Identify the values that should replace the blanks **[ E ]**, **[ F ]**, **[ G ]**, and **[ H ]** from the execution of the program:
* **[ E ]**: Value of ACC immediately after the second execution of `LDX 200` * **[ F ]**: Value stored in memory location 150 after the second execution of `STO 150` * **[ G ]**: Value of the Index Register (IX) immediately after the second execution of `INC IX` * **[ H ]**: Final value of memory location 151 when the program terminates
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
- **First Iteration**: - `LDX 200`: IX is 0, so effective address is 200. ACC loads contents of 200 (12). - `ADD 150`: ACC becomes 12 + 0 = 12. - `STO 150`: Memory 150 becomes 12. - `INC IX`: IX becomes 1. - `LDD 151`, `SUB #1`, `STO 151`: Memory 151 becomes 2. - `CMP #0`, `JPN L1`: Jump taken. - **Second Iteration**: - `LDX 200`: IX is 1, so effective address is 201. ACC loads contents of 201 (5). Thus, **[ E ] = 5**. - `ADD 150`: ACC becomes 5 + 12 = 17. - `STO 150`: Memory 150 becomes 17. Thus, **[ F ] = 17**. - `INC IX`: IX becomes 2. Thus, **[ G ] = 2**. - `LDD 151`, `SUB #1`, `STO 151`: Memory 151 becomes 1. - `CMP #0`, `JPN L1`: Jump taken. - **Third Iteration**: - `LDX 200`: IX is 2, so effective address is 202. ACC loads contents of 202 (8). - `ADD 150`: ACC becomes 8 + 17 = 25. - `STO 150`: Memory 150 becomes 25. - `INC IX`: IX becomes 3. - `LDD 151`, `SUB #1`, `STO 151`: Memory 151 becomes 0. Thus, **[ H ] = 0**. - `CMP #0`: ACC (0) is equal to 0, so no jump. Program ends.
PastPaper.markingScheme
1 mark for each correct value: * **E = 5** (1 mark) * **F = 17** (1 mark) * **G = 2** (1 mark) * **H = 0** (1 mark)
Paper 22: Fundamental Problem-solving and Programming Skills
Answer all questions. Refer to the insert for standard pseudocode syntax and functional libraries.
19 PastPaper.question · 82 PastPaper.marks
PastPaper.question 1 · Structured Question
2 PastPaper.marks
In a structure chart, two types of parameters can be passed between modules: a data couple and a control couple. Explain the difference between these two couples.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
A data couple transfers variable values needed for computation (such as CustomerID or TotalCost). A control couple transfers control information (such as an EOF flag or validation success status) that dictates the program execution path in the receiving module.
PastPaper.markingScheme
1 mark for correctly explaining that a data couple transfers data values or variables. 1 mark for correctly explaining that a control couple transfers flags, status signals, or control decisions.
PastPaper.question 2 · Structured Question
2 PastPaper.marks
Write a pseudocode procedure header for a procedure named UpdateBalance that accepts an integer parameter AccountNumber by value, and a real parameter CurrentBalance by reference.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
The procedure header must declare the procedure name, specify parameter passing mechanisms using BYVAL and BYREF, and assign correct data types to each parameter using standard 9618 pseudocode syntax.
PastPaper.markingScheme
1 mark for correct procedure syntax, procedure name, and correct parameter passing mechanism (BYVAL and BYREF). 1 mark for declaring appropriate data types (INTEGER and REAL) corresponding to each parameter.
PastPaper.question 3 · Structured Question
2 PastPaper.marks
Stepwise refinement is an essential concept in top-down design. Describe how stepwise refinement is applied when designing a new software program.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
The designer begins with the global system requirements and progressively decomposes the major functions into smaller modules. This decomposition continues level-by-level until the tasks are at an elemental level that can be written directly in code.
PastPaper.markingScheme
1 mark for mentioning the decomposition of a problem into smaller sub-problems. 1 mark for stating that the process is repeated iteratively until individual modules/tasks are simple enough to program.
PastPaper.question 4 · Structured Question
2 PastPaper.marks
State two benefits of using an identifier table during the design and development phase of a program.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
An identifier table registers all variable, constant, and sub-routine names along with their data type, scope, and purpose. This prevents duplicate identifier declarations and supports maintenance programmers in understanding code semantics.
PastPaper.markingScheme
1 mark per distinct benefit (maximum of 2 marks): Promotes consistency in naming/typing; Prevents scope conflict or variable duplication; Serves as documentation for system maintenance; Helps in debugging.
PastPaper.question 5 · Structured Question
2 PastPaper.marks
Explain the concept of abstraction as used in software design, and give one example of how it is implemented in a high-level programming language.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Abstraction reduces complexity by allowing developers to work at a higher conceptual level. Built-in functions, user-defined subroutines, or objects allow programmers to execute complex instructions through a simple interface while concealing the low-level processing steps.
PastPaper.markingScheme
1 mark for a correct definition of abstraction (hiding details to focus on essential aspects). 1 mark for a valid practical example (such as using built-in functions, libraries, or user-defined subroutines).
PastPaper.question 6 · Structured Question
2 PastPaper.marks
State how selection (decision-making) and iteration (looping) are visually represented on a structure chart.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
In standard structure chart notation, conditional paths of execution use a diamond symbol at the split of the connection line. Repeated module calls (loops) are designated by a semi-circular curved arrow that encompasses the module paths.
PastPaper.markingScheme
1 mark for stating selection is represented by a diamond symbol. 1 mark for stating iteration is represented by a curved arrow.
PastPaper.question 7 · practical
3 PastPaper.marks
Write a pseudocode header for a function named FindAverage that takes a 1D array of integers named Scores (with index range 1 to 50) as a parameter passed by reference, and returns a real number.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
The function header requires the FUNCTION keyword, followed by the name FindAverage. The parameter list should declare Scores as an array with bounds 1 to 50 of type integer, preceded by BYREF to pass it by reference. Finally, the return type REAL must be specified using the RETURNS keyword.
PastPaper.markingScheme
1 mark: Correct FUNCTION FindAverage(...) and RETURNS REAL. 1 mark: Correct parameter declaration with BYREF. 1 mark: Correct array type definition Scores : ARRAY[1:50] OF INTEGER.
PastPaper.question 8 · practical
3 PastPaper.marks
Write the complete pseudocode function CheckEnds that takes a 1D array of 10 integers (index 1 to 10) called Levels as a parameter by value, and returns TRUE if the first element is equal to the last element, and FALSE otherwise.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
The function is defined with parameter passing mode BYVAL. It compares the element at index 1 (Levels[1]) with the element at index 10 (Levels[10]). Based on the comparison, it returns TRUE or FALSE.
PastPaper.markingScheme
1 mark: Correct function header and footer with BYVAL Levels : ARRAY[1:10] OF INTEGER and RETURNS BOOLEAN. 1 mark: Correct indexing of first (Levels[1]) and last (Levels[10]) elements. 1 mark: Logic to compare the elements and return correct Boolean values (e.g., RETURN (Levels[1] = Levels[10]) is also acceptable).
PastPaper.question 9 · theory
3 PastPaper.marks
Explain why passing a large 2D array by reference (BYREF) is computationally more efficient than passing it by value (BYVAL) in a procedure call, even if the procedure does not modify the array.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Passing by value causes the computer to duplicate the entire array structure in memory, which consumes CPU cycles and RAM. Passing by reference passes only a memory pointer to the original array, which executes instantly regardless of array size.
PastPaper.markingScheme
1 mark: Identification that BYVAL makes a complete duplicate/copy of the array. 1 mark: Explaining the overhead of BYVAL (takes up extra memory and CPU time to copy elements). 1 mark: Identification that BYREF only passes a reference/pointer to the original memory location, avoiding this overhead.
PastPaper.question 10 · practical
3 PastPaper.marks
Write a complete pseudocode procedure ZeroNegative that takes a 1D array of 5 integers (index 1 to 5) as a parameter. The procedure must modify the original array so that any negative value is replaced by 0.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
The procedure must use BYREF because it needs to modify the original array. Inside, a loop iterates through indexes 1 to 5. An IF statement checks if the current element is negative, and if so, reassigns it to 0.
PastPaper.markingScheme
1 mark: Correct procedure header using BYREF for the array parameter: PROCEDURE ZeroNegative(BYREF Elements : ARRAY[1:5] OF INTEGER). 1 mark: Correct loop structure (e.g. FOR i <- 1 TO 5 ... NEXT i) to iterate through all 5 indices. 1 mark: Correct check Elements[i] < 0 and assignment Elements[i] <- 0 inside the loop, and proper termination (ENDPROCEDURE).
PastPaper.question 11 · practical
6 PastPaper.marks
An array `Names` of size `N` contains string values. Write a pseudocode procedure `RemoveConsecutiveDuplicates(BYREF Names : ARRAY, N : INTEGER)` that modifies the array in-place. If the same name appears consecutively (e.g., 'John', 'John'), only the first occurrence is kept, and the consecutive duplicates are removed. All subsequent elements must be shifted to the left, and the remaining empty slots at the end of the array must be filled with the empty string `""`.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
The algorithm uses a two-pointer approach to modify the array in-place. 1. `WritePtr` keeps track of the last unique element placed. 2. `ReadPtr` scans the array from index 2 to `N`. 3. If `Names[ReadPtr]` is different from `Names[WritePtr]`, `WritePtr` is incremented and the unique element is copied. 4. After scanning, all elements from `WritePtr + 1` to `N` are overwritten with the empty string `""` to clear the remaining slots.
PastPaper.markingScheme
1 mark: Correct procedure header definition with `BYREF Names : ARRAY` and `N : INTEGER` parameters. 1 mark: Loop initialization and handling of base case (where `N <= 1`). 1 mark: Outer loop iterating safely from index 2 to `N`. 1 mark: Correct comparison of current element with the element at `WritePtr`. 1 mark: Correct copy/update of elements to compact the array in-place. 1 mark: Correct loop from `WritePtr + 1` to `N` to pad the rest of the array with `""`.
PastPaper.question 12 · practical
6 PastPaper.marks
A 2D integer array `Grid` has 5 rows and 5 columns. Write a pseudocode procedure `SmoothRowValues(BYREF Grid : ARRAY)` that modifies the array in-place. For each row, if any element (excluding the boundary elements at column 1 and column 5) is less than 0, it must be replaced by the average (integer division) of its immediate left and right neighbors.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
We iterate through each row (1 to 5) and check inner columns (2 to 4) to avoid accessing out-of-bounds neighbors. If the value at `Grid[Row, Col]` is negative, we calculate the sum of `Grid[Row, Col - 1]` and `Grid[Row, Col + 1]` and perform integer division with `DIV 2` to overwrite the negative value.
PastPaper.markingScheme
1 mark: Correct procedure header with `BYREF Grid : ARRAY`. 1 mark: Outer loop correctly iterating through all 5 rows. 1 mark: Inner loop correctly iterating strictly from column 2 to 4. 1 mark: Correct conditional statement to check if the current element is less than 0. 1 mark: Correct calculation of left and right neighbor sum. 1 mark: Correct use of `DIV 2` (or equivalent integer division) and saving it back to `Grid[Row, Col]`.
PastPaper.question 13 · practical
6 PastPaper.marks
Write a pseudocode procedure `ReverseSubArray(BYREF Arr : ARRAY, StartIndex : INTEGER, EndIndex : INTEGER)` that reverses the order of elements in the 1D integer array `Arr` strictly between `StartIndex` and `EndIndex` inclusive, in-place. Assume the array is 1-indexed. Do not use an auxiliary array.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
The algorithm initializes two pointers, `Left` to `StartIndex` and `Right` to `EndIndex`. Inside a loop that runs while `Left` is less than `Right`, the elements at these two index positions are swapped using a temporary variable `Temp`. After swapping, `Left` is incremented and `Right` is decremented to move closer to the center.
PastPaper.markingScheme
1 mark: Correct procedure declaration with `BYREF` parameter for `Arr` and proper types for indices. 1 mark: Initializing pointer variables `Left` and `Right` to the parameters `StartIndex` and `EndIndex`. 1 mark: Correct loop condition `Left < Right` to prevent duplicate swapping or index crossing. 1 mark: Storing the value of `Arr[Left]` in a temporary variable to allow exchange. 1 mark: Correctly swapping elements `Arr[Left]` and `Arr[Right]` without losing values. 1 mark: Correctly incrementing `Left` and decrementing `Right` inside the loop.
PastPaper.question 14 · practical
6 PastPaper.marks
A 1D array `SortedNumbers` contains 10 integer elements in ascending order, where index 10 holds a dummy value of 9999. Write a pseudocode procedure `InsertValue(BYREF SortedNumbers : ARRAY, NewValue : INTEGER)` that inserts `NewValue` into its correct sorted position. To make room for `NewValue`, all elements greater than `NewValue` must be shifted one position to the right. Assume the array is 1-indexed.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
To maintain sorted order: 1. Start a pointer `Index` at 9 (the last valid non-dummy element). 2. Compare `SortedNumbers[Index]` with `NewValue`. If it is larger, shift it to `Index + 1`. 3. Decrement `Index` and repeat until we either reach the start of the array or find a value less than or equal to `NewValue`. 4. Write `NewValue` into the empty slot at `Index + 1`.
PastPaper.markingScheme
1 mark: Correct procedure header definition with `BYREF SortedNumbers` and integer value. 1 mark: Initializing index pointer to 9 (not 10, as index 10 is overwritten first). 1 mark: Loop condition checking boundaries (`Index >= 1`) to avoid index-out-of-bounds error. 1 mark: Correct comparative condition checking if array element is greater than `NewValue`. 1 mark: Shifting elements to the right safely (`SortedNumbers[Index + 1] <- SortedNumbers[Index]`). 1 mark: Placing `NewValue` correctly at `Index + 1` after the shift loop terminates.
PastPaper.question 15 · practical
6 PastPaper.marks
Two 1D integer arrays, `ArrayA` and `ArrayB`, each contain 5 elements and are sorted in ascending order. Write a pseudocode procedure `MergeArrays(ArrayA : ARRAY, ArrayB : ARRAY, BYREF ArrayC : ARRAY)` that merges the elements of `ArrayA` and `ArrayB` into a 10-element array `ArrayC` such that `ArrayC` is also sorted in ascending order.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
The algorithm uses three pointers (`IndexA`, `IndexB`, `IndexC`) initialized to 1. 1. A primary loop compares current elements of both arrays and writes the smaller one to `ArrayC`, incrementing the respective index and `IndexC`. 2. Once one array is exhausted, the remaining two loops copy any leftover elements from either `ArrayA` or `ArrayB` straight into the remaining spaces of `ArrayC`.
PastPaper.markingScheme
1 mark: Correct procedure signature with `BYREF ArrayC : ARRAY` (inputs do not need BYREF). 1 mark: Initializing pointers `IndexA`, `IndexB`, and `IndexC` to 1. 1 mark: Main while-loop comparing elements of `ArrayA` and `ArrayB` without crossing bounds. 1 mark: Correctly selecting and copying the smaller element to `ArrayC` and incrementing the respective pointers. 1 mark: Post-processing loop to copy remaining elements from `ArrayA` if elements are left. 1 mark: Post-processing loop to copy remaining elements from `ArrayB` if elements are left.
A stack is implemented using a 1D array MyStack of size 6, and an integer pointer TopPointer which is initialized to 0.
Write pseudocode for the procedure PushAndLog(NewChar : CHAR) which: 1. Checks if the stack is full. 2. If the stack is not full, increments TopPointer and stores NewChar at the top of the stack. 3. If the stack is full, opens a text file named "error_log.txt" in append mode, writes the line "Stack Overflow: " followed by the character NewChar, and closes the file.
- 1 mark: Correct PROCEDURE header and parameter definition with data type. - 1 mark: Check if stack is full using TopPointer >= 6 or TopPointer = 6. - 1 mark: If full, open "error_log.txt" for APPEND. - 1 mark: Write correct string concatenation ("Stack Overflow: " & NewChar) using WRITEFILE. - 1 mark: Correctly close the file using CLOSEFILE. - 1 mark: If not full, increment TopPointer (e.g., TopPointer <- TopPointer + 1). - 1 mark: Store NewChar in MyStack[TopPointer] and end procedure structure.
A text file "input.txt" contains several lines of data, where each line holds a single integer. An array-based stack NumStack is declared as ARRAY[1..10] OF INTEGER with an integer pointer TopPtr (initially 0).
Write a pseudocode procedure ProcessFileToStack() that reads all integers from "input.txt" until the end of the file is reached. For each integer read: 1. If the integer is even and the stack is not full, push the integer onto NumStack. 2. Otherwise, ignore the integer.
After reading all elements, close the file.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
PROCEDURE ProcessFileToStack() DECLARE TempNum : INTEGER OPENFILE "input.txt" FOR READ WHILE NOT EOF("input.txt") READFILE "input.txt", TempNum IF TempNum MOD 2 = 0 THEN IF TopPtr < 10 THEN TopPtr <- TopPtr + 1 NumStack[TopPtr] <- TempNum ENDIF ENDIF ENDWHILE CLOSEFILE "input.txt" ENDPROCEDURE
PastPaper.markingScheme
- 1 mark: Open file "input.txt" for READ. - 1 mark: Use a loop that tests for end-of-file properly (e.g., WHILE NOT EOF("input.txt")). - 1 mark: Read a value from the file using READFILE. - 1 mark: Check if the value is even using MOD 2 = 0. - 1 mark: Check if stack is not full (TopPtr < 10). - 1 mark: Correctly increment TopPtr and assign TempNum to NumStack[TopPtr]. - 1 mark: Correctly close the file and terminate all blocks (ENDWHILE, ENDPROCEDURE).
A stack is represented by a 1D array DataStack[1..5] OF STRING and pointer Top (initially 0).
The following stack operations are executed sequentially: 1. Push("Alpha") 2. Push("Beta") 3. Pop() 4. Push("Gamma") 5. Push("Delta") 6. Pop() 7. Push("Epsilon")
a) State the final value of Top and the elements remaining in the array DataStack (indexing from 1 to 5) after these operations are completed. [4 marks]
b) Explain why a stack is referred to as a Last-In, First-Out (LIFO) structure, referencing how the Pop operation behaves compared to the order of insertion. [3 marks]
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
a) Trace analysis: 1. Push("Alpha") -> Stack: ["Alpha", "", "", "", ""], Top = 1 2. Push("Beta") -> Stack: ["Alpha", "Beta", "", "", ""], Top = 2 3. Pop() -> Returns "Beta", Top = 1 4. Push("Gamma") -> Stack: ["Alpha", "Gamma", "", "", ""], Top = 2 5. Push("Delta") -> Stack: ["Alpha", "Gamma", "Delta", "", ""], Top = 3 6. Pop() -> Returns "Delta", Top = 2 7. Push("Epsilon") -> Stack: ["Alpha", "Gamma", "Epsilon", "", ""], Top = 3
b) In a stack, elements are added and removed from the same end (the top). Therefore, the element that was added most recently (the "last in") is positioned at the top pointer and will be the first one accessed and removed (the "first out") by a Pop operation.
PastPaper.markingScheme
Part (a): [4 marks] - 1 mark: Correct final value of Top (3). - 1 mark: DataStack[1] is "Alpha". - 1 mark: DataStack[2] is "Gamma". - 1 mark: DataStack[3] is "Epsilon".
Part (b): [3 marks] - 1 mark: Explaining "Last-In, First-Out" concept (the element added most recently is retrieved first). - 1 mark: Linking the removal behavior specifically to the Top pointer's operation. - 1 mark: Contrasting with older elements remaining at the bottom of the stack.
A software application uses a stack ActionStack implemented as a 1D array ActionStack[1..20] OF STRING with pointer TopPointer.
Write a pseudocode procedure SaveAndClearStack(FileName : STRING) that pops all values from ActionStack one by one and writes them into a text file specified by the parameter FileName. Each value must be written on a new line.
Your procedure should also ensure that the stack is left empty (i.e. TopPointer becomes 0) and the file is properly closed. If the stack is already empty at the start, the procedure should simply open the file, write nothing, and close it.
- 1 mark: Correct PROCEDURE header with FileName : STRING parameter. - 1 mark: Open the file using OPENFILE FileName FOR WRITE. - 1 mark: Loop condition to check if stack is not empty (e.g., WHILE TopPointer > 0). - 1 mark: Retrieve element from ActionStack[TopPointer]. - 1 mark: Write retrieved element to the file using WRITEFILE. - 1 mark: Decrement TopPointer (e.g., TopPointer <- TopPointer - 1). - 1 mark: Close file using CLOSEFILE FileName outside the loop, and end procedure structure.