Cambridge IAS-Level · Thinka-original Practice Paper

2023 Cambridge IAS-Level Computer Science (9618) Practice Paper with Answers

Thinka Nov 2023 (V2) Cambridge International A Level-Style Mock — Computer Science (9618)

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

Paper 1 Theory Fundamentals

Answer all questions. Use black or dark blue pen. Calculators must not be used.
26 Question · 75 marks
Question 1 · short_answer
1.5 marks
State the minimum number of bits required to represent the denary value \(-58\) in two's complement binary, and explain why this minimum number of bits is needed.
Show answer & marking scheme

Worked solution

To represent a signed integer in two's complement using \(n\) bits, the range of representable values is \(-2^{n-1}\) to \(2^{n-1}-1\). For 6 bits, the range is \(-32\) to \(31\), which is insufficient for \(-58\). For 7 bits, the range is \(-64\) to \(63\). Therefore, the minimum number of bits required to represent \(-58\) is 7.

Marking scheme

0.5 marks: Stating 7 bits (or 7).
1.0 mark: Explaining the range for 6 bits (down to \(-32\)) and 7 bits (down to \(-64\)), demonstrating why 7 bits are mathematically required to hold \(-58\).
Question 2 · short_answer
1.5 marks
Explain why a resistive touchscreen is often preferred over a capacitive touchscreen in an industrial factory environment where operators wear heavy, non-conductive protective gloves.
Show answer & marking scheme

Worked solution

Resistive touchscreens operate by detecting physical pressure that brings two conductive layers into contact, making them responsive to any pointer (gloved hand, stylus, etc.). Capacitive touchscreens rely on the electrical charge of the human body to change the screen's electrostatic field; heavy protective gloves insulate the finger, preventing capacitive registration.

Marking scheme

0.5 marks: Stating that resistive touchscreens rely on physical pressure / contact of layers.
0.5 marks: Stating that capacitive touchscreens require electrical conductivity of the human body.
0.5 marks: Explaining that heavy gloves act as insulators, preventing capacitive touch working but allowing resistive touch via pressure.
Question 3 · short_answer
1.5 marks
During the execution of an assembly language program, an addition instruction results in the accumulator value changing from \(01111111\) (binary) to \(10000000\) (binary). State which status register flag is set by this operation, and explain why.
Show answer & marking scheme

Worked solution

In 8-bit signed two's complement, \(01111111\) represents \(+127\) (the maximum positive value). Adding 1 mathematically results in \(+128\), which cannot be represented in 8-bit signed two's complement. The bit pattern becomes \(10000000\), which represents \(-128\). Because the sign bit of the result changed from positive (0) to negative (1) during an addition of positive numbers, a signed overflow occurred, setting the Overflow flag.

Marking scheme

0.5 marks: Identifying the Overflow flag (or V flag).
1.0 mark: Explaining that adding to the maximum positive signed value (127) causes the sign bit to change to negative, which indicates a signed arithmetic overflow.
Question 4 · short_answer
1.5 marks
Define the term 'baud rate' and explain how it is possible for the 'bit rate' of a digital transmission channel to exceed its 'baud rate'.
Show answer & marking scheme

Worked solution

Baud rate measures the number of physical signal transitions or symbol changes sent down a medium per second. Bit rate is the number of bits transmitted per second. If a modulation technique encodes multiple bits per signal change (for example, using four different voltage levels to represent 2 bits per symbol), the bit rate will be higher than the baud rate.

Marking scheme

0.5 marks: Define baud rate as the number of signal or symbol changes per second.
1.0 mark: Explain that multiple bits can be encoded per signal change (e.g., via multi-level signaling, amplitude, or phase modulation) to make bit rate higher.
Question 5 · short_answer
1.5 marks
Describe the difference between a check digit and a checksum in terms of how they are calculated and used to detect errors.
Show answer & marking scheme

Worked solution

A check digit is a single digit appended to the end of a identification number (such as a barcode or product code). It is calculated using a specific algorithm (like Modulo 11) on the preceding digits to detect human data entry errors. A checksum is a numerical value calculated by summing the byte values of an entire block of data or file. It is appended to the payload and recalculated by the receiver to detect corruption introduced during transmission.

Marking scheme

0.5 marks: Check digit is calculated on a single short identification code (e.g., barcode) and appended as a single character.
0.5 marks: Checksum is calculated on an entire block of data/payload by summing up data bytes.
0.5 marks: Check digit is mainly for manual entry error detection; checksum is for automated transmission/corruption error detection.
Question 6 · short_answer
1.5 marks
Explain the role of a device driver and why it is necessary when connecting a new external peripheral to a computer system.
Show answer & marking scheme

Worked solution

A device driver is software that translates generic operating system commands (e.g., 'print document') into device-specific instructions that the particular peripheral hardware understands. It is necessary because hardware manufacturers use diverse proprietary command sets; without the driver, the operating system would not be able to communicate with or control the device.

Marking scheme

0.5 marks: Explaining that a device driver acts as a translator/interface between the OS and the hardware.
1.0 mark: Explaining that because peripherals have unique, hardware-specific command sets, the driver is necessary to convert generic OS commands into specific hardware signals.
Question 7 · short_answer
1.5 marks
In a relational database with a 1-to-many relationship between tables CUSTOMER and ORDER, explain what referential integrity is and how it is enforced when a user attempts to delete a customer.
Show answer & marking scheme

Worked solution

Referential integrity is a database property ensuring that all foreign key values match valid primary key values in the related table. If a user tries to delete a customer record that has corresponding order records in the ORDER table, referential integrity rules prevent this deletion (to avoid leaving 'orphaned' orders with a non-existent customer foreign key), or automatically delete the associated orders (cascade delete).

Marking scheme

0.5 marks: Defining referential integrity as ensuring that foreign keys always point to valid primary keys (preventing orphaned records).
1.0 mark: Describing how it is enforced during deletion (either by blocking the deletion of the parent customer if active orders exist, or performing a cascade delete).
Question 8 · short_answer
1.5 marks
Describe the difference in how system memory is handled when a large array parameter is passed 'by value' compared to 'by reference' to a subroutine.
Show answer & marking scheme

Worked solution

When an array is passed 'by value', the operating system allocates a new block of memory on the stack and copies every element of the array into it, which can be inefficient for large arrays. When passed 'by reference', only the memory address (pointer) of the original array is passed to the subroutine; the subroutine accesses the original memory location, saving memory space and execution time.

Marking scheme

0.5 marks: Explaining 'by value' duplicates the entire array in a new memory allocation.
0.5 marks: Explaining 'by reference' passes only the memory address/pointer of the original array.
0.5 marks: Stating that 'by reference' is more memory-efficient / avoids high memory usage for large arrays.
Question 9 · Short Answer
1.5 marks
In a relational database, explain the term 'composite primary key' and provide a suitable example of attributes that could form a composite primary key in a class enrollment system.
Show answer & marking scheme

