An original Thinka practice paper modelled on the structure and difficulty of the Nov 2023 (V3) Cambridge International A Level Computer Science (9618) paper. Not affiliated with or reproduced from Cambridge.
PastPaper.section 9618/13 Theory Fundamentals
Answer all questions on the spaces provided. Calculators must not be used.
14 PastPaper.question · 75 PastPaper.marks
PastPaper.question 1 · Short recall / Fill-in-the-gap
2.5 PastPaper.marks
Complete the following sentence by filling in the three missing terms. The number of bits allocated to represent each sound sample is known as the (i) _____________. The number of samples recorded per second is the (ii) _____________. Multiplying these two values together with the number of channels gives the (iii) _____________.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
The sampling resolution (or bit depth) defines the number of bits used to represent each audio sample. The sampling rate (or sampling frequency) represents the number of audio samples captured every second. The bit rate is the quantity of data processed per unit of time, calculated as: Sampling Rate x Sampling Resolution x Number of Channels.
PastPaper.markingScheme
1 mark for (i) sampling resolution / bit depth. 1 mark for (ii) sampling rate / sampling frequency. 0.5 marks for (iii) bit rate.
PastPaper.question 2 · Short recall / Fill-in-the-gap
2.5 PastPaper.marks
Identify the networking terms described by the following statements: (i) An IP address where the host ID part consists entirely of binary 1s, used to transmit data packets to all devices on a local subnet. (ii) A method used to map private IP addresses within a local area network to a single public IP address before sending packets over the Internet.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
(i) A broadcast address is a specialized IP address that allows communication to all hosts on a network segment. (ii) Network Address Translation (NAT) is standard on routers to translate private, non-routable local IP addresses into a public routable IP address.
PastPaper.markingScheme
1 mark for (i) Broadcast address (accept: directed broadcast address). 1.5 marks for (ii) Network Address Translation / NAT.
PastPaper.question 3 · Short recall / Fill-in-the-gap
2.5 PastPaper.marks
Complete the following sentences regarding registers in the fetch-decode-execute cycle of a CPU. During the Fetch stage, the address of the next instruction to be fetched is copied from the (i) _____________________ to the (ii) _____________________. The memory contents at that address are then read and temporarily stored in the (iii) _____________________.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
At the start of the fetch cycle, the Program Counter (PC) holds the address of the next instruction. This address is copied to the Memory Address Register (MAR) via the address bus. The control unit then triggers a memory read, which loads the instruction data from memory into the Memory Data Register (MDR).
PastPaper.markingScheme
1 mark for (i) Program Counter / PC. 1 mark for (ii) Memory Address Register / MAR. 0.5 marks for (iii) Memory Data Register / MDR / Memory Buffer Register / MBR.
PastPaper.question 4 · Short recall / Fill-in-the-gap
2.5 PastPaper.marks
Complete the descriptions of data integrity check methods by filling in the blanks. Method A: (i) _______________ - An extra digit calculated from the other digits in a number and appended to the end, commonly used in ISBNs to detect keying errors. Method B: Checksum. Method C: (ii) _______________ - A single bit appended to a binary block to ensure the count of 1s matches a specific parity. This technique cannot detect (iii) _______________ errors where an even number of bits are corrupted.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
A check digit is appended to a code (like ISBN or barcode) to detect human entry errors. A parity check adds a single parity bit to verify data transmission, but if two bits (or any even number of bits) flip during transmission, the parity remains correct, making the error undetectable.
PastPaper.markingScheme
1 mark for (i) Check digit. 1 mark for (ii) Parity bit / Parity check / Parity. 0.5 marks for (iii) double / two-bit / multiple / even number of bit errors.
PastPaper.question 5 · Structured Analytical
6.5 PastPaper.marks
Describe the sequence of steps that occur during the fetch stage of the Fetch-Execute cycle, specifically highlighting how the Program Counter (PC), Memory Address Register (MAR), Memory Data Register (MDR), and Current Instruction Register (CIR) are used. Furthermore, explain how a conditional jump instruction (for example, JPE - Jump if Equal) affects the Program Counter (PC) during the execute stage.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
During the fetch stage: 1. The address in the PC is copied to the MAR. 2. The PC is incremented by 1 to point to the next instruction. 3. The instruction at the memory location stored in the MAR is loaded into the MDR. 4. The instruction in the MDR is copied to the CIR. During the execute stage of a JPE instruction, the status register/accumulator flag is checked. If the comparison flag indicates equality, the PC is updated with the target address from the operand of the instruction. If the flag does not indicate equality, the PC remains unchanged, holding the incremented address from the fetch stage.
PastPaper.markingScheme
1 mark: PC contents copied to MAR. 1 mark: PC incremented. 1 mark: Memory content at MAR loaded to MDR. 1 mark: MDR content copied to CIR. 1 mark: JPE checks the status register. 1.5 marks: Explains that if the condition is met, PC is updated with the target address; if false, PC remains unchanged. Total: 6.5 marks.
PastPaper.question 6 · Structured Explanatory
6.5 PastPaper.marks
Carrier Sense Multiple Access with Collision Detection (CSMA/CD) is a protocol used in Ethernet networks. Explain why a collision detection mechanism is necessary, and describe the precise sequence of actions taken by a device when a collision is detected during data transmission.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
On a shared medium, multiple devices can transmit data simultaneously, which causes their signals to overlap and corrupt each other, resulting in lost frames. CSMA/CD is necessary to identify these occurrences and recover from them. When a collision is detected, the device: 1. Immediately stops transmitting the current frame. 2. Broadcasts a jam signal to ensure all other devices on the network segment detect the collision. 3. Increments its collision retransmission counter. 4. Calculates a random backoff time using a backoff algorithm. 5. Waits for this random period before attempting to sense the carrier again and retransmit.
PastPaper.markingScheme
1.5 marks: Explains the necessity of collision detection (prevents signal corruption, loss of data, wasted bandwidth). 1 mark: Device immediately stops current transmission. 1 mark: Device sends a jam signal. 1 mark: Device calculates a random backoff/wait time. 1 mark: Device waits for the random period. 1 mark: Device re-senses the channel before attempting to retransmit. Total: 6.5 marks.
PastPaper.question 7 · Structured Analytical
6.5 PastPaper.marks
Digital signatures are widely used in secure electronic communication. Explain how asymmetric encryption algorithms and hashing functions are combined to create and verify a digital signature to guarantee both the authenticity of the sender and the integrity of the message.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
To create a digital signature: 1. The original message is run through a hash function to generate a unique message digest. 2. The sender encrypts this digest using their own private key, creating the digital signature. 3. The signature is appended to the message and sent. To verify the signature: 4. The recipient decrypts the digital signature using the sender's public key to retrieve the original digest. 5. The recipient applies the identical hash function to the received message to produce a new digest. 6. The recipient compares the two digests. If they are identical, it proves integrity (the message was not modified) and authenticity (only the owner of the private key could have encrypted it).
PastPaper.markingScheme
1 mark: Hash function generates a digest from the message. 1 mark: Sender encrypts the digest with their private key to create the signature. 1 mark: Signature is appended and sent. 1 mark: Recipient decrypts the signature with the sender's public key to get the original digest. 1 mark: Recipient hashes the received message. 1.5 marks: If both digests match, it verifies integrity (no changes made) and authenticity (proven by private key ownership). Total: 6.5 marks.
PastPaper.question 8 · Structured Explanatory
6.5 PastPaper.marks
An educational institution keeps track of student registrations in a relational database. Explain the differences between Second Normal Form (2NF) and Third Normal Form (3NF), including the specific types of dependency that must be removed to move from 1NF to 2NF, and then from 2NF to 3NF. Illustrate your answer by describing how a transitive dependency is resolved.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
To convert a relation from 1NF to 2NF, any partial dependencies must be removed. This means non-key attributes must depend on the entire composite primary key, not just a portion of it. To transition from 2NF to 3NF, transitive dependencies must be removed, meaning no non-key attribute can depend on another non-key attribute. To resolve a transitive dependency where attribute A determines B, and B determines C (A -> B -> C), we decompose the relation into two tables: Table 1 with attributes A and B (where A is the primary key), and Table 2 with attributes B and C (where B is the primary key and acts as a foreign key in Table 1).
PastPaper.markingScheme
1.5 marks: Explain 1NF to 2NF transition (removal of partial dependencies, where non-key attributes depend on part of a composite key). 1.5 marks: Explain 2NF to 3NF transition (removal of transitive dependencies, where non-key attributes depend on other non-key attributes). 1 mark: Define a transitive relationship representation (e.g., A determines B, B determines C). 1.5 marks: Describe decomposition into two tables, specifying primary and foreign keys. 1 mark: Overall clarity and technical accuracy. Total: 6.5 marks.
PastPaper.question 9 · Structured Analytical
6.5 PastPaper.marks
An industrial automated greenhouse uses a computer-based control system to maintain a constant temperature of exactly \(24^\circ\text{C}\). Describe how temperature sensors, an embedded microprocessor, and a heating/cooling actuator work together in a closed-loop feedback system. Your answer must explain how data conversion is achieved and how the microprocessor determines the appropriate output action.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
The temperature sensor continuously measures the physical environment, outputting an analog voltage signal. This analog signal is converted to digital data by an Analog-to-Digital Converter (ADC) so the microprocessor can read it. The microprocessor compares the digital temperature value to the preset target of \(24^\circ\text{C}\). If the reading is less than \(24^\circ\text{C}\), the microprocessor sends a control signal to activate the heater actuator. If the reading is greater than \(24^\circ\text{C}\), it sends a signal to activate the cooling actuator. If it matches, no action is taken. If necessary, a Digital-to-Analog Converter (DAC) converts digital control commands to analog signals to drive the actuators. This entire loop repeats continuously, forming a closed feedback system.
PastPaper.markingScheme
1 mark: Sensor output is analog and must be processed. 1 mark: ADC converts analog sensor signals to digital input. 1 mark: Microprocessor compares digital input to the preset value of \(24^\circ\text{C}\). 1.5 marks: Describes decision logic (heater turned on if below, cooler if above target). 1 mark: DAC (if needed) converts digital commands back to analog for actuators. 1 mark: Explains the continuous, closed-loop nature of feedback. Total: 6.5 marks.
PastPaper.question 10 · Structured Analytical
6.5 PastPaper.marks
A digital sound editor is preparing a stereo audio file for a client. The client requests a 5-minute recording sampled at \(44.1\text{ kHz}\) with a 16-bit sampling resolution. 1. Calculate the minimum file size of the uncompressed audio in megabytes (MB), showing your steps and stating your assumption for MB conversion. 2. Describe how increasing the sampling resolution impacts the dynamic range and fidelity of the sound, and identify one consequence on system resource requirements.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
1. Calculation: Duration = 5 minutes = 300 seconds. Channels = 2 (stereo). Sampling Rate = 44,100 Hz. Bit Depth = 16 bits = 2 bytes. File size = \(44,100 \times 2 \times 2 \times 300 = 52,920,000\text{ bytes}\). Assuming \(1\text{ MB} = 1,000,000\text{ bytes}\), the size is \(52,920,000 / 1,000,000 = 52.92\text{ MB}\). (Or assuming \(1\text{ MB} = 1,048,576\text{ bytes}\), the size is \(52,920,000 / 1,048,576 = 50.47\text{ MB}\)). 2. Impact: Increasing sampling resolution means more bits are used per sample, which allows for a larger dynamic range (wider range of decibels represented) and reduces quantization noise, leading to higher fidelity (closer representation of the original sound wave). A consequence of this is increased storage requirements and greater network bandwidth needed for transmission.
PastPaper.markingScheme
1 mark: Correctly identifies 300 seconds and 2 channels. 1 mark: Calculates file size in bytes as 52,920,000. 1 mark: Converts bytes to MB correctly based on stated assumption (52.92 MB or 50.47 MB). 1.5 marks: Explains impact of higher resolution (more vertical intervals, wider dynamic range, reduced quantization error). 1 mark: Explains resulting high fidelity. 1 mark: Identifies increased storage or bandwidth resource requirements. Total: 6.5 marks.
PastPaper.question 11 · Structured Explanatory
6.5 PastPaper.marks
During the development of a software application, a programmer decides to use an interpreter. However, once the application is ready for commercial distribution, they choose to compile the source code into an executable file. Justify this strategy by comparing compilers and interpreters, focusing on: ease of debugging during development, execution speed and resource usage, and intellectual property protection when distributing the software.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
During development, an interpreter is preferred because it translates and executes code line-by-line. If an error is found, it stops execution immediately and points to the specific line, facilitating rapid debugging and correction. Compilers require the entire program to be error-free before generating any executable, which slows down the testing loop. For distribution, a compiler is preferred because compiled code runs much faster since translation has already occurred, and it does not require an interpreter to be installed on the user's machine. Furthermore, compiling translates the readable high-level source code into binary machine code, protecting the programmer's intellectual property, whereas interpreted code requires distributing the original readable source code.
PastPaper.markingScheme
2 marks (Debugging): Interpreters run line-by-line and stop immediately at errors, aiding fast debugging, whereas compilers require complete translation and output error lists. 2 marks (Execution speed): Compiled code is pre-translated and runs faster without runtime overhead, whereas interpreted code is translated dynamically during execution. 1.5 marks (IP Protection): Compilers hide original code by producing machine code binaries, preventing reverse engineering, while interpreters require sharing source files. 1 mark: Clear, logical comparative justification. Total: 6.5 marks.
PastPaper.question 12 · Structured Analytical
6.5 PastPaper.marks
A software company is preparing to release a critical update for a healthcare application. Describe the differences between black-box testing and white-box testing. Explain how test cases are selected for each method, and explain why both methods must be used in conjunction to ensure robust quality assurance.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Black-box testing tests the system functional requirements without knowledge of the internal code structure. Test cases are selected based on specification inputs and expected outputs, using techniques like boundary value analysis and equivalence partitioning. White-box testing tests the internal logic, paths, and structure of the source code. Test cases are selected to guarantee code path coverage, ensuring every statement and branch is executed. Both methods must be used in conjunction because black-box testing might miss internal code inefficiencies or hidden vulnerabilities that function correctly under standard inputs, whereas white-box testing cannot identify whether a required software feature has been completely omitted from the codebase.
PastPaper.markingScheme
1.5 marks: Definitions and selection criteria for black-box testing (input/output focused, based on specifications). 1.5 marks: Definitions and selection criteria for white-box testing (code-path focused, based on code structure). 1.5 marks: Identifies limitations of black-box testing (cannot inspect code logic or security paths directly). 1 mark: Identifies limitations of white-box testing (cannot detect missing software requirements). 1 mark: Explains the synergy of using both to cover structural and functional assurance. Total: 6.5 marks.
PastPaper.question 13 · Calculations and Logic Representation
6.5 PastPaper.marks
An 8-bit fixed-point representation uses two's complement format with 5 bits for the integer part (mantissa) and 3 bits for the fractional part, as shown below:
`[MSB] I I I I . F F F [LSB]`
(a) Convert the decimal value \(-9.625\) into this 8-bit fixed-point representation. Show your working.
(b) Convert the binary representation `01101.101` into a denary (decimal) value. Show your working.
(c) Explain why the decimal value \(4.3\) cannot be represented exactly in this 8-bit system, and state the value that would actually be stored if truncation is used.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
(a) To convert \(-9.625\) to two's complement: 1. Convert the positive value \(+9.625\): - Integer part: 9 in 5 bits is `01001`. - Fractional part: \(0.625 = 0.5 + 0.125 = 2^{-1} + 2^{-3}\), which is `101` in 3 bits. - Combined representation: `01001.101` (or `01001101` as raw bits). 2. Invert the bits (one's complement): `10110010` 3. Add 1 to the least significant bit (two's complement): `10110011` Therefore, the final representation is `10110.011` (or binary `10110011`).
(b) Convert binary `01101.101` to decimal: - Since the MSB is 0, the value is positive. - Integer part: `01101` = \(8 + 4 + 1 = 13\) - Fractional part: `.101` = \(0.5 + 0.125 = 0.625\) - Combined decimal value: \(13 + 0.625 = 13.625\)
(c) The fractional part of \(4.3\) is \(0.3\). Converting \(0.3\) into binary yields an infinite recurring sequence: \(0.0100110011\dots\) Because there are only 3 fractional bits available, this value cannot be stored exactly. Truncating this to 3 fractional bits yields `.010` (which is \(0.25\) in denary). Thus, the actual value stored is \(4.0 + 0.25 = 4.25\) (represented as `00100.010`).
PastPaper.markingScheme
(a) Max 3 marks: - 1 mark for correct binary representation of +9.625 (`01001101`) - 1 mark for correct one's complement step (`10110010`) - 1 mark for correct final two's complement representation (`10110011`)
(b) Max 2 marks: - 1 mark for converting integer part (`01101` to 13) - 1 mark for converting fractional part (`.101` to 0.625) and obtaining 13.625
(c) Max 1.5 marks: - 1 mark for explaining that the fractional part 0.3 results in an infinite recurring binary series / cannot be represented in finite bits. - 0.5 marks for stating the correct stored truncated value (4.25 or `00100.010`).
PastPaper.question 14 · Calculations and Logic Representation
6.5 PastPaper.marks
(a) Complete the truth table for the following Boolean expression:
\(X = (\bar{A} \cdot \bar{B}) + (A \cdot B \cdot \bar{C})\)
(a) Evaluating X for each combination: - For \(A=0, B=0, C=0\): \(\bar{A}\bar{B} = 1 \cdot 1 = 1\), so \(X = 1\). - For \(A=0, B=0, C=1\): \(\bar{A}\bar{B} = 1 \cdot 1 = 1\), so \(X = 1\). - For \(A=0, B=1, C=0\): \(\bar{A}\bar{B} = 0\), \(AB\bar{C} = 0\), so \(X = 0\). - For \(A=0, B=1, C=1\): \(\bar{A}\bar{B} = 0\), \(AB\bar{C} = 0\), so \(X = 0\). - For \(A=1, B=0, C=0\): \(\bar{A}\bar{B} = 0\), \(AB\bar{C} = 0\), so \(X = 0\). - For \(A=1, B=0, C=1\): \(\bar{A}\bar{B} = 0\), \(AB\bar{C} = 0\), so \(X = 0\). - For \(A=1, B=1, C=0\): \(\bar{A}\bar{B} = 0\), \(AB\bar{C} = 1 \cdot 1 \cdot 1 = 1\), so \(X = 1\). - For \(A=1, B=1, C=1\): \(\bar{A}\bar{B} = 0\), \(AB\bar{C} = 1 \cdot 1 \cdot 0 = 0\), so \(X = 0\).
(b) Step-by-step simplification of \(Y = (P \cdot Q) + (P \cdot (Q + R)) + Q \cdot (Q + R)\): 1. Expand the terms using the Distributive Law: \(Y = (P \cdot Q) + (P \cdot Q) + (P \cdot R) + (Q \cdot Q) + (Q \cdot R)\) 2. Apply the Idempotent Law (where \(P \cdot Q + P \cdot Q = P \cdot Q\) and \(Q \cdot Q = Q\)): \(Y = (P \cdot Q) + (P \cdot R) + Q + (Q \cdot R)\) 3. Apply the Absorption Law (where \(Q + (Q \cdot R) = Q\)): \(Y = (P \cdot Q) + (P \cdot R) + Q\) 4. Apply the Absorption Law again (rearranging to \(Q + (P \cdot Q) = Q\)): \(Y = Q + (P \cdot R)\)
PastPaper.markingScheme
(a) Max 3 marks: - 3 marks for all 8 output rows correct. - 2 marks for 6 or 7 output rows correct. - 1 mark for 4 or 5 output rows correct. - 0 marks for 3 or fewer rows correct. (Correct sequence of outputs from top to bottom: 1, 1, 0, 0, 0, 0, 1, 0)
(b) Max 3.5 marks: - 1 mark for correct expansion of the terms using the Distributive Law. - 1 mark for correct use of the Idempotent Law to reduce terms. - 1 mark for correct use of the Absorption Law to eliminate redundant terms. - 0.5 marks for the correct simplified expression: \(Q + (P \cdot R)\) (or equivalent such as \(Q + PR\)).
1. SUBSTR(Phrase, 11, 4) extracts 4 characters starting at index 11 of "Cambridge 9618", which is "9618". LENGTH("9618") evaluates to the integer 4. 2. INT(Num1) converts 12.75 to the integer 12. 12 MOD 4 calculates the remainder of 12 divided by 4, which is 0 (INTEGER). 3. Num1 + 0.5 is 13.25. INT(13.25) is 13. NUM_TO_STR(13) is "13". RIGHT(Phrase, 2) extracts the last two characters of "Cambridge 9618", which is "18". Concatenating these with a space gives "13 18" (STRING). 4. SUBSTR(Phrase, 1, 3) extracts "Cam". LCASE("Cam") is "cam". The comparison "cam" = "cam" evaluates to TRUE (BOOLEAN).
PastPaper.markingScheme
1 mark for each correct evaluation containing both the correct value and correct data type: - Expression 1: Value: 4, Type: INTEGER (1 mark) - Expression 2: Value: 0, Type: INTEGER (1 mark) - Expression 3: Value: "13 18" (accept 13 18 without quotes), Type: STRING (1 mark) - Expression 4: Value: TRUE (accept True), Type: BOOLEAN (1 mark)
A programmer writes a pseudocode procedure designed to find the maximum value in a 1D array of 10 integers. The code contains four distinct syntax errors that violate the Cambridge International 9618 pseudocode specification:
01 PROCEDURE FindMax(MyArray : ARRAY[1:10] OF INTEGER) 02 DECLARE MaxVal : INTEGER 03 MaxVal <- MyArray[1] 04 FOR i <- 2 TO 10 05 IF MyArray[i] > MaxVal DO 06 MaxVal = MyArray[i] 07 ENDIF 08 NEXT i 09 RETURN MaxVal 10 ENDPROCEDURE
Identify the four syntax errors by specifying their line numbers and the correct syntax required to fix them.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
The syntax errors are: 1. On Line 01, parameters in 9618 pseudocode procedure headers must explicitly specify their passing mode using either the BYVAL or BYREF keyword. 2. On Line 05, the conditional statement IF must be followed by THEN, not DO. 3. On Line 06, the assignment operator is <-, not = (which is a comparison operator). 4. On Line 09, a PROCEDURE is not permitted to return a value using a RETURN statement; only a FUNCTION can do so.
PastPaper.markingScheme
1 mark for each correct identification of line number and correction (Max 4 marks): - Line 01: Add BYVAL or BYREF keyword (e.g., PROCEDURE FindMax(BYVAL MyArray ...)) (1 mark) - Line 05: Replace DO with THEN (1 mark) - Line 06: Replace = with <- (1 mark) - Line 09: Remove RETURN MaxVal (or change PROCEDURE to FUNCTION and ENDPROCEDURE to ENDFUNCTION) (1 mark)
Study the following recursive pseudocode function:
FUNCTION ProcessString(Str : STRING) RETURNS STRING IF LENGTH(Str) <= 1 THEN RETURN Str ELSE IF SUBSTR(Str, 1, 1) = "A" OR SUBSTR(Str, 1, 1) = "E" THEN RETURN ProcessString(SUBSTR(Str, 2, LENGTH(Str) - 1)) ELSE RETURN SUBSTR(Str, 1, 1) & ProcessString(SUBSTR(Str, 2, LENGTH(Str) - 1)) ENDIF ENDIF ENDFUNCTION
(a) State the exact return value when this function is called with ProcessString("ELEVATE"). [2 marks] (b) Explain why the final letter 'E' in "ELEVATE" is not removed by this function, whereas all other instances of 'E' and 'A' are. [2 marks]
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Let us trace the execution of ProcessString("ELEVATE"): - Call 1: "ELEVATE" (length 7). First char is 'E'. Returns ProcessString("LEVATE"). - Call 2: "LEVATE" (length 6). First char is 'L'. Returns 'L' & ProcessString("EVATE"). - Call 3: "EVATE" (length 5). First char is 'E'. Returns ProcessString("VATE"). - Call 4: "VATE" (length 4). First char is 'V'. Returns 'V' & ProcessString("ATE"). - Call 5: "ATE" (length 3). First char is 'A'. Returns ProcessString("TE"). - Call 6: "TE" (length 2). First char is 'T'. Returns 'T' & ProcessString("E"). - Call 7: "E" (length 1). Because LENGTH("E") <= 1 is TRUE, the base case triggers, returning "E" directly without executing the conditional checks for 'A' or 'E'.
Part (a): [2 marks] - 1 mark for identifying that vowels 'E' (first) and 'A' are removed ("LVT"). - 1 mark for correctly preserving the final 'E', yielding the exact output "LVTE" (accept with or without double quotes. Reject "LVT").
Part (b): [2 marks] - 1 mark for identifying the base case condition (LENGTH(Str) <= 1). - 1 mark for explaining that when "E" is the last character, the function hits this base case and returns "E" immediately, skipping the inner selection block that removes vowels.
PastPaper.question 4 · practical
5.5 PastPaper.marks
An algorithm processes a sequence of four user inputs using a flowchart. The steps of the flowchart are described below: 1. Start, 2. Set Count to 0, Total to 0, Limit to 4, 3. Input Value, 4. Check if Value > 10: If YES, set Total to Total + Value, and set Count to Count + 1; If NO, set Total to Total - Value, 5. Set Limit to Limit - 1, 6. Check if Limit > 0: If YES, go back to step 3; If NO, proceed to step 7, 7. Set Result to Total / Count, 8. Output Result, 9. End. The input values provided are: 12, 5, 18, 4. Trace this algorithm and complete the trace table recording the changes in variables and outputs.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Dry run execution step-by-step: 1. Initialization: \(Count = 0\), \(Total = 0\), \(Limit = 4\). 2. First Input (12): \(Value = 12\). Since \(12 > 10\), \(Total = 0 + 12 = 12\), and \(Count = 0 + 1 = 1\). \(Limit\) decrements to 3. Since \(Limit > 0\), the loop continues. 3. Second Input (5): \(Value = 5\). Since \(5 \le 10\), \(Total = 12 - 5 = 7\). \(Limit\) decrements to 2. Since \(Limit > 0\), the loop continues. 4. Third Input (18): \(Value = 18\). Since \(18 > 10\), \(Total = 7 + 18 = 25\), and \(Count = 1 + 1 = 2\). \(Limit\) decrements to 1. Since \(Limit > 0\), the loop continues. 5. Fourth Input (4): \(Value = 4\). Since \(4 \le 10\), \(Total = 25 - 4 = 21\). \(Limit\) decrements to 0. Since \(Limit\) is not greater than 0, the loop terminates. 6. Calculation: \(Result = Total / Count = 21 / 2 = 10.5\). Output is 10.5.
PastPaper.markingScheme
1 mark for initializing Limit = 4, Count = 0, Total = 0. 1 mark for tracking first input (Value = 12, Count = 1, Total = 12, Limit = 3). 1 mark for tracking second input (Value = 5, Total = 7, Limit = 2). 1 mark for tracking third input (Value = 18, Count = 2, Total = 25, Limit = 1). 1 mark for tracking fourth input (Value = 4, Total = 21, Limit = 0). 0.5 marks for correct final Result (10.5) and Output (10.5).
PastPaper.question 5 · practical
5.5 PastPaper.marks
A 1D array named Numbers contains 5 integers: [15, 23, 8, 31, 12]. The index of the array starts at 1. An algorithm processes this array using a flowchart, described below: 1. Start, 2. Set Index to 2, MinVal to Numbers[1], MaxVal to Numbers[1], 3. Check if Index > 5: If YES, go to step 8; If NO, proceed to step 4, 4. Check if Numbers[Index] < MinVal: If YES, set MinVal to Numbers[Index], then proceed to step 6; If NO, proceed to step 5, 5. Check if Numbers[Index] > MaxVal: If YES, set MaxVal to Numbers[Index], then proceed to step 6; If NO, proceed to step 6, 6. Set Index to Index + 1, 7. Go back to step 3, 8. Set RangeVal to MaxVal - MinVal, 9. Output RangeVal, 10. End. Trace this algorithm and complete the trace table.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
Dry run execution step-by-step: - Initialization: \(Index = 2\), \(MinVal = Numbers[1] = 15\), \(MaxVal = Numbers[1] = 15\). - Iteration 1 (Index = 2): \(Numbers[2] = 23\). Check if \(23 < MinVal (15)\) -> No. Check if \(23 > MaxVal (15)\) -> Yes, MaxVal becomes 23. Index is incremented to 3. - Iteration 2 (Index = 3): \(Numbers[3] = 8\). Check if \(8 < MinVal (15)\) -> Yes, MinVal becomes 8. Step 5 is bypassed. Index is incremented to 4. - Iteration 3 (Index = 4): \(Numbers[4] = 31\). Check if \(31 < MinVal (8)\) -> No. Check if \(31 > MaxVal (23)\) -> Yes, MaxVal becomes 31. Index is incremented to 5. - Iteration 4 (Index = 5): \(Numbers[5] = 12\). Check if \(12 < MinVal (8)\) -> No. Check if \(12 > MaxVal (31)\) -> No. No variables change other than Index. Index is incremented to 6. - Exit: \(Index = 6\). Since \(Index > 5\), loop terminates. \(RangeVal = MaxVal - MinVal = 31 - 8 = 23\). Output is 23.
PastPaper.markingScheme
1 mark for initial row (Index = 2, MinVal = 15, MaxVal = 15). 1 mark for first loop update (MaxVal = 23, Index = 3). 1 mark for second loop update (MinVal = 8, Index = 4). 1 mark for third loop update (MaxVal = 31, Index = 5). 1 mark for fourth loop update (Index incremented to 6, no other changes). 0.5 marks for correct final RangeVal (23) and Output (23).
PastPaper.question 6 · procedural
10.2 PastPaper.marks
A company tracks its energy consumption using an array of records. The user-defined record type is defined as follows:
TYPE EnergyRecord DECLARE ReadingID : STRING DECLARE KWhUsage : REAL DECLARE PeakTime : BOOLEAN ENDTYPE
Write pseudocode for a procedure ProcessEnergyData that receives three parameters: - EnergyData: an array of type EnergyRecord indexed from 1 to 100 - NumRecords: the integer number of active records in the array - Threshold: a real value representing the consumption limit
The procedure must perform the following tasks: 1. Find and output (to screen) the ReadingID of all records where KWhUsage is strictly greater than Threshold AND PeakTime is TRUE. 2. Calculate the average KWhUsage of these specific matching records. 3. Output the average to screen. If no matching records are found, output 'No records exceeded the threshold during peak times.'.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
PROCEDURE ProcessEnergyData(EnergyData : ARRAY[1:100] OF EnergyRecord, NumRecords : INTEGER, Threshold : REAL) DECLARE Index : INTEGER DECLARE MatchCount : INTEGER DECLARE TotalUsage : REAL DECLARE AvgUsage : REAL
MatchCount <- 0 TotalUsage <- 0.0
FOR Index <- 1 TO NumRecords IF EnergyData[Index].KWhUsage > Threshold AND EnergyData[Index].PeakTime = TRUE THEN OUTPUT EnergyData[Index].ReadingID MatchCount <- MatchCount + 1 TotalUsage <- TotalUsage + EnergyData[Index].KWhUsage ENDIF NEXT Index
IF MatchCount > 0 THEN AvgUsage <- TotalUsage / MatchCount OUTPUT \"Average usage: \", AvgUsage ELSE OUTPUT \"No records exceeded the threshold during peak times.\" ENDIF ENDPROCEDURE
PastPaper.markingScheme
1 mark: Correct PROCEDURE header with three parameter names and types. 1 mark: Correct DECLARE statements for local variables with appropriate types. 1 mark: Initializing MatchCount and TotalUsage to appropriate starting values. 1 mark: FOR loop from 1 to NumRecords to iterate through the array. 1 mark: IF statement checking both conditions: KWhUsage > Threshold AND PeakTime = TRUE (or PeakTime). 1 mark: OUTPUT the ReadingID inside the matching block. 1 mark: Increment MatchCount and accumulate TotalUsage correctly inside the IF block. 1 mark: Close loop with NEXT or ENDFOR/ENDWHILE correctly. 1 mark: Post-loop check IF MatchCount > 0 to prevent division by zero. 1.2 marks: Correct calculation of average and output of average or the error message.
PastPaper.question 7 · procedural
10.2 PastPaper.marks
Write a pseudocode function ValidateCode that takes a single string parameter Code and returns a boolean value (TRUE or FALSE).
The function must validate the string according to the following strict criteria: - It must be exactly 9 characters long. - The first two characters must be uppercase alphabetic letters ('A' to 'Z'). - The next five characters (index 3 to 7) must be numeric digits ('0' to '9'). - The eighth character must be a hyphen ('-'). - The ninth (last) character must be either 'Y' or 'N' (case-insensitive).
Assume the existence of the following built-in functions: - LENGTH(s): Returns the integer length of string s. - MID(s, start, length): Returns a substring of s starting at position start with length length. - UCASE(c): Returns the uppercase equivalent of character or string c.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
FUNCTION ValidateCode(Code : STRING) RETURNS BOOLEAN DECLARE Len : INTEGER DECLARE Index : INTEGER DECLARE Char : CHAR DECLARE LastChar : CHAR
Len <- LENGTH(Code) IF Len <> 9 THEN RETURN FALSE ENDIF
FOR Index <- 1 TO 2 Char <- MID(Code, Index, 1) IF Char < \"A\" OR Char > \"Z\" THEN RETURN FALSE ENDIF NEXT Index
FOR Index <- 3 TO 7 Char <- MID(Code, Index, 1) IF Char < \"0\" OR Char > \"9\" THEN RETURN FALSE ENDIF NEXT Index
IF MID(Code, 8, 1) <> \"-\" THEN RETURN FALSE ENDIF
LastChar <- UCASE(MID(Code, 9, 1)) IF LastChar <> \"Y\" AND LastChar <> \"N\" THEN RETURN FALSE ENDIF
RETURN TRUE ENDFUNCTION
PastPaper.markingScheme
1 mark: Correct FUNCTION header with parameter, parameter type, and return type. 1 mark: Check if length of Code is exactly 9, returning FALSE if not. 2 marks: Correct loop/checks for first two characters to ensure they are between 'A' and 'Z' inclusive. 2 marks: Correct loop/checks for characters 3 to 7 to ensure they are between '0' and '9' inclusive. 1 mark: Correct check for the hyphen '-' at position 8. 1.2 marks: Correct check for the ninth character being 'Y' or 'N' (handling case sensitivity with UCASE or both cases). 1 mark: Correctly returning TRUE if all checks pass and FALSE if any check fails. 1 mark: Correct ENDFUNCTION terminator.
PastPaper.question 8 · procedural
10.2 PastPaper.marks
A text file Inventory.txt contains stock details. Each item's record is stored across three consecutive lines: - Line 1: Item Code (e.g., \"ITM-229\") - Line 2: Quantity in stock (as an integer string) - Line 3: Reorder level (as an integer string)
Write a pseudocode procedure GenerateReorderList that performs the following tasks: 1. Read through the file Inventory.txt until the end of the file is reached. 2. For each item, check if the Quantity in stock is strictly less than the Reorder level. 3. If it is, write the Item Code to a new file named Reorder.txt. 4. Keep track of the total count of items written to Reorder.txt. 5. Output this count to the screen at the end. 6. Correctly open and close all files used.
Use the following built-in file operations: - OPENFILE FOR READ/WRITE - READFILE , - WRITEFILE , - CLOSEFILE - EOF()
Count <- 0 OPENFILE \"Inventory.txt\" FOR READ OPENFILE \"Reorder.txt\" FOR WRITE
WHILE NOT EOF(\"Inventory.txt\") DO READFILE \"Inventory.txt\", ItemCode READFILE \"Inventory.txt\", QuantityStr READFILE \"Inventory.txt\", ReorderLevelStr
1 mark: Correct PROCEDURE header and declaration of variables. 1 mark: Correctly opening 'Inventory.txt' for READ and 'Reorder.txt' for WRITE. 1 mark: Use of a WHILE NOT EOF('Inventory.txt') loop (or equivalent loop). 2 marks: Correctly reading three values sequentially inside the loop using READFILE. 1.2 marks: Correctly converting string values to integers (using STRING_TO_NUM). 1 mark: Correct comparison checking if Quantity < ReorderLevel. 1 mark: Correctly writing the ItemCode to 'Reorder.txt' using WRITEFILE inside the IF block. 1 mark: Incrementing a counter for each matching record and outputting the count post-loop. 1 mark: Closing both files 'Inventory.txt' and 'Reorder.txt' after the loop.
PastPaper.question 9 · procedural
10.2 PastPaper.marks
A game board uses an 8 by 8 grid represented by a 2D integer array Grid indexed from 1 to 8 for both rows and columns.
Write a pseudocode procedure SumDiagonalSector that accepts two parameters: - Grid: an 8x8 2D array of integers - Sector: a character variable ('U', 'L', or other values)
The procedure must perform the following actions: 1. If Sector is 'U', calculate and output the sum of all elements strictly above the main diagonal (where column index is greater than row index). 2. If Sector is 'L', calculate and output the sum of all elements strictly below the main diagonal (where row index is greater than column index). 3. If Sector is any other character, output an error message \"Invalid Sector\". 4. Use nested loops to traverse the elements.
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
PROCEDURE SumDiagonalSector(Grid : ARRAY[1:8, 1:8] OF INTEGER, Sector : CHAR) DECLARE Row : INTEGER DECLARE Col : INTEGER DECLARE Sum : INTEGER
Sum <- 0
IF Sector = \"U\" THEN FOR Row <- 1 TO 8 FOR Col <- 1 TO 8 IF Col > Row THEN Sum <- Sum + Grid[Row, Col] ENDIF NEXT Col NEXT Row OUTPUT \"Sum of Upper Sector: \", Sum ELSE IF Sector = \"L\" THEN FOR Row <- 1 TO 8 FOR Col <- 1 TO 8 IF Row > Col THEN Sum <- Sum + Grid[Row, Col] ENDIF NEXT Col NEXT Row OUTPUT \"Sum of Lower Sector: \", Sum ELSE OUTPUT \"Invalid Sector\" ENDIF ENDIF ENDPROCEDURE
PastPaper.markingScheme
1 mark: Correct PROCEDURE header with parameters (Grid as 2D array, Sector as CHAR). 1 mark: Correct declaration of nested loop counter variables (Row, Col) and accumulator (Sum). 1 mark: Initializing Sum to 0. 1.2 marks: Correctly handling outer conditional logic (IF Sector = 'U', ELSE IF Sector = 'L', ELSE error message). 2 marks: Correctly nested loops structure traversing 1 to 8 for rows and columns. 1 mark: Correct comparison Col > Row for upper sector summing. 1 mark: Correct comparison Row > Col for lower sector summing. 1 mark: Correct array indexing Grid[Row, Col] to accumulate values into Sum. 1 mark: Correct outputs for both sum cases and the error message.
PastPaper.question 10 · procedural
10.2 PastPaper.marks
Write a pseudocode function SearchAndFrequency that searches a 1D array of strings for a specific search term. The function receives three parameters: - Words: an array of strings indexed from 1 to 100 - NumElements: an integer representing the number of active elements in the array to search - SearchTerm: a string representing the target value to search for
The function must do the following: 1. Search the active elements of the Words array from index 1 to NumElements. 2. Keep a count of how many times SearchTerm is found in the array. 3. Output the index of the first occurrence of SearchTerm in the array (only once). 4. If SearchTerm is not found at all, output \"Not Found\". 5. The function must return the total count of occurrences found (0 if not found).
PastPaper.showAnswersPastPaper.hideAnswers
PastPaper.workedSolution
FUNCTION SearchAndFrequency(Words : ARRAY[1:100] OF STRING, NumElements : INTEGER, SearchTerm : STRING) RETURNS INTEGER DECLARE Index : INTEGER DECLARE Count : INTEGER DECLARE FirstIndex : INTEGER
Count <- 0 FirstIndex <- 0
FOR Index <- 1 TO NumElements IF Words[Index] = SearchTerm THEN Count <- Count + 1 IF FirstIndex = 0 THEN FirstIndex <- Index ENDIF ENDIF NEXT Index
IF Count > 0 THEN OUTPUT \"First occurrence at index: \", FirstIndex ELSE OUTPUT \"Not Found\" ENDIF
RETURN Count ENDFUNCTION
PastPaper.markingScheme
1 mark: Correct FUNCTION header with parameter definitions and RETURNS INTEGER. 1 mark: Correct local variable declarations (Index, Count, FirstIndex). 1 mark: Initializing Count to 0 and FirstIndex to 0 (or equivalent boolean flag). 2 marks: FOR loop running from 1 to NumElements to inspect elements. 1.2 marks: Correct comparison checking if Words[Index] matches SearchTerm. 1 mark: Logic to identify and record the FIRST occurrence's index only (e.g., checking if FirstIndex = 0). 1 mark: Incrementing the occurrence counter correctly inside the match condition. 1 mark: Post-loop conditional check to output the first index or 'Not Found'. 1 mark: Returning the total Count and ending with ENDFUNCTION.