An original Thinka practice paper modelled on the structure and difficulty of the Jun 2024 (V3) Cambridge International A Level Computer Science (9618) paper. Not affiliated with or reproduced from Cambridge.
Paper 1 - Theory Fundamentals
Answer all questions. Show your working where appropriate. Calculators must not be used.
(a) Convert the denary value \(-58.375\) into a 12-bit signed fixed-point binary representation. Use 8 bits for the integer part and 4 bits for the fractional part, both using two's complement. Show your working. [4]
(b) A sound engineer records a mono audio track. The recording parameters are: - Sampling rate: \(32 \text{ kHz}\) (32,000 Hz) - Bit depth: 16 bits - Duration: 24 seconds
Calculate the final file size of this uncompressed audio track in Kibibytes (KiB), where \(1 \text{ KiB} = 1024 \text{ bytes}\). Show your working. [5]
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Part (a): 1. Convert the absolute denary integer part (58) to 8-bit unsigned binary: \(58 = 32 + 16 + 8 + 2 = 00111010_2\) 2. Convert the fractional part (0.375) to 4-bit unsigned binary: \(0.375 = 0.25 + 0.125 = 2^{-2} + 2^{-3} = 0110_2\) 3. Combine them to get the positive representation: \(58.375 = 00111010.0110_2\) 4. Convert to two's complement to represent the negative value: - One's complement: \(11000101.1001_2\) - Add the Least Significant Bit (\(2^{-4}\)): \(11000101.1001 + 0.0001 = 11000101.1010_2\) Verification: \(-128 + 64 + 4 + 1 + 0.5 + 0.125 = -58.375\). The final 12-bit binary representation is: `11000101.1010` (or `110001011010`).
Part (a) [4 Marks]: - 1 mark for converting positive integer part to binary (00111010) or equivalent working. - 1 mark for converting positive fractional part to binary (0110) or equivalent working. - 1 mark for showing correct combined positive value (00111010.0110). - 1 mark for correct final 12-bit two's complement value: 11000101.1010 (accept without dot: 110001011010).
Part (b) [5 Marks]: - 1 mark for showing multiplication of sample rate, bit depth, and duration (e.g., 32,000 * 16 * 24). - 1 mark for indicating mono / 1 channel (implicit or explicit in formula). - 1 mark for converting bits to bytes (dividing by 8) to get 1,536,000 bytes. - 1 mark for dividing the byte value by 1024. - 1 mark for correct final answer with units: 1500 KiB (accept 1500).
(a) A bitmap image has the following properties: - Image resolution: \(512 \times 400\) pixels - Colour depth: 16 bits per pixel - File header size: 2,048 bytes
Calculate the total file size of the bitmap image in Kibibytes (KiB). Show your working. [5]
(b) A single 8-pixel horizontal row of a 24-bit RGB bitmap image has the following pixel values represented in hexadecimal: `FFFFFF`, `FFFFFF`, `FFFFFF`, `000000`, `000000`, `FF0000`, `FF0000`, `FF0000`
(i) Show the Run-Length Encoding (RLE) representation for this row of pixels. [2] (ii) State whether RLE is a lossy or lossless compression method, and explain how the given row of pixels justifies the use of RLE. [2]
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Part (a): 1. Calculate total number of pixels in the image: \(512 \times 400 = 204,800 \text{ pixels}\) 2. Calculate the size of the image pixel data in bits: \(204,800 \times 16 \text{ bits} = 3,276,800 \text{ bits}\) 3. Convert image pixel data from bits to bytes: \(3,276,800 / 8 = 409,600 \text{ bytes}\) (Alternatively: 16 bits = 2 bytes per pixel, so \(204,800 \times 2 = 409,600 \text{ bytes}\)) 4. Add the file header size to get the total file size in bytes: \(409,600 \text{ bytes} + 2,048 \text{ bytes} = 411,648 \text{ bytes}\) 5. Convert total bytes to KiB: \(411,648 / 1024 = 402 \text{ KiB}\).
Part (b): (i) Run-Length Encoding groups consecutive identical pixels together as a count and value pair: - 3 pixels of `FFFFFF` -> `3 FFFFFF` - 2 pixels of `000000` -> `2 000000` - 3 pixels of `FF0000` -> `3 FF0000` Combined representation: `3 FFFFFF, 2 000000, 3 FF0000` (or equivalent notation like `(3, FFFFFF), (2, 000000), (3, FF0000)`).
(ii) RLE is a lossless compression method. It is justified here because there are long "runs" of consecutive identical pixels, which significantly reduces the amount of storage required without losing any of the original data when uncompressed.
PastPaper.markingScheme
Part (a) [5 Marks]: - 1 mark for calculating total pixels: 204,800 pixels. - 1 mark for multiplying pixels by colour depth to find size in bits (3,276,800 bits) or calculating bytes per pixel (2 bytes). - 1 mark for calculating correct image data size in bytes (409,600 bytes). - 1 mark for adding the header size of 2,048 bytes (411,648 bytes). - 1 mark for correct final answer: 402 KiB (unit required, accept 402).
Part (b)(i) [2 Marks]: - 1 mark for identifying the correct counts (3, 2, 3) in sequence. - 1 mark for correctly matching the counts with the corresponding hex values in order (e.g., 3 FFFFFF, 2 000000, 3 FF0000).
Part (b)(ii) [2 Marks]: - 1 mark for stating "lossless". - 1 mark for explaining that the image row contains consecutive repeating pixel values (runs) which compression can reduce without losing any original detail/data.
The following is a section of assembly language program for a processor with a single accumulator (ACC). The instruction set is standard: LDM #n (load immediate), LDD (load direct), STO (store), ADD (add direct), SUB (subtract direct), CMP #n (compare ACC to n), and JPN (jump to label if not equal).
LDM #0 STO 150 LDM #4 STO 151 LDM #1 STO 152 loop: LDD 150 ADD 151 STO 150 LDD 151 SUB 152 STO 151 CMP #1 JPN loop END
Complete the trace table below to show the execution of the program. Use a new row each time a variable changes. Note that memory location 152 is initialized to 1 and does not change.
Step-by-step trace of the assembly program: 1. LDM #0 loads 0 into ACC. 2. STO 150 stores 0 into memory location 150. 3. LDM #4 loads 4 into ACC. 4. STO 151 stores 4 into memory location 151. 5. LDM #1 loads 1 into ACC. 6. STO 152 stores 1 into memory location 152. 7. Loop starts: - LDD 150 loads 0 into ACC. - ADD 151 adds 4 to ACC (ACC = 4). - STO 150 stores 4 in location 150. - LDD 151 loads 4 into ACC. - SUB 152 subtracts 1 from ACC (ACC = 3). - STO 151 stores 3 in location 151. - CMP #1 compares ACC (3) with 1 (not equal). - JPN loop jumps back to loop.
8. Iteration 2: - LDD 150 loads 4 into ACC. - ADD 151 adds 3 to ACC (ACC = 7). - STO 150 stores 7. - LDD 151 loads 3 into ACC. - SUB 152 subtracts 1 (ACC = 2). - STO 151 stores 2. - CMP #1 compares 2 with 1 (not equal). - JPN loop jumps back.
9. Iteration 3: - LDD 150 loads 7 into ACC. - ADD 151 adds 2 to ACC (ACC = 9). - STO 150 stores 9. - LDD 151 loads 2 into ACC. - SUB 152 subtracts 1 (ACC = 1). - STO 151 stores 1. - CMP #1 compares 1 with 1 (equal). - JPN loop does not jump because the condition is false. - END terminates execution.
PastPaper.markingScheme
Award 1 mark for each of the following points up to a maximum of 5: 1. Correctly shows initial loading of memory locations 150 (0) and 151 (4). 2. Correctly traces the first iteration: Memory [150] = 4, Memory [151] = 3. 3. Correctly traces the second iteration: Memory [150] = 7, Memory [151] = 2. 4. Correctly traces the third iteration: Memory [150] = 9, Memory [151] = 1. 5. Correctly terminates the loop on CMP #1 without jumping back to loop, leaving ACC at 1, Memory [150] at 9, and Memory [151] at 1.
An 8-bit status register in a manufacturing unit holds sensory information. The bits are numbered 0 to 7 from right (least significant) to left (most significant). - Bits 0 to 3: 4-bit temperature code - Bit 4: Door status (1 = open, 0 = closed) - Bit 5: Heater status (1 = active, 0 = inactive) - Bits 6 & 7: Unused (always 0)
The register currently contains the binary value: 00111010
(a) Determine the current door status, heater status, and the denary value of the temperature code. [3 marks] (b) Write an assembly instruction, including an appropriate binary mask, to toggle the heater status (Bit 5) while keeping all other bits unchanged. [2 marks]
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
For part (a): Identify the positions in the 8-bit binary value 00111010: - Bit 7: 0 - Bit 6: 0 - Bit 5: 1 (Heater is active) - Bit 4: 1 (Door is open) - Bits 3 to 0: 1010 (Temperature code) Convert binary 1010 to denary: (1 * 8) + (0 * 4) + (1 * 2) + (0 * 1) = 10.
For part (b): To toggle a specific bit while leaving others unchanged, we perform a bitwise XOR operation. The bit mask needs a 1 at the bit position we want to change (Bit 5) and 0s elsewhere: Bit position: 7 6 5 4 3 2 1 0 Mask: 0 0 1 0 0 0 0 0 (which is B00100000 or 32 in denary). The standard assembly instruction to achieve this is: XOR #B00100000 (or XOR #32).
PastPaper.markingScheme
(a) 1 mark for identifying Door status as open / 1. 1 mark for identifying Heater status as active / 1. 1 mark for calculating the correct temperature code as 10 (denary). (b) 1 mark for using XOR / bitwise XOR operation. 1 mark for correct mask: B00100000 (or binary equivalent / denary 32 / hex &20).
PastPaper.question 5 · structured
14 PastPaper.marks
A local sports club uses a relational database to manage tournament registrations. The database contains three tables:
(a) Write SQL DDL commands to create the REGISTRATION table. PlayerID and TournamentID must be defined as foreign keys referencing their respective parent tables, and together they must form the composite primary key. Assume PlayerID is VARCHAR(5), TournamentID is VARCHAR(4), RegistrationDate is DATE, and Paid is BOOLEAN. [4]
(b) Write an SQL query to display the FirstName, LastName, and TournamentName of all players who have registered for a tournament held in the location 'Birmingham' and whose Paid status is TRUE. The results must be sorted alphabetically by the player's LastName. [5]
(c) Write an SQL query to change the Paid status to TRUE for player 'PL094' registered for tournament 'TN05'. [2]
(d) Explain how referential integrity is maintained by a database management system (DBMS) when a user attempts to delete a record from the PLAYER table. [3]
Part (b): SELECT PLAYER.FirstName, PLAYER.LastName, TOURNAMENT.TournamentName FROM REGISTRATION INNER JOIN PLAYER ON REGISTRATION.PlayerID = PLAYER.PlayerID INNER JOIN TOURNAMENT ON REGISTRATION.TournamentID = TOURNAMENT.TournamentID WHERE TOURNAMENT.Location = 'Birmingham' AND REGISTRATION.Paid = TRUE ORDER BY PLAYER.LastName;
(Alternative valid SQL syntax): SELECT FirstName, LastName, TournamentName FROM PLAYER, TOURNAMENT, REGISTRATION WHERE PLAYER.PlayerID = REGISTRATION.PlayerID AND TOURNAMENT.TournamentID = REGISTRATION.TournamentID AND Location = 'Birmingham' AND Paid = TRUE ORDER BY LastName;
Part (c): UPDATE REGISTRATION SET Paid = TRUE WHERE PlayerID = 'PL094' AND TournamentID = 'TN05';
Part (d): Referential integrity ensures that relationships between tables remain consistent and that foreign key values always point to valid, existing primary keys in parent tables. When a user attempts to delete a record in the PLAYER table, the DBMS checks the REGISTRATION table (the child table) for any matching PlayerID records. To prevent 'orphaned' registrations, the DBMS will either: 1. Prevent/restrict the deletion of the player record and return an error. 2. Cascade the deletion, which automatically deletes all associated records in the REGISTRATION table.
PastPaper.markingScheme
Part (a): [Max 4 marks] - 1 mark: Correct CREATE TABLE statement with correct columns and data types. - 1 mark: Correct definition of the composite primary key: PRIMARY KEY (PlayerID, TournamentID). - 1 mark: Correct foreign key constraint for PlayerID referencing PLAYER(PlayerID). - 1 mark: Correct foreign key constraint for TournamentID referencing TOURNAMENT(TournamentID).
Part (b): [Max 5 marks] - 1 mark: Correct SELECT clause with FirstName, LastName, and TournamentName. - 1 mark: Correct FROM clause identifying all three tables (using joins or a list of tables). - 1 mark: Correct join conditions linking PlayerID and TournamentID across the tables. - 1 mark: Correct search criteria: Location = 'Birmingham' AND Paid = TRUE (accept Paid = 1 or Paid = 'TRUE'). - 1 mark: Correct ORDER BY clause (LastName or PLAYER.LastName, ASC is optional as it is default).
Part (c): [Max 2 marks] - 1 mark: Correct UPDATE statement updating the correct table and column (UPDATE REGISTRATION SET Paid = TRUE). - 1 mark: Correct filter criteria (WHERE PlayerID = 'PL094' AND TournamentID = 'TN05').
Part (d): [Max 3 marks] - 1 mark: Explaining the purpose of referential integrity (e.g. to prevent orphaned records / ensure foreign keys reference valid primary keys). - 1 mark: Explaining that the DBMS inspects the foreign key relation in the child table (REGISTRATION) before allowing deletion in the parent table (PLAYER). - 1 mark: Explaining the outcome / resolution policy (e.g. restricting the delete action, or cascade-deleting the dependent records).
PastPaper.question 6 · theory
12 PastPaper.marks
A software design startup is setting up its local area network (LAN) and needs to choose its architecture and configure its subnetting.
(a) Describe two differences between a thin-client network architecture and a thick-client network architecture in terms of processing and software installation. [4]
(b) One of the workstations on the network is assigned the IP address \(192.168.10.45\) with a subnet mask of \(255.255.255.240\).
(i) Calculate the Network ID (subnet address) for this subnet. Show your working. [3]
(ii) State the range of valid IP addresses that can be allocated to host devices on this subnet. [2]
(c) The LAN is connected to the internet. Describe the functions of the following two pieces of hardware: - Router - Network Interface Card (NIC) [3]
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Part (a) - Processing: In a thin-client architecture, processing is done primarily on the central server, whereas in a thick-client architecture, processing is done locally on the client workstation's CPU. - Software Installation: In a thin-client architecture, software is installed and run directly on the central server, whereas in a thick-client architecture, software is installed locally on the client's hard drive.
Part (b)(i) - Convert the last octet of the IP address (45) to binary: \(00101101_2\) - Convert the last octet of the subnet mask (240) to binary: \(11110000_2\) - Perform a bitwise AND operation on these two values: \(00101101_2\) AND \(11110000_2 = 00100000_2\) (which is 32 in decimal). - Thus, the Network ID is \(192.168.10.32\).
Part (b)(ii) - The first assignable host address is Network ID + 1: \(192.168.10.33\) - The next subnet starts at \(192.168.10.48\), meaning the broadcast address of the current subnet is \(192.168.10.47\). - The last assignable host address is Broadcast Address - 1: \(192.168.10.46\) - The range of valid host IP addresses is \(192.168.10.33\) to \(192.168.10.46\).
Part (c) - Router: Receives data packets from a network, reads the destination IP address, and uses routing tables to forward packets across different networks toward their destination. - Network Interface Card (NIC): Provides a physical connection between the workstation and the network media (cabled or wireless) and contains the unique hardware MAC address used for identification on the local network.
PastPaper.markingScheme
Part (a) [Max 4 marks]: - 1 mark: Thin-client processing occurs on the central server. - 1 mark: Thin-client software is installed/managed centrally on the server. - 1 mark: Thick-client processing occurs locally on the client machine. - 1 mark: Thick-client software is installed locally on individual client machines.
Part (b)(i) [3 marks]: - 1 mark: Correct binary representation of the octet 45 (\(00101101_2\)) or equivalent logical working. - 1 mark: Correct binary representation of the mask octet 240 (\(11110000_2\)) or equivalent block-size identification (size is 16). - 1 mark: Correct final Network ID (\(192.168.10.32\)).
Part (b)(ii) [2 marks]: - 1 mark: Correct start of range (\(192.168.10.33\)). - 1 mark: Correct end of range (\(192.168.10.46\)). - Note: Reject ranges including .32 (Network ID) or .47 (Broadcast address).
Part (c) [Max 3 marks]: - 1 mark: Router routes/forwards data packets across different networks. - 1 mark: Router uses logical IP addresses to determine the path of packets. - 1 mark: NIC provides physical/wireless connectivity between the hardware and the network media. - 1 mark: NIC provides/stores the device's unique physical MAC address.
PastPaper.question 7 · theory
12 PastPaper.marks
An operating system (OS) performs key management tasks to coordinate the resources of a computer system.
(a) Describe how the operating system manages: (i) Memory management [3] (ii) Process management (using a scheduling algorithm) [3]
(b) During the execution of processes, peripheral devices may trigger interrupts. (i) Explain the sequence of steps the processor takes when an interrupt is detected. [4] (ii) State two reasons why a printer might generate an interrupt. [2]
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Part (a)(i) - Keeps track of which blocks of memory are currently allocated to programs and which are free. - Allocates memory space to processes when they are loaded into RAM. - Implements virtual memory (such as paging or segmentation) to allow processes to execute when physical RAM is insufficient. - Protects memory space to prevent one program from overwriting or reading data belonging to another process or the OS.
Part (a)(ii) - Uses a scheduling algorithm (e.g., Round-Robin, First-In-First-Out, or Priority-based) to decide which process gets CPU time. - Allocates CPU time slices to active processes to allow multi-tasking. - Handles context switching, which involves saving the state of the currently executing process and loading the state of the next scheduled process.
Part (b)(i) - At the end of each fetch-execute cycle, the CPU checks if an interrupt flag has been set. - If an interrupt is present, the processor suspends execution of the current process. - The current register values (including the Program Counter) are saved onto a system stack. - The processor identifies the source of the interrupt and loads the start address of the appropriate Interrupt Service Routine (ISR) into the Program Counter. - After the ISR has run, the saved register values and the Program Counter are popped off the stack, and the original process resumes.
Part (b)(ii) - The printer has run out of paper or experienced a paper jam. - The printer's internal buffer is empty and it is ready to receive more data from the CPU.
PastPaper.markingScheme
Part (a)(i) [Max 3 marks]: - 1 mark: Allocating/deallocating memory to active processes. - 1 mark: Protecting memory space (preventing unauthorized memory access by processes). - 1 mark: Managing virtual memory (paging/segmentation). - 1 mark: Keeping track of allocated/free memory blocks.
Part (a)(ii) [Max 3 marks]: - 1 mark: Uses a scheduling algorithm to determine priority/execution order. - 1 mark: Allocates CPU time slices to active processes. - 1 mark: Handles context switching (saving process states/registers). - 1 mark: Manages process states (ready, running, blocked).
Part (b)(i) [Max 4 marks]: - 1 mark: CPU checks for interrupts at the end of each instruction cycle. - 1 mark: CPU suspends current process and saves registers/PC to the stack. - 1 mark: CPU loads the start address of the Interrupt Service Routine (ISR) / interrupt handler. - 1 mark: Once complete, CPU restores the registers/PC from the stack and resumes the interrupted program.
Part (b)(ii) [2 marks]: - 1 mark per valid reason, for example: * Out of paper / paper jam. * Out of ink/toner. * Buffer empty (ready to receive more print data). * Printer offline/hardware error.
PastPaper.question 8 · theory
12 PastPaper.marks
Data integrity is essential when transmitting data over local and wide area networks.
(a) Distinguish between the terms 'data security' and 'data integrity', providing an example mechanism used to achieve each. [4]
(b) A computer system transmits blocks of data using a two-dimensional parity check with even parity. The rightmost column contains the parity bit for each byte, and the final row contains the block parity bits for each column.
The following block is received with a single-bit transmission error: ``` Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Parity Bit Byte 1 1 0 1 1 0 1 0 0 Byte 2 0 1 1 0 1 1 1 1 Byte 3 1 1 0 0 0 0 1 0 Byte 4 0 1 0 1 1 0 1 0 Parity 0 1 0 0 1 0 1 1 ``` (i) Identify the exact location of the corrupted bit (state the Byte number and Bit number) and explain how you arrived at this conclusion. [3]
(ii) State the correct binary pattern for Byte 3 (including its parity bit). [1]
(c) Another method of maintaining data integrity is using a checksum. Describe how a checksum is calculated and used to detect errors in transmitted data. [4]
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Part (a) - Data security is the protection of data against unauthorized access, theft, or corruption. Example: Encryption, firewalls, user permissions. - Data integrity is the assurance that data remains accurate, complete, and consistent during storage and transmission. Example: Parity check, validation, checksum.
Part (b)(i) - The error is located at Byte 3, Bit 5. - Explanation: * Row Check: Sum of 1s in Byte 3 is 3 (1 + 1 + 0 + 0 + 0 + 0 + 1 + 0 = 3). This is odd, violating the even parity rule. * Column Check: Sum of 1s in the Bit 5 column is 3 (0 + 1 + 0 + 1 + 1 = 3). This is odd, violating the even parity rule. * The intersection of the invalid row (Byte 3) and invalid column (Bit 5) identifies the corrupted bit.
Part (b)(ii) - Since the original bit was 0, flipping it back gives the correct Byte 3 pattern: `1 1 0 0 1 0 1 0`.
Part (c) - Prior to transmission, the sender calculates a checksum value based on the data block using a specific mathematical algorithm. - The calculated checksum value is appended to the data block and transmitted with it. - On receipt, the receiver runs the same algorithm on the received data to calculate its own checksum value. - The receiver compares its calculated checksum with the received checksum. If they match, the transmission is assumed error-free; if they do not match, an error is detected, and the receiver requests retransmission.
PastPaper.markingScheme
Part (a) [4 marks]: - 1 mark: Definition of data security (protection against unauthorized access/theft). - 1 mark: Valid example of data security (e.g., firewall, access rights, encryption). - 1 mark: Definition of data integrity (ensuring accuracy, consistency, and completeness of data). - 1 mark: Valid example of data integrity (e.g., checksum, validation, verification, parity check).
Part (b)(i) [3 marks]: - 1 mark: Correctly identifies the location of the corrupted bit (Byte 3, Bit 5). - 1 mark: Explains that Byte 3 has an odd number of 1s (violating even parity). - 1 mark: Explains that Bit 5 has an odd number of 1s (violating even parity).
Part (b)(ii) [1 mark]: - 1 mark: Correct binary pattern `1 1 0 0 1 0 1 0` (all 8 bits must be correct).
Part (c) [Max 4 marks]: - 1 mark: Sender calculates a checksum from the data block using a specific algorithm. - 1 mark: Calculated checksum is transmitted along with the data block. - 1 mark: Receiver applies the same algorithm to the received data to recalculate the checksum. - 1 mark: Receiver compares both checksum values; a mismatch signals a transmission error, resulting in a request for retransmission.
Paper 2 - Fundamental Problem-solving and Programming Skills
Answer all questions on the question paper. Refer to the insert for built-in pseudocode resources.
An algorithm is designed to process a 1D array of integers to find the maximum absolute difference between any two consecutive elements. The pseudocode for the function MaxDiff is defined below:
FUNCTION MaxDiff(List : ARRAY, Size : INTEGER) RETURNS INTEGER DECLARE MaxDifference : INTEGER DECLARE Diff : INTEGER DECLARE I : INTEGER MaxDifference <- -1 FOR I <- 1 TO Size - 1 IF List[I] > List[I+1] THEN Diff <- List[I] - List[I+1] ELSE Diff <- List[I+1] - List[I] ENDIF IF Diff > MaxDifference THEN MaxDifference <- Diff ENDIF NEXT I RETURN MaxDifference ENDFUNCTION
The 1-indexed array 'List' contains the following elements: Index: 1, 2, 3, 4, 5, 6 Value: 12, 18, 15, 9, 23, 10 And 'Size' is 6.
Complete the trace table below for the execution of the function call MaxDiff(List, 6) and state the final returned value and the purpose of the function.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Let's perform the step-by-step trace:
Initial state: MaxDifference = -1
Iteration 1 (I = 1): - List[1] is 12, List[2] is 18. - List[1] > List[2] is False. - Diff = 18 - 12 = 6. - Diff > MaxDifference (6 > -1) is True. MaxDifference becomes 6.
Iteration 2 (I = 2): - List[2] is 18, List[3] is 15. - List[2] > List[3] is True. - Diff = 18 - 15 = 3. - Diff > MaxDifference (3 > 6) is False. MaxDifference remains 6.
Iteration 3 (I = 3): - List[3] is 15, List[4] is 9. - List[3] > List[4] is True. - Diff = 15 - 9 = 6. - Diff > MaxDifference (6 > 6) is False. MaxDifference remains 6.
Iteration 4 (I = 4): - List[4] is 9, List[5] is 23. - List[4] > List[5] is False. - Diff = 23 - 9 = 14. - Diff > MaxDifference (14 > 6) is True. MaxDifference becomes 14.
Iteration 5 (I = 5): - List[5] is 23, List[6] is 10. - List[5] > List[6] is True. - Diff = 23 - 10 = 13. - Diff > MaxDifference (13 > 14) is False. MaxDifference remains 14.
The loop ends as I reaches Size - 1 (5). The function returns MaxDifference, which is 14.
The purpose of the function is to determine the maximum absolute difference between any two consecutive elements in a given array.
PastPaper.markingScheme
Trace Table Marks (4 Marks total): - 1 mark: Correct values for I = 1 (Diff = 6, MaxDifference = 6). - 1 mark: Correct values for I = 2 and I = 3 (Diff = 3 and 6, MaxDifference = 6). - 1 mark: Correct values for I = 4 (Diff = 14, MaxDifference = 14). - 1 mark: Correct values for I = 5 (Diff = 13, MaxDifference = 14).
Output/Purpose Marks (2 Marks total): - 1 mark: Correct returned value of 14. - 1 mark: Clear description of the function's purpose (calculates/returns the maximum difference between adjacent/consecutive elements).
An algorithm is designed to perform a binary search on a 1-indexed sorted 1D array of strings named 'Names', containing 'N' elements. The pseudocode contains three blank lines (labelled Line A, Line B, and Line C) representing missing statements.
FUNCTION BinarySearch(SearchValue : STRING, N : INTEGER) RETURNS INTEGER DECLARE Low : INTEGER DECLARE High : INTEGER DECLARE Mid : INTEGER DECLARE Found : BOOLEAN Low <- 1 High <- N Found <- FALSE WHILE (Low <= High) AND (Found = FALSE) Mid <- (Low + High) DIV 2 IF Names[Mid] = SearchValue THEN Found <- TRUE ELSE IF Names[Mid] < SearchValue THEN // Line A ELSE // Line B ENDIF ENDIF ENDWHILE IF Found = TRUE THEN RETURN Mid ELSE // Line C ENDIF ENDFUNCTION
Identify the correct pseudocode statements to replace Line A, Line B, and Line C to ensure the binary search works correctly.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
To implement a binary search algorithm correctly: 1. If the value at the current middle index (`Names[Mid]`) is less than the target value (`SearchValue`), the search range must be restricted to the upper half. Thus, the lower boundary (`Low`) must be updated to one index past the middle: `Low <- Mid + 1` (Line A). 2. If the value at the current middle index is greater than the target value, the search range must be restricted to the lower half. Thus, the upper boundary (`High`) must be updated to one index before the middle: `High <- Mid - 1` (Line B). 3. If the search term is not found, the function must exit and indicate that the item was not found. Since the array is 1-indexed, returning a non-positive integer like `-1` or `0` represents a standard 'not found' status indicator: `RETURN -1` or `RETURN 0` (Line C).
PastPaper.markingScheme
Line A (2 Marks): - 1 mark: Identifying that `Low` must be updated. - 1 mark: Correct adjustment calculation `Mid + 1`.
Line B (2 Marks): - 1 mark: Identifying that `High` must be updated. - 1 mark: Correct adjustment calculation `Mid - 1`.
Line C (2 Marks): - 1 mark: Using the keyword `RETURN`. - 1 mark: Returning an appropriate sentinel value indicating not found (e.g. -1 or 0).
A sequence detector algorithm is modeled using a Finite State Machine (FSM) to validate whether a binary sequence contains the pattern '101'. The FSM starts in state S0. If the full sequence '101' is successfully detected, it transitions to and stays in state S3 (the success state).
The input to the FSM can only be the characters '0' or '1'.
Complete the following state-transition table by identifying the destination states for the labels A, B, C, D, E, and F.
Let's analyze the transitions required to match the sequence '101': - State S0 is the starting state (no matched digits). - If input is '0', we stay in state S0 (Cell A = S0). - If input is '1', we have found the first correct character. We transition to S1 (Cell B = S1). - State S1 means we have matched the first digit '1'. - If input is '0', we now have '10'. This is progress. We transition to S2 (Cell C = S2). - If input is '1', the sequence is restarted but we still have a '1' at the start of our search. We stay in S1 (Cell D = S1). - State S2 means we have matched '10'. - If input is '0', our sequence is broken ('100'). We must go back to S0 (Cell E = S0). - If input is '1', the sequence '101' is completed. We transition to S3 (Cell F = S3).
PastPaper.markingScheme
Award 1 mark for each correctly identified cell transition: - 1 mark: Cell A is S0 - 1 mark: Cell B is S1 - 1 mark: Cell C is S2 - 1 mark: Cell D is S1 - 1 mark: Cell E is S0 - 1 mark: Cell F is S3
PastPaper.question 4 · written
5 PastPaper.marks
An algorithm is represented by the flowchart-style steps below:
1. Start 2. Input X 3. Set Y = 1, Z = 0 4. If X > Y is False, go to Step 8 5. Set X = X - Y 6. Set Y = Y + 2, Z = Z + 1 7. Go to Step 4 8. Output X, Y, Z 9. End
Complete the trace table for the execution of this algorithm when the input value of X is 24.
- 1 mark: Correctly initializing Y to 1 and Z to 0. - 1 mark: Correctly updating the X column values (23, 20, 15, 8) in sequence. - 1 mark: Correctly updating the Y column (3, 5, 7, 9) and Z column (1, 2, 3, 4) in sequence. - 1 mark: Correct evaluation of all 'X > Y' conditions (True, True, True, True, False). - 1 mark: Correct final output displayed as '8, 9, 4' (or clearly showing these three numbers).
PastPaper.question 5 · structural
9 PastPaper.marks
A software developer is designing a library management system using structured programming principles. The main module is `ManageLoan`.
`ManageLoan` interacts with three sub-modules as follows: - `CheckEligibility`: takes `BorrowerID` as an input and returns a boolean value `Eligible` to indicate if the member can borrow books. - `CalculateFine`: takes `BorrowerID` as an input and returns the real value `FineAmount` representing any outstanding fines. - `IssueBook`: is only called if `Eligible` is `TRUE`. It takes `BorrowerID` and `BookID` as inputs and returns a boolean flag `UpdateSuccess` representing whether the database transaction succeeded.
(a) Complete the description of the parameters passed between `ManageLoan` and its sub-modules. Identify their names, direction of movement, and whether they represent a data couple or a control couple. (4 marks)
(b) Describe how selection is represented in a structure chart and identify which module in this scenario is subject to selection. (2 marks)
(c) Explain two benefits to a developer of using a structure chart during the design stage of this software. (3 marks)
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Part (a) Worked Solution: - Parameters that represent actual values/data items are data couples (represented by an arrow with an open circle). In this scenario, these are `BorrowerID`, `BookID`, and `FineAmount`. - Parameters that represent status signals or flags which control program flow are control couples (represented by an arrow with a filled circle). In this scenario, these are `Eligible` (boolean condition to call IssueBook) and `UpdateSuccess` (transaction status flag). - Direction of flow: * `BorrowerID` and `BookID` flow downwards from the coordinating module `ManageLoan` to the respective sub-modules. * `FineAmount` flows upwards from `CalculateFine` to `ManageLoan`. * `Eligible` flows upwards from `CheckEligibility` to `ManageLoan`. * `UpdateSuccess` flows upwards from `IssueBook` to `ManageLoan`.
Part (b) Worked Solution: - In standard structure chart notation, a selection (conditional execution) is denoted by a small diamond symbol placed where the connecting lines leave the parent/coordinating module (`ManageLoan`). - In this scenario, the `IssueBook` module is conditionally executed (it is only called if `Eligible` is `TRUE`), making it the module subject to selection.
Part (c) Worked Solution: - Benefit 1: Promotes modular design. By visualizing how the system decomposes into smaller, self-contained sub-units, developers can debug, test, and maintain specific pieces of logic (like fine calculation) independently. - Benefit 2: Clarifies interface specifications. It shows exactly what inputs are needed and what outputs are expected for each module, reducing integration errors when different team members write code for separate modules.
PastPaper.markingScheme
Part (a) [4 Marks]: - 1 mark for correctly classifying data couples: `BorrowerID`, `BookID`, and `FineAmount`. - 1 mark for correctly classifying control couples: `Eligible` and `UpdateSuccess`. - 1 mark for identifying correct downwards flow (inputs): `BorrowerID` and `BookID` going from `ManageLoan` to sub-modules. - 1 mark for identifying correct upwards flow (outputs/returns): `FineAmount`, `Eligible`, and `UpdateSuccess` returning to `ManageLoan`.
Part (b) [2 Marks]: - 1 mark for: Explaining that selection is represented by a diamond symbol at the connection/line split. - 1 mark for: Identifying `IssueBook` as the conditional module.
Part (c) [3 Marks]: - 1 mark each for two distinct benefits (max 2 marks): * Shows structural relationships / visual hierarchy of modules. * Identifies parameters / data and control flow clearly to define interfaces. * Enables division of labor / parallel development of separate modules. * Simplifies debugging / tracing / testing by isolating functions. - 1 mark for linking benefits to structured programming principles (e.g., modularity, abstraction, or ease of maintenance).
PastPaper.question 6 · structured
13 PastPaper.marks
A school library system manages member book checkouts. A valid Member ID consists of exactly 6 characters, where the first character is either 'S' (for student) or 'T' (for teacher), and the remaining 5 characters are numeric digits ('0' to '9'). The system stores active checkouts in a global 2D array: DECLARE Checkouts : ARRAY[1:100, 1:2] OF STRING, where row index 1 contains the Member ID, and row index 2 contains the Book Title. Empty slots in this array contain empty strings (""). (a) Define the parameters, their data types, and any return types for: (i) A function IsValidID that validates a member ID. [2 marks] (ii) A procedure DisplayCheckouts that lists a member's books. [1 mark] (b) Write pseudocode for the function IsValidID(MemberID : STRING) RETURNS BOOLEAN. [5 marks] (c) Write pseudocode for the procedure DisplayCheckouts(MemberID : STRING) that searches the entire Checkouts array. It must output the Book Title for every match found and, at the end of the search, output the total number of books checked out by this member. If no checkouts are found, it must output "No books found". [5 marks]
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
(a)(i) Parameter: MemberID of type STRING. Return type: BOOLEAN. (a)(ii) Parameter: MemberID of type STRING. No return type (it is a procedure). (b) FUNCTION IsValidID(MemberID : STRING) RETURNS BOOLEAN ; DECLARE i : INTEGER ; DECLARE NextChar : CHAR ; IF LENGTH(MemberID) <> 6 THEN ; RETURN FALSE ; ENDIF ; IF MID(MemberID, 1, 1) <> "S" AND MID(MemberID, 1, 1) <> "T" THEN ; RETURN FALSE ; ENDIF ; FOR i <- 2 TO 6 ; NextChar <- MID(MemberID, i, 1) ; IF NextChar < "0" OR NextChar > "9" THEN ; RETURN FALSE ; ENDIF ; NEXT i ; RETURN TRUE ; ENDFUNCTION (c) PROCEDURE DisplayCheckouts(MemberID : STRING) ; DECLARE i : INTEGER ; DECLARE Count : INTEGER ; Count <- 0 ; FOR i <- 1 TO 100 ; IF Checkouts[i, 1] = MemberID THEN ; OUTPUT Checkouts[i, 2] ; Count <- Count + 1 ; ENDIF ; NEXT i ; IF Count = 0 THEN ; OUTPUT "No books found" ; ELSE ; OUTPUT "Total checked out: ", Count ; ENDIF ; ENDPROCEDURE
PastPaper.markingScheme
Part (a): 1 mark for IsValidID parameter (MemberID : STRING) and 1 mark for return type (BOOLEAN). 1 mark for DisplayCheckouts parameter (MemberID : STRING) with no return type. Part (b): 1 mark for checking LENGTH is exactly 6. 1 mark for checking if first character is 'S' or 'T'. 1 mark for setting up a loop from index 2 to 6. 1 mark for checking that every character is a digit ('0' to '9'). 1 mark for returning TRUE if all checks pass and FALSE otherwise. Part (c): 1 mark for declaring and initializing local variables (Count to 0). 1 mark for setting up a loop to iterate from 1 to 100. 1 mark for correctly comparing Checkouts[i, 1] with MemberID. 1 mark for outputting Checkouts[i, 2] and incrementing Count when a match is found. 1 mark for outputting the final total or 'No books found' if Count is 0.
PastPaper.question 7 · structured
13 PastPaper.marks
An application processes user-entered registration codes. Each code contains mixed characters. A formatting module is needed to separate letters from numbers. We use a procedure defined as: SplitCode(Code : STRING, BYREF Letters : STRING, BYREF Numbers : STRING). (a) State the purpose of passing parameters by reference (BYREF) rather than by value (BYVAL) in the context of this procedure. [3 marks] (b) Write pseudocode for the procedure SplitCode. The procedure must: (i) Clear the reference parameters Letters and Numbers to be empty strings. (ii) Extract every uppercase letter ('A' to 'Z') and lowercase letter ('a' to 'z') from Code and append it to Letters. (iii) Extract every digit ('0' to '9') from Code and append it to Numbers. (iv) Ignore any other characters. [7 marks] (c) Complete an identifier table for the local variables used inside the SplitCode procedure. [3 marks]
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
(a) Passing by reference (BYREF) passes the memory address of the actual argument to the procedure, allowing any modifications to persist after the procedure terminates. In this case, since a procedure cannot return values via a RETURN statement, BYREF parameters are necessary to send back two separate outputs (Letters and Numbers) to the caller. Code can be passed by value (BYVAL) because it is only read and does not need to be updated. (b) PROCEDURE SplitCode(Code : STRING, BYREF Letters : STRING, BYREF Numbers : STRING) ; DECLARE i : INTEGER ; DECLARE Ch : CHAR ; Letters <- "" ; Numbers <- "" ; FOR i <- 1 TO LENGTH(Code) ; Ch <- MID(Code, i, 1) ; IF (Ch >= "A" AND Ch <= "Z") OR (Ch >= "a" AND Ch <= "z") THEN ; Letters <- Letters & Ch ; ELSE ; IF Ch >= "0" AND Ch <= "9" THEN ; Numbers <- Numbers & Ch ; ENDIF ; ENDIF ; NEXT i ; ENDPROCEDURE (c) Local Variable Table: 1. Name: i, Type: INTEGER, Description: Loop counter used to iterate through each index of the string 'Code'. 2. Name: Ch, Type: CHAR or STRING, Description: Holds the single character extracted from 'Code' at the current index position.
PastPaper.markingScheme
Part (a): 1 mark for stating BYREF passes memory address / reference to original variable. 1 mark for explaining that changes within the procedure modify the caller's variables. 1 mark for noting this allows procedures to return multiple outputs where a function cannot. Part (b): 1 mark for correct procedure header with BYREF keywords. 1 mark for initializing Letters and Numbers to empty strings inside the procedure. 1 mark for looping from 1 to LENGTH(Code). 1 mark for using MID to extract individual characters. 1 mark for correctly checking upper and lowercase alphabetic bounds. 1 mark for correctly checking digit bounds. 1 mark for correctly appending characters to the appropriate parameter. Part (c): 2 marks for listing 'i' and 'Ch' with correct types (INTEGER and CHAR/STRING). 1 mark for complete and accurate descriptions.
PastPaper.question 8 · structured
13 PastPaper.marks
A smart agriculture system monitors greenhouse temperatures. An array HourlyTemps contains 24 hourly temperature readings (as REAL values). A programmer is designing modular routines to perform calculations on this array. (a) Write a pseudocode function MaxTemp(Readings : ARRAY OF REAL) RETURNS REAL that accepts an array of 24 real values and returns the maximum temperature found. [4 marks] (b) Write a pseudocode function AvgAboveThreshold(Readings : ARRAY OF REAL, Limit : REAL) RETURNS REAL that calculates and returns the mathematical average of all readings strictly greater than Limit. If no readings are above Limit, the function must return -1.0. [6 marks] (c) Write a pseudocode segment for a main program that prompts the user to input a threshold temperature, calls AvgAboveThreshold using the HourlyTemps array and the user input, and outputs the average value or a message "No temperatures exceeded the limit" if -1.0 is returned. [3 marks]
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
(a) FUNCTION MaxTemp(Readings : ARRAY OF REAL) RETURNS REAL ; DECLARE Max : REAL ; DECLARE i : INTEGER ; Max <- Readings[1] ; FOR i <- 2 TO 24 ; IF Readings[i] > Max THEN ; Max <- Readings[i] ; ENDIF ; NEXT i ; RETURN Max ; ENDFUNCTION (b) FUNCTION AvgAboveThreshold(Readings : ARRAY OF REAL, Limit : REAL) RETURNS REAL ; DECLARE Total : REAL ; DECLARE Count : INTEGER ; DECLARE i : INTEGER ; Total <- 0.0 ; Count <- 0 ; FOR i <- 1 TO 24 ; IF Readings[i] > Limit THEN ; Total <- Total + Readings[i] ; Count <- Count + 1 ; ENDIF ; NEXT i ; IF Count = 0 THEN ; RETURN -1.0 ; ELSE ; RETURN Total / Count ; ENDIF ; ENDFUNCTION (c) DECLARE LimitValue : REAL ; DECLARE AverageResult : REAL ; OUTPUT "Enter threshold temperature:" ; INPUT LimitValue ; AverageResult <- AvgAboveThreshold(HourlyTemps, LimitValue) ; IF AverageResult = -1.0 THEN ; OUTPUT "No temperatures exceeded the limit" ; ELSE ; OUTPUT "Average of exceeding temperatures: ", AverageResult ; ENDIF
PastPaper.markingScheme
Part (a): 1 mark for correct function header and initialization of Max to first array element. 1 mark for loop structure from 2 to 24. 1 mark for comparison step (Readings[i] > Max). 1 mark for returning the correct maximum value. Part (b): 1 mark for correct function header, and initializing Total to 0.0 and Count to 0. 1 mark for loop structure from 1 to 24. 1 mark for comparison condition checking if element is strictly greater than Limit. 1 mark for accumulating Total and incrementing Count inside loop. 1 mark for handling the division / average calculation only when Count > 0. 1 mark for returning -1.0 when Count is 0. Part (c): 1 mark for prompting the user and capturing inputs. 1 mark for calling AvgAboveThreshold with correct arguments. 1 mark for conditional output based on whether the result is -1.0.