Worked solution

A composite primary key is used when a single attribute is not sufficient to uniquely identify a record in a table. By combining two or more attributes (such as StudentID and ClassID), the system creates a unique identifier for every enrollment transaction, preventing duplicate entries for the same student-class pair.

Marking scheme

[1 Mark] for defining composite primary key: must mention that it consists of two or more attributes/fields that together uniquely identify a record. [0.5 Marks] for a valid example of two combined fields in a class enrollment context (e.g., StudentID and ClassID / CourseID). Reject single fields.
Question 10 · Short Answer
1.5 marks
Describe two distinct actions that occur to the Program Counter (PC) register during the Fetch stage of the fetch-decode-execute cycle.
Show answer & marking scheme

Worked solution

During the Fetch stage of the cycle, the address of the next instruction currently held in the Program Counter (PC) is placed onto the address bus and copied to the Memory Address Register (MAR). Immediately after, or during this cycle, the PC is incremented (usually by 1) so it points to the address of the subsequent instruction to be executed.

Marking scheme

[1 Mark] for stating that the value/address in the PC is copied to the Memory Address Register (MAR). [0.5 Marks] for stating that the PC is incremented (by 1) to point to the next instruction.
Question 11 · Short Answer
1.5 marks
Identify three essential functions performed by a router when managing data transmission across the internet.
Show answer & marking scheme

Worked solution

A router acts as a node connecting separate networks. It receives incoming data packets, inspects their headers to find the destination IP address, references its routing table to calculate the most efficient path, and forwards the packets toward their destination.

Marking scheme

[0.5 Marks per correct point up to 1.5 Marks] - Connects distinct/different networks together (e.g., LAN to WAN). - Receives packets and reads the destination IP address. - Forwards packets to the next node/router along the path. - Determines the most efficient route/path for packets using routing tables.
Question 12 · Short Answer
1.5 marks
Explain the purpose of utility software in a computer system and state one common example of a utility program.
Show answer & marking scheme

Worked solution

Utility software is categorized under system software. Its role is to help analyze, configure, optimize, or maintain the computer infrastructure, focusing on the underlying hardware and operating system tasks rather than user-level applications. Common examples include file compression utilities, antivirus programs, system backup software, and disk defragmenters.

Marking scheme

[1 Mark] for explaining the purpose: software designed to analyze, configure, optimize, or maintain a computer system (must mention maintenance or system optimization). [0.5 Marks] for a correct example (e.g., antivirus, disk defragmenter, backup utility, file compressor, firewall).
Question 13 · Structured Explanation
3.5 marks
Explain how the transition from standard 7-bit ASCII to variable-width Unicode (such as UTF-8) impacts both the range of characters that can be represented and the storage requirements for a plain text document.
Show answer & marking scheme

Worked solution

Unicode uses a variable-width system (1 to 4 bytes) that allows representing over 1 million distinct characters, accommodating global scripts, emojis, and technical symbols, whereas standard ASCII is restricted to 7 bits, which can only represent \( 2^7 = 128 \) characters. In terms of storage, plain text containing only basic Latin characters requires exactly the same space (1 byte per character) in both ASCII and UTF-8. However, plain text containing multi-lingual characters or symbols will see an increased file size in UTF-8, as those characters require 2 to 4 bytes each.

Marking scheme

1 mark: Explain that ASCII represents up to \( 2^7 = 128 \) characters using 7 bits, while Unicode (UTF-8) represents over 1 million characters using variable widths (1 to 4 bytes). 1 mark: State that Unicode provides native support for global languages, mathematical symbols, and emojis not present in ASCII. 1 mark: Explain that storage for standard English / basic Latin characters remains unchanged (1 byte per character). 0.5 marks: Explain that storage for non-Latin characters increases up to 4 bytes per character, resulting in larger overall file sizes.
Question 14 · Structured Explanation
3.5 marks
In a shared-medium Ethernet network, collisions can occur. Explain how the Carrier Sense Multiple Access with Collision Detection (CSMA/CD) protocol manages these collisions to ensure successful transmission.
Show answer & marking scheme

Worked solution

A device first listens to the transmission medium to check if it is idle (carrier sensing). If idle, the device begins transmitting data. While transmitting, it continuously monitors the line for a collision. If a collision is detected, the device immediately halts transmission and broadcasts a jam signal to notify all other devices on the network. Each device then waits for a random period of time (calculated using a backoff algorithm) before attempting to retransmit.

Marking scheme

1 mark: Device monitors the channel and only transmits when it is idle. 1 mark: Device continues monitoring during transmission to detect collisions immediately. 1 mark: Sends a jam signal upon detecting a collision to inform other nodes. 0.5 marks: Implements a backoff algorithm to wait a random time before attempting retransmission.
Question 15 · Structured Explanation
3.5 marks
During the Fetch stage of the Fetch-Execute cycle, instructions are retrieved from main memory. Explain how the Program Counter (PC) and the Memory Address Register (MAR) interact during this stage, and explain how the Program Counter is updated.
Show answer & marking scheme

Worked solution

At the start of the Fetch stage, the memory address stored in the Program Counter (PC) is copied to the Memory Address Register (MAR). Immediately after this, the PC is incremented by 1 (or by the instruction size) to point to the address of the next sequential instruction. The address in the MAR is then sent along the address bus to the main memory, and the data at that address is retrieved and placed into the Memory Data Register (MDR).

Marking scheme

1 mark: Value in the PC is copied to the MAR. 1 mark: PC is incremented immediately to point to the next instruction. 1 mark: Address in the MAR is sent via the address bus to locate the instruction in main memory. 0.5 marks: The fetched instruction is loaded from memory into the MDR.
Question 16 · Structured Explanation
3.5 marks
In a relational database system, explain the purpose of a foreign key and how referential integrity is maintained when a record in a parent table is deleted.
Show answer & marking scheme

Worked solution

A foreign key is an attribute in a relational database table that links to the primary key of another table, establishing a relationship between the two. Referential integrity ensures that these relationships remain consistent and that no foreign keys point to non-existent primary keys. If a record in a parent table is deleted, referential integrity is maintained either by a 'restrict' rule (preventing deletion of the parent record while dependent child records exist) or a 'cascade' rule (automatically deleting all matching records in the child table).

Marking scheme

1 mark: Defines a foreign key as a field in one table pointing to a primary key in another to link tables. 1 mark: Explains that referential integrity ensures consistency and prevents orphaned records. 1 mark: Explains the restrictive approach (blocking deletion of parent records with active child relations) OR the cascade approach (deleting corresponding child records). 0.5 marks: Gives a realistic scenario example (e.g., deleting a customer must delete or block their associated orders).
Question 17 · Structured Explanation
3.5 marks
A company wants to secure its internal communications. Compare symmetric encryption and asymmetric encryption, explaining why asymmetric encryption is more secure for key exchange over public channels, but symmetric encryption is preferred for bulk data transfer.
Show answer & marking scheme

Worked solution

Symmetric encryption uses a single shared key for both encryption and decryption, meaning the key must be shared beforehand, which poses a security risk if intercepted over a public network. Asymmetric encryption solves this by using a public key for encryption and a mathematically linked private key for decryption; the private key never needs to be shared. However, asymmetric encryption is computationally heavy and slow. Therefore, symmetric encryption is preferred for bulk data transfer because it is much faster, while asymmetric encryption is used initially to securely exchange the symmetric key.

Marking scheme

1 mark: Symmetric encryption uses a single key for both processes, posing a distribution risk. 1 mark: Asymmetric encryption uses public/private key pairs, removing the key exchange risk. 1 mark: Symmetric encryption is computationally faster and highly efficient for large datasets. 0.5 marks: Identifies the use of a hybrid system (asymmetric used to exchange symmetric session keys).
Question 18 · Structured Explanation
3.5 marks
Explain the operational differences between a compiler and an interpreter when translating high-level source code into machine code, specifically focusing on error detection and execution speed.
Show answer & marking scheme

Worked solution

A compiler translates the entire high-level source code into a standalone machine code executable (object code) in a single operation. An interpreter, however, translates and executes the source code line-by-line during runtime. For error detection, a compiler analyzes the whole program and generates an error report only after compilation fails, whereas an interpreter stops execution immediately at the first line containing an error, facilitating easier debugging. For execution speed, a compiled program runs much faster because the translation has already occurred, whereas an interpreted program runs slower because translation occurs continuously during execution.

Marking scheme

1 mark: Compiler translates whole program into object code; interpreter translates line-by-line at runtime. 1 mark: Compiler reports all errors at the end; interpreter halts instantly at the first encountered error. 1 mark: Compiled code executes faster as it does not require live translation; interpreted code is slower due to runtime translation overhead. 0.5 marks: Compiler does not require source code to run on target machine; interpreter requires both source code and the interpreter software.
Question 19 · Structured Explanation
3.5 marks
Compare the physical operation and user capabilities of resistive touch screens and capacitive touch screens.
Show answer & marking scheme

Worked solution

Resistive touch screens consist of multiple layers, including two conductive layers separated by a small gap. When pressure is applied, these layers touch, completing a circuit to register coordinates. Because it relies on physical pressure, any stylus, gloved hand, or fingernail can operate it. Capacitive touch screens consist of a glass layer coated with a transparent conductor. Touching the screen draws charge from the electrostatic field, changing the capacitance. This requires a conductive pointer, like a bare finger. Capacitive screens offer high clarity, high durability, and support multi-touch gestures (e.g., pinching), whereas resistive screens are generally single-touch and easily scratched but are highly robust in dusty or wet environments.

Marking scheme

1 mark: Resistive screens detect pressure bringing two layers into contact; capacitive screens detect changes in electrostatic field/capacitance. 1 mark: Resistive screens work with any input medium (stylus, glove); capacitive screens require conductive objects (bare fingers). 1 mark: Capacitive screens support multi-touch and have better optical clarity; resistive screens are single-touch and have lower clarity due to multiple layers. 0.5 marks: Resistive screens are cheaper but more prone to physical wear; capacitive screens are highly durable but more expensive to manufacture.
Question 20 · Structured Explanation
3.5 marks
An independent developer is deciding between licensing their new software utility under an open-source license (e.g., GNU GPL) or as proprietary commercial software. Explain the differences between these licensing models in terms of source code accessibility, modification rights, and distribution.
Show answer & marking scheme

Worked solution

Under an open-source license, the source code is made completely accessible to all users, allowing them to study how it works. Users have the legal right to modify the code to fix bugs or add features, and they can redistribute their modified versions, often under the condition that the derivative work remains open-source (copyleft). Conversely, proprietary commercial software is distributed only as compiled executable files; the source code is kept secret by the owner. Users are strictly prohibited by law from modifying, reverse engineering, or sharing the software, and distribution is tightly controlled through individual licenses or End-User License Agreements (EULAs).

Marking scheme

1 mark: Open-source provides full access to source code; proprietary hides source code and distributes only executables. 1 mark: Open-source permits and encourages modification; proprietary legally bans modifications, reverse-engineering, and copying. 1 mark: Open-source allows free redistribution (often keeping it open-source); proprietary strictly limits distribution using EULAs. 0.5 marks: Proprietary models generate direct revenue from software sales/licenses; open-source projects rely on support services, donations, or dual-licensing.
Question 21 · Structured Explanation
3 marks
Explain the role of the Program Counter (PC) and how its value changes during the fetch stage of the Fetch-Execute cycle.
Show answer & marking scheme

Worked solution

During the fetch stage of the Fetch-Execute cycle:
1. The Program Counter (PC) holds the address of the next instruction to be fetched.
2. This address is copied from the PC to the Memory Address Register (MAR) via the internal bus.
3. The Program Counter (PC) is then incremented by 1 so that it contains the address of the next sequential instruction.

Marking scheme

Award 1 mark per bullet point, up to a maximum of 3 marks:
- PC stores the address of the next instruction to be fetched / executed.
- The address stored in the PC is copied or transferred to the MAR.
- The PC is incremented (by 1) to point to the next instruction in sequence.
Question 22 · Structured Explanation
4 marks
In the context of relational databases, explain the term 'referential integrity' and describe two distinct methods a Database Management System (DBMS) can use to maintain this integrity when a record in a primary key table is deleted.
Show answer & marking scheme

Worked solution

Referential integrity is a database state where all foreign key references are valid, preventing "orphan" records in child tables. When a record in a primary key table (parent) is deleted, the DBMS must handle any records in the foreign key table (child) that reference it. Two common methods are:
- Cascade Delete: The DBMS automatically deletes all dependent records in the child table when the parent record is deleted.
- Restrict / Prohibit: The DBMS blocks the user from deleting the parent record if there are any dependent records in the child table.
- Set Null (Alternative): The DBMS sets the foreign key field to NULL in all matching child records.

Marking scheme

Award up to 4 marks:
- 1 mark: Correct definition of referential integrity (e.g., ensuring foreign keys point to valid, existing primary keys / avoiding orphan records).
- 1 mark: Correctly naming two valid methods (e.g., Cascade Delete, Restrict / Prevent, Set Null).
- 1 mark: Explaining one of the named methods accurately.
- 1 mark: Explaining the second named method accurately.
Question 23 · Diagram and Truth Table Completion
5.5 marks
An industrial process monitoring system controls an alarm output \(X\) using three inputs: \(A\) (high temperature sensor), \(B\) (high pressure sensor), and \(C\) (vibration sensor).

The Boolean expression for the logic circuit is:
\(X = (A \text{ AND } B) \text{ OR } (\text{NOT } B \text{ AND } C)\)

(a) Complete the following truth table by calculating the values for intermediate outputs \(P = A \text{ AND } B\), \(Q = \text{NOT } B \text{ AND } C\), and the final output \(X\). [4 marks]

| A | B | C | P | Q | X |
|---|---|---|---|---|---|
| 0 | 0 | 0 | | | |
| 0 | 0 | 1 | | | |
| 0 | 1 | 0 | | | |
| 0 | 1 | 1 | | | |
| 1 | 0 | 0 | | | |
| 1 | 0 | 1 | | | |
| 1 | 1 | 0 | | | |
| 1 | 1 | 1 | | | |

(b) Identify the name of each logic gate (Gate 1, Gate 2, and Gate 3) described in the circuit diagram configuration below:
- Gate 1 takes inputs \(A\) and \(B\) to produce intermediate output \(P\).
- Gate 2 takes \(NOT \ B\) and \(C\) to produce intermediate output \(Q\).
- Gate 3 takes inputs \(P\) and \(Q\) to produce final output \(X\). [1.5 marks]
Show answer & marking scheme

Worked solution

Part (a):
- Column P (\(A \text{ AND } B\)): Outputs are 1 only when both A and B are 1 (rows 7 and 8). Hence: 0, 0, 0, 0, 0, 0, 1, 1.
- Column Q (\(\text{NOT } B \text{ AND } C\)): \(\text{NOT } B\) is 1 when \(B = 0\) (rows 1, 2, 5, 6). Comparing this with column C, both are 1 only in row 2 and row 6. Hence: 0, 1, 0, 0, 0, 1, 0, 0.
- Column X (\(P \text{ OR } Q\)): Outputs 1 if either P or Q is 1. Combining columns P and Q yields: 0, 1, 0, 0, 0, 1, 1, 1.

Part (b):
- Gate 1 implements \(P = A \text{ AND } B\), so it must be an AND gate.
- Gate 2 implements the logical conjunction of \(\text{NOT } B\) and \(C\) (assuming the NOT operation on B has occurred), so it must be an AND gate.
- Gate 3 combines \(P\) and \(Q\) using logical OR, so it must be an OR gate.

Marking scheme

Part (a): Total [4 marks]
- 1 mark for correct column P values (0, 0, 0, 0, 0, 0, 1, 1).
- 1.5 marks for correct column Q values (0, 1, 0, 0, 0, 1, 0, 0). Allow 1 mark for 6 or 7 correct values.
- 1.5 marks for correct column X values (0, 1, 0, 0, 0, 1, 1, 1) based on candidate's P and Q values (follow-through allowed). Allow 1 mark for 6 or 7 correct values.

Part (b): Total [1.5 marks]
- 0.5 marks for Gate 1: AND
- 0.5 marks for Gate 2: AND
- 0.5 marks for Gate 3: OR
Question 24 · Diagram and Truth Table Completion
5.5 marks
A ventilation control system produces an output \(Y\) based on three environmental factors: \(A\) (humidity above limit), \(B\) (CO2 level above limit), and \(C\) (manual override switch active).

The logic circuit is represented by the Boolean expression:
\(Y = (A \text{ NOR } B) \text{ AND } (B \text{ XOR } C)\)

(a) Complete the truth table below by calculating the columns for \(P = A \text{ NOR } B\), \(Q = B \text{ XOR } C\), and the output \(Y\). [4 marks]

| A | B | C | P | Q | Y |
|---|---|---|---|---|---|
| 0 | 0 | 0 | | | |
| 0 | 0 | 1 | | | |
| 0 | 1 | 0 | | | |
| 0 | 1 | 1 | | | |
| 1 | 0 | 0 | | | |
| 1 | 0 | 1 | | | |
| 1 | 1 | 0 | | | |
| 1 | 1 | 1 | | | |

(b) Identify the names of the logic gates needed to directly implement the expressions for \(P\), \(Q\), and \(Y\) as single hardware components:
- Gate 1: produces \(P\) from inputs \(A\) and \(B\). [0.5 marks]
- Gate 2: produces \(Q\) from inputs \(B\) and \(C\). [0.5 marks]
- Gate 3: produces \(Y\) from inputs \(P\) and \(Q\). [0.5 marks]
Show answer & marking scheme

Worked solution

Part (a):
- Column P (\(A \text{ NOR } B\)): Outputs are 1 only when both A and B are 0 (rows 1 and 2). For all other inputs, output is 0. Hence: 1, 1, 0, 0, 0, 0, 0, 0.
- Column Q (\(B \text{ XOR } C\)): Outputs 1 if B and C have different logic states (rows 2, 3, 6, 7). Hence: 0, 1, 1, 0, 0, 1, 1, 0.
- Column Y (\(P \text{ AND } Q\)): Outputs 1 only when both P and Q are 1 (row 2). Hence: 0, 1, 0, 0, 0, 0, 0, 0.

Part (b):
- Gate 1 directly produces \(P = A \text{ NOR } B\), requiring a NOR gate.
- Gate 2 directly produces \(Q = B \text{ XOR } C\), requiring an XOR (Exclusive OR) gate.
- Gate 3 directly combines \(P\) and \(Q\) via logical conjunction, requiring an AND gate.

Marking scheme

Part (a): Total [4 marks]
- 1 mark for correct column P values (1, 1, 0, 0, 0, 0, 0, 0).
- 1.5 marks for correct column Q values (0, 1, 1, 0, 0, 1, 1, 0). Allow 1 mark for 6 or 7 correct values.
- 1.5 marks for correct column Y values (0, 1, 0, 0, 0, 0, 0, 0) based on candidate's P and Q values (follow-through allowed). Allow 1 mark for 6 or 7 correct values.

Part (b): Total [1.5 marks]
- 0.5 marks for Gate 1: NOR
- 0.5 marks for Gate 2: XOR (accept EOR / EX-OR)
- 0.5 marks for Gate 3: AND
Question 25 · Diagram and Truth Table Completion
5.5 marks
A greenhouse control panel has an output signal \(Z\) constructed from three inputs: \(A\) (low soil moisture), \(B\) (low light level), and \(C\) (heater active).

The Boolean expression is:
\(Z = \text{NOT } (A \text{ OR } B) \text{ NAND } C\)

(a) Complete the truth table below by providing the outputs for intermediate term \(P = \text{NOT } (A \text{ OR } B)\) and final output \(Z\). [4 marks]

| A | B | C | P | Z |
|---|---|---|---|---|
| 0 | 0 | 0 | | |
| 0 | 0 | 1 | | |
| 0 | 1 | 0 | | |
| 0 | 1 | 1 | | |
| 1 | 0 | 0 | | |
| 1 | 0 | 1 | | |
| 1 | 1 | 0 | | |
| 1 | 1 | 1 | | |

(b) Write down the logic gate names corresponding to the operations that generate \(P\) and \(Z\):
- Gate 1: produces \(P\) directly from inputs \(A\) and \(B\). [0.75 marks]
- Gate 2: produces \(Z\) directly from inputs \(P\) and \(C\). [0.75 marks]
Show answer & marking scheme

Worked solution

Part (a):
- Column P (\(\text{NOT } (A \text{ OR } B)\) which is equivalent to \(A \text{ NOR } B\)): Outputs 1 only when both A and B are 0 (rows 1 and 2). For all other cases, it outputs 0. Hence: 1, 1, 0, 0, 0, 0, 0, 0.
- Column Z (\(P \text{ NAND } C\)): A NAND operation outputs 0 only when both inputs (P and C) are 1. Comparing P and C, both are 1 only in row 2 (where \(P=1\) and \(C=1\)). In all other rows, the NAND operation outputs 1. Hence: 1, 0, 1, 1, 1, 1, 1, 1.

Part (b):
- Gate 1 performs \(\text{NOT } (A \text{ OR } B)\), which represents a NOR gate.
- Gate 2 performs the NAND operation on intermediate input \(P\) and input \(C\), which represents a NAND gate.

Marking scheme

Part (a): Total [4 marks]
- 1.5 marks for correct column P values (1, 1, 0, 0, 0, 0, 0, 0). Allow 1 mark for 6 or 7 correct values.
- 2.5 marks for correct column Z values (1, 0, 1, 1, 1, 1, 1, 1) based on candidate's P column (follow-through allowed). Allow 2 marks for 6 or 7 correct values, 1 mark for 4 or 5 correct values.

Part (b): Total [1.5 marks]
- 0.75 marks for Gate 1: NOR
- 0.75 marks for Gate 2: NAND
Question 26 · Diagram and Truth Table Completion
5.5 marks
An automated conveyor belt alarm system uses three inputs to trigger output alarm \(S\): \(A\) (item jam detected), \(B\) (stop button pressed), and \(C\) (power surges detected).

The Boolean expression is:
\(S = (A \text{ AND } \text{NOT } B) \text{ XOR } (B \text{ OR } C)\)

(a) Complete the truth table below by filling in intermediate columns for \(P = A \text{ AND } \text{NOT } B\), \(Q = B \text{ OR } C\), and the output \(S\). [4 marks]

| A | B | C | P | Q | S |
|---|---|---|---|---|---|
| 0 | 0 | 0 | | | |
| 0 | 0 | 1 | | | |
| 0 | 1 | 0 | | | |
| 0 | 1 | 1 | | | |
| 1 | 0 | 0 | | | |
| 1 | 0 | 1 | | | |
| 1 | 1 | 0 | | | |
| 1 | 1 | 1 | | | |

(b) Identify the minimum set of standard 2-input logic gates required to construct this system:
- List the basic gates needed to build intermediate term \(P = A \text{ AND } \text{NOT } B\). [0.5 marks]
- State the logic gate used to produce final output \(S\) from intermediate signals \(P\) and \(Q\). [1 mark]
Show answer & marking scheme

Worked solution

Part (a):
- Column P (\(A \text{ AND } \text{NOT } B\)): Outputs 1 only when \(A = 1\) and \(B = 0\) (rows 5 and 6). Hence: 0, 0, 0, 0, 1, 1, 0, 0.
- Column Q (\(B \text{ OR } C\)): Outputs 1 when either B or C is 1 (rows 2, 3, 4, 6, 7, 8). Hence: 0, 1, 1, 1, 0, 1, 1, 1.
- Column S (\(P \text{ XOR } Q\)): Outputs 1 when P and Q have different logic states. Comparing P and Q: row 1 (0, 0) -> 0; row 2 (0, 1) -> 1; row 3 (0, 1) -> 1; row 4 (0, 1) -> 1; row 5 (1, 0) -> 1; row 6 (1, 1) -> 0; row 7 (0, 1) -> 1; row 8 (0, 1) -> 1. Hence: 0, 1, 1, 1, 1, 0, 1, 1.

Part (b):
- To implement \(P = A \text{ AND } \text{NOT } B\), we require a single NOT gate to invert B, and a single 2-input AND gate to combine the inverted B with A.
- The operation combining \(P\) and \(Q\) is represented by the XOR symbol, which requires a single XOR (Exclusive-OR) gate.

Marking scheme

Part (a): Total [4 marks]
- 1 mark for correct column P values (0, 0, 0, 0, 1, 1, 0, 0).
- 1.5 marks for correct column Q values (0, 1, 1, 1, 0, 1, 1, 1). Allow 1 mark for 6 or 7 correct values.
- 1.5 marks for correct column S values (0, 1, 1, 1, 1, 0, 1, 1) based on candidate's P and Q values (follow-through allowed). Allow 1 mark for 6 or 7 correct values.

Part (b): Total [1.5 marks]
- 0.5 marks for specifying both 'one NOT gate' and 'one AND gate' (or 'NOT and AND').
- 1 mark for specifying 'XOR' (accept 'Exclusive OR' or 'EOR').

Paper 2 Fundamental Problem-solving and Programming Skills

Answer all questions. Use of the provided pseudocode insert is required.
9 Question · 49.5 marks
Question 1 · Pseudocode Writing
6.5 marks
An athletics club measures sprinters' times for a 100-metre race. Write a pseudocode function CalculateAverageSpeed that:
- Takes two parameters: an array Times (a 1D array of REAL values representing race times in seconds) and an integer NumElements representing the number of items in the array.
- Iterates through the array to find all times that are strictly less than 12.0 seconds.
- For each such time, calculates the speed using the formula: speed = 100.0 / time.
- Calculates and returns the average speed of these valid runs.
- If no runs are completed in less than 12.0 seconds, the function must return -1.0.

Write the pseudocode for the function CalculateAverageSpeed.
Show answer & marking scheme

Worked solution

The function CalculateAverageSpeed must iterate through the entire Times array up to NumElements. It initializes SumSpeed to 0.0 and Count to 0. For each valid index, it checks if Times[Index] is less than 12.0. If true, it calculates the sprinter's speed by dividing the distance (100.0) by the sprinter's time. This speed is added to SumSpeed, and the Count of valid runs is incremented by 1. After the loop, the function checks if any valid runs were found (Count > 0) to avoid division by zero. If valid runs exist, it returns SumSpeed divided by Count; otherwise, it returns -1.0.

Marking scheme

1 mark: Correct FUNCTION header (with parameters and return type) and ENDFUNCTION.
1 mark: Initialising accumulator (SumSpeed) and counter (Count) to 0 or 0.0.
1 mark: Loop through all elements from 1 to NumElements.
1 mark: Conditional check Times[Index] < 12.0.
1 mark: Calculating speed correctly (100.0 / Times[Index]), adding it to SumSpeed, and incrementing Count.
1.5 marks: Checking if Count > 0 before division to prevent division by zero, returning the correct average speed or -1.0.
Question 2 · Pseudocode Writing
6.5 marks
A software application requires product codes to follow a strict format. Write a pseudocode function ValidateCode(ProductCode : STRING) RETURNS BOOLEAN that returns TRUE if the product code is valid, and FALSE otherwise.

A product code is valid if it meets all of the following rules:
1. It must be exactly 8 characters long.
2. The first three characters must be uppercase alphabetical letters ('A' to 'Z').
3. The fourth character must be a hyphen ('-').
4. The last four characters must be numeric digits ('0' to '9').

You should assume the existence of the following built-in string manipulation functions:
- LENGTH(s : STRING) RETURNS INTEGER (returns the number of characters in the string s)
- MID(s : STRING, start : INTEGER, length : INTEGER) RETURNS STRING (returns a substring of length 'length' starting at index 'start')
- ASC(c : CHAR) RETURNS INTEGER (returns the ASCII value of character c)
Show answer & marking scheme

Worked solution

The function ValidateCode first verifies that the string has a length of exactly 8. If not, it immediately returns FALSE. Next, it loops through the first three positions (1 to 3), extracts each character, finds its ASCII value, and checks if it lies outside the range [65, 90] (representing 'A' through 'Z'). If it does, it returns FALSE. It then checks if the fourth character is a hyphen; if not, it returns FALSE. Finally, it loops through the last four positions (5 to 8), extracts each character, and checks if its ASCII value is outside the range [48, 57] (representing '0' through '9'). If all checks are successfully passed without returning FALSE, the function returns TRUE.

Marking scheme

1 mark: Correct function header and returning boolean values.
1 mark: Checking length of ProductCode is exactly 8 (returning FALSE if not).
1.5 marks: Correctly checking first 3 characters are uppercase ('A'-'Z') using a loop and ASCII ranges (65 to 90).
1 mark: Correctly checking character 4 is a hyphen "-".
1.5 marks: Correctly checking characters 5 to 8 are numeric ('0'-'9') using ASCII ranges (48 to 57).
0.5 marks: Returning TRUE if all checks pass.
Question 3 · Pseudocode Writing
6.5 marks
A theatre booking system uses a 2D array SeatingPlan of type STRING, dimensioned [1:10, 1:6] (representing 10 rows and 6 seats per row). Empty seats are represented by the string "EMPTY", while reserved seats contain the customer's name.

Write a pseudocode procedure FindAdjacentSeats() that searches the entire array and identifies any occurrences where two adjacent seats in the same row are both empty.

For each such occurrence, the procedure should output a message in the format:
"Row , Seats and are empty"
For example, if seats 3 and 4 in Row 5 are both empty, it outputs:
"Row 5, Seats 3 and 4 are empty"

Note: If seats 2, 3, and 4 are all empty, this counts as two overlapping pairs (2 and 3, and 3 and 4), and both should be output.
Show answer & marking scheme

Worked solution

The procedure utilizes nested loops to scan the 2D array SeatingPlan. The outer loop iterates through the rows 1 to 10. The inner loop iterates through the columns/seats 1 to 5. We iterate only up to seat 5 because we need to compare SeatingPlan[Row, Seat] with SeatingPlan[Row, Seat + 1]. If both are equal to "EMPTY", the procedure prints the desired format using an OUTPUT statement.

Marking scheme

1 mark: Correct PROCEDURE header and ENDPROCEDURE.
1 mark: Correct outer loop iterating through all 10 rows (1 to 10).
1.5 marks: Correct inner loop iterating through seats from 1 to 5 (to avoid out-of-bounds error when checking Seat + 1).
1.5 marks: Conditional check verifying that BOTH SeatingPlan[Row, Seat] and SeatingPlan[Row, Seat + 1] are equal to "EMPTY".
1.5 marks: Correct output statement formatting matching the specified format exactly, using the correct variables.
Question 4 · Pseudocode Writing
6.5 marks
A text file Students.txt contains records of students. For each student, three consecutive lines are written:
- First line: Student ID (e.g., "ST101")
- Second line: Class Name (e.g., "12B")
- Third line: Test Score (as a string representing an integer, e.g., "78")

Write a pseudocode procedure FilterPassedStudents(MinScore : INTEGER) that:
- Reads all student records from Students.txt.
- Determines if the student's score is greater than or equal to MinScore. (Note: Convert the string score to an integer before comparison using a built-in conversion function TONUM(s : STRING) RETURNS NUMERIC).
- For each student who meets this criteria, writes their Student ID and Test Score to a new file Passed.txt as a single comma-separated line (e.g., "ST101,78").
- Closes all files when processing is complete.

You must use standard pseudocode file handling commands (such as OPENFILE, READFILE, WRITEFILE, CLOSEFILE, and EOF).
Show answer & marking scheme

Worked solution

The procedure opens Students.txt in READ mode and Passed.txt in WRITE mode. It uses a WHILE NOT EOF("Students.txt") loop to iterate through the entire file. Inside the loop, it reads three consecutive lines into variables ID, Class, and ScoreStr. It then converts ScoreStr into a numeric format ScoreNum. If ScoreNum is greater than or equal to MinScore, it concatenates ID, a comma, and ScoreStr, then writes this line to Passed.txt. Finally, it closes both files.

Marking scheme

1 mark: Opening both files with correct modes (Students.txt for READ, Passed.txt for WRITE).
1 mark: Correct loop structure using WHILE NOT EOF("Students.txt").
1 mark: Reading exactly three lines inside the loop in correct order (ID, Class, Score).
1 mark: Converting the score to an integer using TONUM and performing the validation check ScoreNum >= MinScore.
1.5 marks: Creating a comma-separated string of ID and score, and writing it to Passed.txt.
1 mark: Closing both files outside the loop.
Question 5 · trace-table
5 marks
An algorithm is written to process an array of 5 integers. The initial state of the 1-based array Numbers is:
Numbers[1] = 12
Numbers[2] = 5
Numbers[3] = 8
Numbers[4] = 15
Numbers[5] = 3

The pseudocode is as follows:
Count <- 0
FOR Index <- 1 TO 4
IF Numbers[Index] > Numbers[Index + 1] THEN
Temp <- Numbers[Index]
Numbers[Index] <- Numbers[Index + 1]
Numbers[Index + 1] <- Temp
Count <- Count + 1
ENDIF
NEXT Index
Trace the execution of this algorithm by completing the trace table. Note: intermediate values should only be recorded when a variable's value changes.
Show answer & marking scheme

Worked solution

Let's perform the dry run step-by-step:
1. Initially, Count is set to 0. Numbers is [12, 5, 8, 15, 3].
2. Index = 1:
- Numbers[1] (12) > Numbers[2] (5) is TRUE.
- Temp <- Numbers[1] (12)
- Numbers[1] <- Numbers[2] (5)
- Numbers[2] <- Temp (12)
- Count <- Count + 1 (1)
- Current Array: [5, 12, 8, 15, 3]
3. Index = 2:
- Numbers[2] (12) > Numbers[3] (8) is TRUE.
- Temp <- Numbers[2] (12)
- Numbers[2] <- Numbers[3] (8)
- Numbers[3] <- Temp (12)
- Count <- Count + 1 (2)
- Current Array: [5, 8, 12, 15, 3]
4. Index = 3:
- Numbers[3] (12) > Numbers[4] (15) is FALSE. No swap occurs.
5. Index = 4:
- Numbers[4] (15) > Numbers[5] (3) is TRUE.
- Temp <- Numbers[4] (15)
- Numbers[4] <- Numbers[5] (3)
- Numbers[5] <- Temp (15)
- Count <- Count + 1 (3)
- Current Array: [5, 8, 12, 3, 15]
6. The loop terminates after Index = 4.

The completed trace table is:
| Index | Numbers[1] | Numbers[2] | Numbers[3] | Numbers[4] | Numbers[5] | Temp | Count |
|---|---|---|---|---|---|---|---|
| Initial | 12 | 5 | 8 | 15 | 3 | | 0 |
| 1 | 5 | 12 | | | | 12 | 1 |
| 2 | | 8 | 12 | | | 12 | 2 |
| 3 | | | | | | | |
| 4 | | | | 3 | 15 | 15 | 3 |

Marking scheme

- 1 mark for correct initial values and tracing Index from 1 to 4.
- 1 mark for correct first swap at Index = 1 (Numbers[1]=5, Numbers[2]=12, Temp=12, Count=1).
- 1 mark for correct second swap at Index = 2 (Numbers[2]=8, Numbers[3]=12, Temp=12, Count=2).
- 1 mark for identifying no changes at Index = 3.
- 1 mark for correct final swap at Index = 4 (Numbers[4]=3, Numbers[5]=15, Temp=15, Count=3).
Question 6 · trace-table
5 marks
A function ProcessString is defined as follows:
FUNCTION ProcessString(InString : STRING) RETURNS STRING
DECLARE OutString : STRING
DECLARE Length, i : INTEGER
DECLARE NextChar : CHAR
OutString <- ""
Length <- LENGTH(InString)
i <- 1
WHILE i <= Length
NextChar <- MID(InString, i, 1)
IF NextChar = 'A' OR NextChar = 'E' OR NextChar = 'I' OR NextChar = 'O' OR NextChar = 'U' THEN
OutString <- OutString & "*"
ELSE
OutString <- OutString & NextChar
ENDIF
i <- i + 2
ENDWHILE
RETURN OutString
ENDFUNCTION
Complete the trace table for the function call: ProcessString("CAMBRIDGE"). Note: MID(String, Start, Length) returns a substring starting at the 1-based index 'Start' with the specified 'Length'.
Show answer & marking scheme

Worked solution

Tracing the execution with InString = "CAMBRIDGE":
1. Length is initialized to 9. OutString is "". i is 1.
2. Iteration 1 (i = 1):
- NextChar = MID("CAMBRIDGE", 1, 1) -> 'C'.
- 'C' is not a vowel.
- OutString <- "" & 'C' -> "C".
- i <- 1 + 2 -> 3.
3. Iteration 2 (i = 3):
- NextChar = MID("CAMBRIDGE", 3, 1) -> 'M'.
- 'M' is not a vowel.
- OutString <- "C" & 'M' -> "CM".
- i <- 3 + 2 -> 5.
4. Iteration 3 (i = 5):
- NextChar = MID("CAMBRIDGE", 5, 1) -> 'R'.
- 'R' is not a vowel.
- OutString <- "CM" & 'R' -> "CMR".
- i <- 5 + 2 -> 7.
5. Iteration 4 (i = 7):
- NextChar = MID("CAMBRIDGE", 7, 1) -> 'D'.
- 'D' is not a vowel.
- OutString <- "CMR" & 'D' -> "CMRD".
- i <- 7 + 2 -> 9.
6. Iteration 5 (i = 9):
- NextChar = MID("CAMBRIDGE", 9, 1) -> 'E'.
- 'E' is a vowel.
- OutString <- "CMRD" & "*" -> "CMRD*".
- i <- 9 + 2 -> 11.
7. Loop condition i <= Length (11 <= 9) is FALSE. Loop ends.

The completed trace table is:
| i | NextChar | OutString |
|---|---|---|
| 1 | | "" |
| | 'C' | "C" |
| 3 | | |
| | 'M' | "CM" |
| 5 | | |
| | 'R' | "CMR" |
| 7 | | |
| | 'D' | "CMRD" |
| 9 | | |
| | 'E' | "CMRD*" |
| 11 | | |

Marking scheme

- 1 mark for correct increment progression of i (1, 3, 5, 7, 9, 11).
- 1 mark for correct evaluation of NextChar ('C', 'M', 'R', 'D', 'E') at odd index positions.
- 1 mark for identifying 'E' as a vowel and substituting '*' correctly.
- 1 mark for correct sequential construction of OutString ("C", "CM", "CMR", "CMRD", "CMRD*").
- 1 mark for correctly concluding the loop with final index i = 11 without running an extra iteration.
Question 7 · Data Structure Diagrams & Flowcharts
4.5 marks
A linked list is implemented using a 2D array List[0..5, 0..1] where column 0 represents Data and column 1 represents Pointer (the integer pointer to the next node). The head of the list is stored in the integer variable Start.

The initial state of the array and Start is:
- Start = 3
- List[0] = ["Fig", 5]
- List[1] = ["Kiwi", -1]
- List[2] = ["Date", 0]
- List[3] = ["Cherry", 2]
- List[4] = ["Grape", 1]
- List[5] = ["Guava", 4]

A programmer designs a flowchart logic to search for a value SearchValue:
1. Initialize CurrentPointer to Start.
2. Check if CurrentPointer is -1. If yes, output 'Not Found' and terminate.
3. Check if List[CurrentPointer, 0] equals SearchValue. If yes, output 'Found at index ' + CurrentPointer and terminate.
4. Set CurrentPointer to List[CurrentPointer, 1].
5. Repeat from Step 2.

Trace the execution of this search algorithm when SearchValue = "Grape". State the values of CurrentPointer, the comparison made, and the final output.
Show answer & marking scheme

Worked solution

Let's trace the execution steps:
- Initially, CurrentPointer is set to Start (3).
- CurrentPointer is not -1. List[3, 0] is "Cherry". "Cherry" is not "Grape".
- CurrentPointer is updated to List[3, 1] which is 2.
- CurrentPointer is not -1. List[2, 0] is "Date". "Date" is not "Grape".
- CurrentPointer is updated to List[2, 1] which is 0.
- CurrentPointer is not -1. List[0, 0] is "Fig". "Fig" is not "Grape".
- CurrentPointer is updated to List[0, 1] which is 5.
- CurrentPointer is not -1. List[5, 0] is "Guava". "Guava" is not "Grape".
- CurrentPointer is updated to List[5, 1] which is 4.
- CurrentPointer is not -1. List[4, 0] is "Grape". This matches SearchValue.
- Output "Found at index 4" and execution terminates.

Marking scheme

Total: 4.5 marks
- 1 mark: Correctly setting initial CurrentPointer to 3 and checking index 3.
- 1 mark: Correctly tracing the pointers to transition to 2 and then 0.
- 1 mark: Correctly tracing the pointers to transition to 5 and then 4.
- 1 mark: Identifying the correct matching condition at index 4.
- 0.5 marks: Stating the correct final output ('Found at index 4' or equivalent).
Question 8 · Data Structure Diagrams & Flowcharts
4.5 marks
A binary search tree stores the following names:
- Root node: "Mango"
- Left subtree of "Mango": "Cherry" (parent of "Apple" on its left, and "Date" on its right)
- Right child of "Mango": "Peach" (no children)

The tree is represented in three 1D arrays: LeftPtr, Data, and RightPtr with index 0 to 5. The root index is stored in the variable Root which contains the value 3.

The incomplete representation is:
Index | LeftPtr | Data | RightPtr
0 | -1 | "Apple" | -1
1 | [ P ] | "Cherry" | [ Q ]
2 | -1 | "Date" | -1
3 | 1 | "Mango" | 4
4 | -1 | "Peach" | -1
5 | -1 | "" | -1 (Empty)

(a) State the pointer values that should replace [ P ] and [ Q ] to correctly construct the tree.
(b) Describe the step-by-step search path (the indices of the elements visited) to search for "Date" in this binary search tree starting from the root.
Show answer & marking scheme

Worked solution

Part (a):
- 'Cherry' at index 1 has a left child 'Apple' which is at index 0. Thus, [ P ] (LeftPtr) must be 0.
- 'Cherry' at index 1 has a right child 'Date' which is at index 2. Thus, [ Q ] (RightPtr) must be 2.

Part (b):
- Start at index 3 (Data: 'Mango'). Since 'Date' is alphabetically smaller than 'Mango' (D < M), follow LeftPtr of index 3, which points to index 1.
- At index 1 (Data: 'Cherry'), since 'Date' is alphabetically larger than 'Cherry' (D > C), follow RightPtr of index 1, which points to index 2.
- At index 2 (Data: 'Date'), 'Date' matches the search value. The search ends successfully.
- The path of indices visited is: 3, 1, 2.

Marking scheme

Total: 4.5 marks
(a) Pointer values (2 marks):
- 1 mark: [ P ] = 0
- 1 mark: [ Q ] = 2

(b) Search path (2.5 marks):
- 0.5 marks: Stating index 3 is visited first (Root).
- 1 mark: Comparing 'Date' with 'Mango' and correctly choosing LeftPtr to visit index 1.
- 1 mark: Comparing 'Date' with 'Cherry' and correctly choosing RightPtr to visit index 2.
Question 9 · Data Structure Diagrams & Flowcharts
4.5 marks
A linear queue is implemented as a 1D array of size 10, called QueueList[1:10]. Two pointers, HeadPointer and TailPointer, are used to keep track of the items. Initially, HeadPointer = 0 and TailPointer = 0.

The algorithm for inserting a new item, NewItem, is described below:
- If TailPointer is equal to 10, output 'Queue Full'.
- Otherwise, if TailPointer is 0 (queue is empty), set HeadPointer to 1, TailPointer to 1, and store NewItem in QueueList[TailPointer].
- Otherwise, increment TailPointer by 1 and store NewItem in QueueList[TailPointer].

(a) Identify the condition that prevents an item from being added to this queue when it reaches its physical limit.
(b) Explain the limitation of this linear queue design when items are repeatedly enqueued and dequeued, and describe how a circular queue modification addresses this issue.
Show answer & marking scheme

Worked solution

Part (a):
The condition 'TailPointer = 10' checks if the last element in the queue has reached the maximum upper bound of the array.

Part (b):
- Limitation: Dequeue operations remove items from the front by incrementing HeadPointer. This leaves empty, unused slots at the start of the array. Because the linear enqueue operation only increments TailPointer, once TailPointer reaches 10, no more items can be added, regardless of how many empty slots exist at the start of the array. This is known as false overflow.
- Circular Queue: A circular queue addresses this by wrapping pointers back to index 1 when they exceed index 10 (often implemented using modulo arithmetic, e.g., TailPointer = (TailPointer MOD 10) + 1). This allows the empty slots at the front of the array to be reused dynamically.

Marking scheme

Total: 4.5 marks
(a) Condition (1 mark):
- 1 mark: Identifies TailPointer = 10 (or equivalent syntax indicating upper boundary check).

(b) Limitation and Resolution (3.5 marks):
- 1 mark: Explains that dequeueing increments HeadPointer, leaving unused empty slots at lower array indices.
- 1 mark: Explains that TailPointer only increments, so it eventually hits the limit (10) and prevents insertions, causing a false overflow.
- 1.5 marks: Explains that a circular queue resolves this by wrapping the pointer around to the start (using modulo or checking index bounds) to reuse those empty slots.

Wondering how well you actually know this?

Thinka is an AI practice app for DSE students — unlimited questions, instant auto-marking, and detailed step-by-step solutions. 100,000+ students use it to confirm they actually know it, not just think they do.

Want more questions like this? Practice unlimited on Thinka — instant answers included.

Start Practising Free