Cambridge IGCSE · Thinka-original Practice Paper

2024 Cambridge IGCSE Computer Science (0478) Practice Paper with Answers

Thinka Nov 2024 (V3) Cambridge International A Level-Style Mock — Computer Science (0478)

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

Section 1 (Paper 1 Theory)

Answer all questions. Calculators are not allowed.
18 Question · 55.5 marks
Question 1 · single_select
1 marks
An error detection method calculates a value from a block of data (such as by summing the bytes) and transmits this calculated value along with the data. The receiving computer performs the same calculation on the received block of data and compares its result with the transmitted value to determine if any transmission errors occurred.

Which error detection method is being described?

A. Parity check
B. Checksum
C. Check digit
D. Symmetric encryption
Show answer & marking scheme

Worked solution

The correct answer is B. Checksum is an error detection method where a value is calculated from a block of data and transmitted alongside it to verify transmission integrity. Parity check (A) uses a single extra bit to check a byte. Check digit (C) is calculated from digits in a number and appended to check for human input errors during data entry. Symmetric encryption (D) is a security method to keep data confidential, not an error detection method.

Marking scheme

1 mark for identifying B (Checksum) as the correct answer.
Question 2 · single_select
1 marks
During the fetch stage of the fetch-decode-execute cycle, which CPU register holds the address of the next instruction that is to be fetched from memory?

A. Memory Address Register (MAR)
B. Program Counter (PC)
C. Current Instruction Register (CIR)
D. Memory Data Register (MDR)
Show answer & marking scheme

Worked solution

The correct answer is B. The Program Counter (PC) stores the address of the next instruction to be fetched. The MAR (A) holds the memory address currently being read from or written to. The CIR (C) holds the instruction currently being decoded and executed. The MDR (D) holds the data or instruction that has just been fetched from, or is about to be written to, memory.

Marking scheme

1 mark for identifying B (Program Counter (PC)) as the correct register.
Question 3 · single_select
1 marks
A web developer wants to compress a high-quality photograph to reduce its file size for faster loading on a website. They want to achieve a very small file size and are willing to permanently discard some redundant visual detail that is not easily noticed by the human eye.

Which type of compression and file format should the developer use?

A. Lossless compression using PNG
B. Lossy compression using JPEG
C. Lossless compression using ZIP
D. Lossy compression using MP3
Show answer & marking scheme

Worked solution

The correct answer is B. JPEG is an image file format that uses lossy compression, which permanently discards some photographic detail to significantly reduce the file size. PNG (A) and ZIP (C) use lossless compression, which does not discard any original data. MP3 (D) is an audio file format and cannot be used for photographic images.

Marking scheme

1 mark for identifying B (Lossy compression using JPEG) as the correct choice.
Question 4 · short answer
3 marks
State three reasons why computer programmers prefer to use hexadecimal representation rather than binary representation.
Show answer & marking scheme

Worked solution

Hexadecimal is used as a shorthand representation for binary. Programmers prefer it because: 1) It is shorter, meaning it occupies fewer characters on a screen compared to long binary strings. 2) It is much easier for humans to read, write, and interpret. 3) This readability reduces the frequency of data entry and typing errors when writing code or configuring memory addresses.

Marking scheme

1 mark per valid point, up to a maximum of 3 marks: - Hexadecimal is easier or quicker for a programmer to read/write/interpret. - It is less prone to human error when inputting or typing code. - It represents long binary sequences in a shorter format (occupying less screen space). - It is easier to identify debugging patterns or memory locations.
Question 5 · short answer
3 marks
Explain how a checksum is used to detect whether data has been corrupted during transmission.
Show answer & marking scheme

Worked solution

Before data is sent, the sender applies a mathematical algorithm to the block of data to calculate a checksum value. This checksum value is appended to the data packet and transmitted. Upon receiving the packet, the receiver executes the same algorithm on the received data block to compute a local checksum. The receiver then compares this newly calculated checksum with the received checksum. If the two values do not match, the receiver knows the data was corrupted during transmission and can request a retransmission.

Marking scheme

1 mark per distinct point, up to a maximum of 3 marks: - The sender calculates a checksum value using a specific algorithm on the block of data. - This checksum is transmitted alongside the data block. - The receiver applies the same algorithm/calculation to the received data. - The receiver compares the calculated checksum with the transmitted checksum. - If they do not match, an error is detected / retransmission is requested.
Question 6 · short answer
3 marks
Describe how asymmetric encryption differs from symmetric encryption.
Show answer & marking scheme

Worked solution

Asymmetric encryption utilizes a pair of mathematically linked keys: a public key, which is distributed openly and used to encrypt data, and a private key, which is kept secret by the owner and used to decrypt data. In contrast, symmetric encryption uses a single secret key that both parties must share and use for both encryption and decryption. Because asymmetric encryption does not require sharing the decryption key, it solves the key distribution vulnerability inherent in symmetric encryption.

Marking scheme

1 mark per valid comparison point, up to a maximum of 3 marks: - Asymmetric encryption uses two different keys (a public and a private key) whereas symmetric uses one single key. - In asymmetric encryption, the public key is used for encryption and the private key is used for decryption, whereas in symmetric encryption the same key performs both operations. - Asymmetric encryption is more secure as the private key never needs to be transmitted/shared, whereas symmetric requires secure distribution of the single key. - Asymmetric encryption is more computationally expensive/slower than symmetric encryption.
Question 7 · short answer
3 marks
Describe the role of the Program Counter (PC) during the fetch stage of the fetch-decode-execute cycle.
Show answer & marking scheme

Worked solution

The fetch stage begins with the Program Counter (PC) holding the address of the next instruction scheduled for execution. This memory address is sent to the Memory Address Register (MAR) over the address bus. Immediately after this transfer, the control unit increments the Program Counter (typically by 1) so that it holds the address of the next sequential instruction, preparing for the next cycle while the current instruction is being fetched from memory.

Marking scheme

1 mark per correct statement, up to a maximum of 3 marks: - The PC holds/stores the address of the next instruction to be fetched. - This address is copied/sent from the PC to the Memory Address Register (MAR). - The PC is incremented (by 1) so it points to the address of the next sequential instruction.
Question 8 · short answer
3 marks
Describe three main functions of a web browser.
Show answer & marking scheme

Worked solution

A web browser has several core tasks: First, it acts as a client by sending HTTP/HTTPS requests containing URLs to web servers and retrieving web resources (like HTML, CSS, images, and script files). Second, it interprets and renders these documents, compiling the HTML and CSS into a visually readable and interactive web page. Third, it provides essential management features for the client, including tracking browsing history, storing user bookmarks, storing cookies, and enabling navigation with back, forward, and refresh controls.

Marking scheme

1 mark per correct function described, up to a maximum of 3 marks: - Sends HTTP/HTTPS requests to web servers (using URLs). - Receives web pages / files from web servers. - Interprets/parses/translates HTML/CSS/JavaScript to render and display web pages. - Manages browser cookies (for session state or tracking). - Maintains user browsing history / bookmark lists. - Provides navigation controls (e.g. back, forward, refresh buttons, address bar).
Question 9 · short answer
3 marks
State three differences between a compiler and an interpreter.
Show answer & marking scheme

Worked solution

A compiler translates the entire high-level program in one single operation into machine code (object code), producing an executable file (like an .exe) that runs independently. It generates an error report only after compiling the whole program. An interpreter, conversely, translates and executes the source code line-by-line. It does not produce an executable file, meaning the source code is required every time the program runs. It stops execution the moment a syntax error is detected, making debugging faster during development.

Marking scheme

1 mark per clear comparative point, up to a maximum of 3 marks: - Compiler translates the entire code at once // Interpreter translates and executes line-by-line. - Compiler produces a standalone executable/object code file // Interpreter does not produce an executable file (source code must be parsed each run). - Compiler lists all syntax errors at the end of the process // Interpreter stops execution immediately when the first error is encountered. - Compiled code runs faster // Interpreted code runs slower. - Compiler requires a compilation step before running // Interpreter can begin execution immediately.
Question 10 · short answer
3 marks
An automated greenhouse system controls the ambient air temperature. Describe how sensors, a microprocessor, and actuators work together to keep the greenhouse at a constant temperature.
Show answer & marking scheme

Worked solution

In an automated greenhouse system, a temperature sensor continuously monitors the internal air temperature. The analogue signals from the sensor are converted into digital data (via an Analogue-to-Digital Converter) and sent to the microprocessor. The microprocessor receives this data and compares it against pre-set target temperature thresholds stored in its memory. If the temperature falls below the threshold, the microprocessor sends a control signal to an actuator (e.g., a heater) to switch on. If the temperature exceeds the upper threshold, it signals a different actuator (e.g., a window opening motor) to open. This loop is repeated continuously to maintain stable conditions.

Marking scheme

1 mark per key component/action in the automated loop, up to a maximum of 3 marks: - Sensor measures temperature and sends digital data (or analogue data converted via ADC) to the microprocessor. - Microprocessor compares the received temperature data against pre-programmed/pre-set values or thresholds. - Microprocessor sends control signals to an actuator (e.g., heater, fan, window motor) if the measured temperature is outside the threshold. - Actuator changes state (e.g., turns heater on/off, opens window) to alter the temperature. - The process forms a continuous feedback loop.
Question 11 · short answer
3 marks
Explain the operation of a 2-input XOR (Exclusive OR) logic gate, describing how its output is determined by the inputs.
Show answer & marking scheme

Worked solution

An XOR (Exclusive OR) gate evaluates two inputs. It outputs a logical high (1) only if the two inputs are of different states (one is 1 and the other is 0). If the inputs are identical (both are 0 or both are 1), the XOR gate outputs a logical low (0). For example, input states A=0, B=0 result in output 0; A=0, B=1 result in output 1; A=1, B=0 result in output 1; and A=1, B=1 result in output 0.

Marking scheme

1 mark per correct descriptive point, up to a maximum of 3 marks: - Outputs 1 / high / true when the two inputs are different (e.g. 0 and 1). - Outputs 0 / low / false when the two inputs are the same / identical (e.g. both 0 or both 1). - Correctly identifies the output for inputs (0,0) and (1,1) as 0. - Correctly identifies the output for inputs (0,1) and (1,0) as 1.
Question 12 · Short answer
3 marks
Explain how a checksum is used to detect errors during data transmission.
Show answer & marking scheme

Worked solution

To verify that data has not been corrupted during transmission, a checksum calculation is performed. Before transmission, the sender runs a specific algorithm on the block of data to generate a checksum value, which is appended to the payload. Once the data arrives, the receiving device executes the identical algorithm on the received data block. The receiver then compares its calculated checksum against the transmitted checksum. If the two values match, the data is assumed to be error-free; if they differ, an error is identified, and the receiver usually requests a retransmission.

Marking scheme

Award up to 3 marks from the following points:
- One mark for stating that the sender calculates a checksum value using an algorithm on the block of data.
- One mark for stating that the calculated checksum is sent/transmitted alongside the data block.
- One mark for stating that the receiver recalculates the checksum using the same algorithm on the received data.
- One mark for stating that the receiver compares the two checksum values (and if they differ, an error is detected / retransmission is requested).
Question 13 · Short answer
3 marks
Explain how symmetric encryption is used to protect data during transmission.
Show answer & marking scheme

Worked solution

Symmetric encryption is a security method where a single shared secret key is utilized by both communicating parties. Prior to transmission, the sender applies an encryption algorithm and the secret key to convert the readable data (plaintext) into an unreadable format (ciphertext). The ciphertext is then sent across the network. Upon receipt, the recipient uses the exact same secret key to decrypt the ciphertext, reversing the algorithm to restore the original plaintext.

Marking scheme

Award up to 3 marks from the following points:
- One mark for explaining that symmetric encryption uses a single/the same secret key for both encryption and decryption.
- One mark for stating that the sender encrypts the plaintext into ciphertext using this secret key (and an algorithm) prior to transmission.
- One mark for stating that the ciphertext is transmitted across the network (preventing unauthorized users from reading it).
- One mark for stating that the receiver decrypts the ciphertext back into readable plaintext using the identical key.
Question 14 · Structured explanation
4.5 marks
A telemetry system transmits data blocks of 4 bytes. Explain how a checksum is used to detect transmission errors in these blocks. Your explanation should cover how the checksum is generated before transmission, how it is verified at the receiving end, and how an error is identified.
Show answer & marking scheme

Worked solution

1. Before transmission: The sender sums the numeric values of all data bytes in the block. 2. If the sum exceeds the maximum value (e.g., 255 for 1 byte), an overflow algorithm like modulo 256 is applied to keep it within the size limit. 3. This calculated value (checksum) is appended to the end of the data payload. 4. During transmission: Both the payload and checksum are sent over the network. 5. At receiver: The receiver separates the checksum from the data bytes and recalculates the sum of the received data bytes. 6. Verification: The receiver compares its recalculated checksum to the transmitted checksum. 7. If they match, the data is accepted. If they differ, an error has occurred, and the receiver requests the block to be retransmitted.

Marking scheme

1.5 marks for generation: 0.5 marks for summing the values of the bytes, 0.5 marks for applying modulo/overflow correction, 0.5 marks for appending the checksum to the payload. 1.5 marks for reception/verification: 0.5 marks for recalculating the sum on the receiving end, 0.5 marks for comparing the recalculated checksum with the received checksum, 0.5 marks for identifying matching checksums as successful transmission. 1.5 marks for error handling: 0.5 marks for explaining that non-matching checksums indicate an error, 0.5 marks for mentioning that it cannot correct the error (only detect it), 0.5 marks for stating a retransmission request (ARQ) is triggered.
Question 15 · Structured explanation
4.5 marks
When a user types a web address such as https://www.cie.org.uk into a browser, a Domain Name System (DNS) server is used. Explain the step-by-step process of how the DNS resolves this URL into an IP address to allow the web page to load.
Show answer & marking scheme

Worked solution

1. The user requests a URL; the browser queries its local cache for the IP address. 2. If not found, the browser contacts the ISP's DNS recursive resolver. 3. The recursive resolver queries a DNS root server, which directs it to the appropriate Top-Level Domain (TLD) server (e.g., .uk). 4. The TLD server directs the resolver to the authoritative name server for the specific domain (cie.org.uk). 5. The authoritative server returns the IP address to the recursive resolver. 6. The resolver caches this IP address and passes it back to the web browser. 7. The browser uses this IP address to directly establish a connection with the web server hosting the website.

Marking scheme

1 mark for initiating query: explaining the browser checking local cache first and then contacting the local/recursive DNS resolver. 1 mark for hierarchy routing: explaining the recursive resolver querying the root DNS server, which directs to the TLD server. 1 mark for authoritative resolution: explaining how the TLD server directs to the authoritative DNS server to retrieve the actual IP address. 1 mark for completion: explaining how the IP address is returned to the resolver, cached, and sent back to the browser. 0.5 marks for subsequent action: stating that the browser then uses the IP address to request the webpage directly from the target web server.
Question 16 · Structured explanation
4.5 marks
An operating system uses interrupts to handle hardware events. Describe the sequence of events that occurs when a printer runs out of paper during a print job, focusing on how the CPU and operating system handle this interrupt.
Show answer & marking scheme

Worked solution

1. The printer hardware detects a paper-out status and generates an interrupt signal. 2. This signal is sent along the control bus to the CPU. 3. The CPU finishes its current instruction/fetch-decode-execute cycle. 4. The CPU saves its current state (contents of the Program Counter (PC) and other registers) onto a stack. 5. The CPU identifies the interrupt source and loads the address of the corresponding Interrupt Service Routine (ISR) into the PC. 6. The ISR executes, displaying an error message ('Out of Paper') to the user and pausing the print queue. 7. Once the ISR completes, the CPU restores the previous state from the stack and resumes the original task where it left off.

Marking scheme

1 mark for signal generation: explaining that the printer detects the status and sends an interrupt signal to the CPU via the control bus. 1 mark for state preservation: explaining that the CPU finishes its current instruction cycle and saves its current register values (e.g., Program Counter) onto a stack. 1 mark for ISR execution: explaining that the CPU calls/executes the specific Interrupt Service Routine (ISR) to handle the out-of-paper warning. 1 mark for system action: explaining the ISR's action, such as displaying a warning to the user and halting the print queue. 0.5 marks for resumption: explaining that after handling, the saved register values are restored from the stack, and execution of the original program resumes.
Question 17 · Structured explanation
4.5 marks
An automotive diagnostic system uses an expert system to diagnose engine faults. Explain how the components of this expert system (user interface, knowledge base, rules base, and inference engine) interact to provide a diagnosis to a mechanic.
Show answer & marking scheme

Worked solution

1. The mechanic enters engine symptoms (e.g., 'engine misfires', 'check engine light is on') using the user interface. 2. The user interface passes these inputs to the inference engine. 3. The knowledge base contains verified domain-specific facts about engine performance and components. 4. The rules base contains the logical conditional statements (IF-THEN rules) used to link symptoms to causes. 5. The inference engine uses inference algorithms (such as forward chaining starting from symptoms, or backward chaining starting from potential faults) to reason through the rules base. 6. By applying rules to the knowledge base and the user's inputs, the inference engine arrives at a diagnostic conclusion. 7. The explanation facility explains the reasoning path to the mechanic. 8. The final diagnosis and explanation are outputted via the user interface.

Marking scheme

1 mark for User Interface interaction: explaining how the user inputs query/symptoms into the interface and how final results/explanations are returned to them. 1 mark for Knowledge and Rule Bases differentiation: explaining that the knowledge base stores static facts/data, while the rules base contains the logical IF-THEN rules. 1 mark for Inference Engine function: explaining that the inference engine acts as the reasoning mechanism that applies rules to facts to draw conclusions. 1 mark for Chaining/Search techniques: describing how the inference engine queries the bases using forward chaining (symptoms to cause) or backward chaining (cause to symptoms). 0.5 marks for Explanation Facility: explaining that the system provides the logical steps or justification behind its diagnosis to build trust with the mechanic.
Question 18 · Structured explanation
4.5 marks
A client wants to securely transmit sensitive financial details to their bank using asymmetric encryption. Describe the process of how keys are distributed, how the data is encrypted, and how it is decrypted to ensure confidentiality.
Show answer & marking scheme

Worked solution

1. Key generation: The bank's system generates a pair of mathematically linked keys: a public key and a private key. 2. Key distribution: The bank distributes its public key freely to the client (and anyone else), while keeping the private key strictly confidential on the bank's secure server. 3. Encryption: The client's browser uses the bank's public key to encrypt the sensitive financial details, turning the plain text into ciphertext. 4. Transmission: The ciphertext is sent over the insecure internet. Even if intercepted, it cannot be decrypted without the correct private key. 5. Decryption: Once received, the bank uses its matching private key to decrypt the ciphertext back into plain text. 6. Confidentiality: Since only the bank has access to the private key, no third party can read the intercepted data, securing the transmission.

Marking scheme

1 mark for Key Pair definition: explaining that asymmetric encryption uses two different but mathematically linked keys (a public key and a private key). 1 mark for Distribution: explaining that the public key is shared freely with the client, but the private key is kept strictly confidential/secret by the bank. 1 mark for Encryption phase: explaining that the sender (client) encrypts the plain text data using the recipient's (bank's) public key. 1 mark for Decryption phase: explaining that the receiver (bank) decrypts the ciphertext using their matching private key. 0.5 marks for Confidentiality logic: highlighting that only the private key can decrypt what was encrypted by the public key, preventing unauthorized interceptors from reading the data.

Section 2 (Paper 2 Practical)

Answer all questions. Write all programs in pseudocode or program code.
7 Question · 44 marks
Question 1 · Syntax Completion
4 marks
An algorithm is required to find the minimum value in a 1D array named Numbers which contains 100 integers (indexed from 0 to 99). Complete the following pseudocode by writing the missing terms in the blank spaces numbered 1 to 4. (Note: Each line is separated by a | character) | DECLARE Numbers : ARRAY[0:99] OF INTEGER | DECLARE Index : INTEGER | DECLARE MinVal : INTEGER | MinVal <- Numbers[0] | FOR Index <- 1 TO [ Blank 1 ] | IF Numbers[Index] [ Blank 2 ] MinVal THEN | [ Blank 3 ] <- Numbers[[ Blank 4 ]] | ENDIF | NEXT Index
Show answer & marking scheme

Worked solution

Blank 1 must be 99 because the array is declared from 0 to 99, and the loop starts at 1, so the final index to check is the last element, which is 99. | Blank 2 must be < (less than) to identify if the current array element is smaller than the current minimum value stored in MinVal. | Blank 3 must be MinVal as this is the variable being updated with the new minimum value. | Blank 4 must be Index because we are copying the value at the current loop index (Numbers[Index]) into the MinVal variable.

Marking scheme

1 mark for Blank 1: 99 | 1 mark for Blank 2: < (accept <= or LESS THAN) | 1 mark for Blank 3: MinVal | 1 mark for Blank 4: Index
Question 2 · Syntax Completion
4 marks
A program is required to open an existing text file called 'Students.txt' in read mode. It must read each name from the file and count how many names start with the letter 'A'. Complete the pseudocode below by writing the appropriate commands or terms in the blank spaces numbered 1 to 4. (Note: Each line is separated by a | character) | DECLARE StudentName : STRING | DECLARE Count : INTEGER | Count <- 0 | OPENFILE 'Students.txt' FOR [ Blank 1 ] | WHILE NOT [ Blank 2 ]('Students.txt') DO | [ Blank 3 ] 'Students.txt', StudentName | IF SUBSTRING(StudentName, 1, 1) = 'A' THEN | Count <- Count + 1 | ENDIF | ENDWHILE | [ Blank 4 ] 'Students.txt'
Show answer & marking scheme

Worked solution

Blank 1 must be READ as the file must be opened for reading. | Blank 2 must be EOF (End Of File) to ensure the loop runs until the end of the file is reached. | Blank 3 must be READFILE to read the next record/line from the file into the variable StudentName. | Blank 4 must be CLOSEFILE to properly close the open file handle.

Marking scheme

1 mark for Blank 1: READ (accept 'Read' or 'read') | 1 mark for Blank 2: EOF (accept 'eof') | 1 mark for Blank 3: READFILE (accept 'Readfile' or 'readfile') | 1 mark for Blank 4: CLOSEFILE (accept 'Closefile' or 'closefile')
Question 3 · Syntax Completion
4 marks
A user-defined function CalculateDiscount is designed to take two parameters: Price (a decimal value representing the cost of an item) and Member (a true/false value representing whether the customer has a membership). The function returns the final price: if the customer is a member, they receive a 10% discount; otherwise, they pay the original price. Complete the pseudocode function below by filling in the blanks numbered 1 to 4. (Note: Each line is separated by a | character) | FUNCTION CalculateDiscount(Price : REAL, Member : [ Blank 1 ]) [ Blank 2 ] REAL | IF Member = TRUE THEN | RETURN Price * [ Blank 3 ] | ELSE | RETURN [ Blank 4 ] | ENDIF | ENDFUNCTION
Show answer & marking scheme

Worked solution

Blank 1 must be BOOLEAN as the Member parameter holds a true/false value. | Blank 2 must be RETURNS because in standard Cambridge pseudocode, the return data type of a function is declared using the keyword RETURNS. | Blank 3 must be 0.9 (or 0.90) because a 10% discount means the customer pays 90% of the price (Price * 0.9). | Blank 4 must be Price because if they are not a member, the function should return the original, unaltered price.

Marking scheme

1 mark for Blank 1: BOOLEAN (accept 'boolean' or 'BOOL') | 1 mark for Blank 2: RETURNS (accept 'returns' or ':') | 1 mark for Blank 3: 0.9 (accept '0.90' or '1 - 0.1') | 1 mark for Blank 4: Price (accept 'price')
Question 4 · Syntax Completion
4 marks
The following algorithm performs a linear search on a 1D array named Names containing 50 strings (indexed 1 to 50) to locate a value stored in SearchName. The variable Position is used to store the index where the search name is found, or remain -1 if the name is not found in the array. Complete the pseudocode by writing the missing terms in the blank spaces numbered 1 to 4. (Note: Each line is separated by a | character) | DECLARE Names : ARRAY[1:50] OF STRING | DECLARE SearchName : STRING | DECLARE Index : INTEGER | DECLARE Found : BOOLEAN | DECLARE Position : INTEGER | Index <- 1 | Found <- FALSE | Position <- -1 | WHILE (Index <= 50) AND ([ Blank 1 ] = FALSE) DO | IF Names[Index] = [ Blank 2 ] THEN | Found <- TRUE | Position <- [ Blank 3 ] | ELSE | Index <- [ Blank 4 ] | ENDIF | ENDWHILE
Show answer & marking scheme

Worked solution

Blank 1 must be Found to ensure the loop stops searching once the match is located. | Blank 2 must be SearchName because we are comparing the current array element against the name we want to find. | Blank 3 must be Index because when a match is found, its position (the current loop index) is stored in the Position variable. | Blank 4 must be Index + 1 because we need to increment the counter variable to move to the next item in the array if the current item is not a match.

Marking scheme

1 mark for Blank 1: Found (accept 'found') | 1 mark for Blank 2: SearchName (accept 'searchname') | 1 mark for Blank 3: Index (accept 'index') | 1 mark for Blank 4: Index + 1 (accept 'index + 1')
Question 5 · Trace Table
6.5 marks
An algorithm has been written in pseudocode to find the largest positive difference between any two consecutive decreasing values in an array of five numbers.

```
DECLARE Numbers : ARRAY[1:5] OF INTEGER
Numbers[1] <-- 12
Numbers[2] <-- 7
Numbers[3] <-- 15
Numbers[4] <-- 4
Numbers[5] <-- 9

DECLARE Count, Temp, Flag : INTEGER
Flag <-- 0
Temp <-- 0

FOR Count <-- 1 TO 4
IF Numbers[Count] > Numbers[Count + 1] THEN
Temp <-- Numbers[Count] - Numbers[Count + 1]
IF Temp > Flag THEN
Flag <-- Temp
ENDIF
ENDIF
NEXT Count
```

Complete the trace table for this algorithm.

| Count | Numbers[Count] | Numbers[Count+1] | Temp | Flag |
|---|---|---|---|---|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
Show answer & marking scheme

Worked solution

The trace table tracks variables as they change during the execution of the loops:
- Initially, Flag is initialized to 0.
- Loop iteration 1 (Count = 1): Numbers[1] is 12, Numbers[2] is 7. Since 12 > 7, Temp is calculated as 12 - 7 = 5. Since Temp (5) > Flag (0), Flag becomes 5.
- Loop iteration 2 (Count = 2): Numbers[2] is 7, Numbers[3] is 15. Since 7 is not greater than 15, no action is taken.
- Loop iteration 3 (Count = 3): Numbers[3] is 15, Numbers[4] is 4. Since 15 > 4, Temp is calculated as 15 - 4 = 11. Since Temp (11) > Flag (5), Flag becomes 11.
- Loop iteration 4 (Count = 4): Numbers[4] is 4, Numbers[5] is 9. Since 4 is not greater than 9, no action is taken.

Marking scheme

6.5 marks total:
- 1 mark: Initializing Flag to 0 on the first line.
- 1 mark: Correct sequence of loop counter variable Count (1, 2, 3, 4).
- 1.5 marks: Correct values of Numbers[Count] and Numbers[Count+1] on the relevant active steps (0.5 marks per correctly traced comparison row).
- 1.5 marks: Correct values in Temp column (5 on row 1, 11 on row 3; leaving empty/unchanged on rows 2 and 4).
- 1.5 marks: Correct updates to Flag column (5 on row 1, 11 on row 3; leaving empty/unchanged on rows 2 and 4).
Question 6 · Truth Table
6.5 marks
A logic circuit has the following Boolean expression:

\( X = (\text{NOT } A \text{ AND } B) \text{ OR } (B \text{ XOR } C) \)

Complete the truth table for this expression.

| A | B | C | NOT A AND B | B XOR C | 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 | | | |
Show answer & marking scheme

Worked solution

Let's evaluate each column step-by-step:
1. Column 'NOT A AND B': Only outputs 1 when A is 0 and B is 1. This occurs when (A, B) = (0, 1), which corresponds to rows 3 and 4. All other rows output 0.
2. Column 'B XOR C': Outputs 1 when B and C have different logic states. This occurs when (B, C) = (0, 1) or (1, 0), which corresponds to rows 2, 3, 6, and 7. All other rows output 0.
3. Column 'X' (OR of the previous two columns): Outputs 1 if either of the previous columns has a 1. This occurs on rows 2, 3, 4, 6, and 7. Rows 1, 5, and 8 output 0.

Marking scheme

6.5 marks total:
- 2 marks: Column 'NOT A AND B' (all 8 correct = 2 marks, 1-2 errors = 1 mark, >2 errors = 0 marks).
- 2 marks: Column 'B XOR C' (all 8 correct = 2 marks, 1-2 errors = 1 mark, >2 errors = 0 marks).
- 2.5 marks: Column 'X' (all 8 correct = 2.5 marks, 1-2 errors = 1.5 marks, 3-4 errors = 0.5 marks, else 0 marks).
Question 7 · 15-Mark Design Scenario
15 marks
A school is setting up an automated 'Eco-Points Recycling Station' to encourage recycling. Students scan their 4-digit Student ID (from 1000 to 9999) and deposit plastic bottles and aluminum cans.

Write an algorithm, using pseudocode or program code, that meets the following requirements:
- Inputs a student's ID, validating that it is a 4-digit number (1000 to 9999). An input of -1 must terminate the program.
- For each valid student:
- Inputs the number of plastic bottles recycled (0 to 50 inclusive).
- Inputs the number of aluminum cans recycled (0 to 50 inclusive).
- Validates both counts. If any count is invalid, or if both counts are 0, the program must display an error message and prompt the user to re-enter the values.
- Calculates the points earned: 5 points per bottle, and 8 points per can.
- Outputs the points earned for that student.
- When -1 is entered for the Student ID, the program must stop and output:
- The total number of bottles recycled by all students.
- The total number of cans recycled by all students.
- The Student ID and points of the student who earned the highest points in a single transaction (if there is a tie, display the first student).

You must use pseudocode or program code. Your algorithm should include appropriate prompts for entry of data, validation of inputs, and meaningful output messages.
Show answer & marking scheme

Worked solution

DECLARE TotalBottles : INTEGER
DECLARE TotalCans : INTEGER
DECLARE MaxPoints : INTEGER
DECLARE MaxStudentID : INTEGER
DECLARE StudentID : INTEGER
DECLARE Bottles : INTEGER
DECLARE Cans : INTEGER
DECLARE Points : INTEGER

TotalBottles <- 0
TotalCans <- 0
MaxPoints <- -1
MaxStudentID <- 0

OUTPUT "Enter Student ID (1000 to 9999) or -1 to stop:"
INPUT StudentID

WHILE StudentID <> -1 DO
WHILE (StudentID < 1000 OR StudentID > 9999) AND StudentID <> -1 DO
OUTPUT "Invalid ID. Enter a 4-digit ID (1000 to 9999) or -1 to stop:"
INPUT StudentID
ENDWHILE

IF StudentID <> -1 THEN
OUTPUT "Enter number of bottles (0 to 50):"
INPUT Bottles
WHILE Bottles < 0 OR Bottles > 50 DO
OUTPUT "Invalid number. Enter 0 to 50:"
INPUT Bottles
ENDWHILE

OUTPUT "Enter number of cans (0 to 50):"
INPUT Cans
WHILE Cans < 0 OR Cans > 50 DO
OUTPUT "Invalid number. Enter 0 to 50:"
INPUT Cans
ENDWHILE

WHILE Bottles = 0 AND Cans = 0 DO
OUTPUT "You must recycle at least one item. Re-enter bottles (0-50):"
INPUT Bottles
WHILE Bottles < 0 OR Bottles > 50 DO
OUTPUT "Invalid number. Enter 0 to 50:"
INPUT Bottles
ENDWHILE

OUTPUT "Re-enter cans (0-50):"
INPUT Cans
WHILE Cans < 0 OR Cans > 50 DO
OUTPUT "Invalid number. Enter 0 to 50:"
INPUT Cans
ENDWHILE
ENDWHILE

Points <- (Bottles * 5) + (Cans * 8)
OUTPUT "Student ", StudentID, " earned ", Points, " points in this session."

TotalBottles <- TotalBottles + Bottles
TotalCans <- TotalCans + Cans

IF Points > MaxPoints THEN
MaxPoints <- Points
MaxStudentID <- StudentID
ENDIF

OUTPUT "Enter Student ID (1000 to 9999) or -1 to stop:"
INPUT StudentID
ENDIF
ENDWHILE

OUTPUT "Total bottles recycled overall: ", TotalBottles
OUTPUT "Total cans recycled overall: ", TotalCans
IF MaxPoints <> -1 THEN
OUTPUT "Highest single transaction points: ", MaxPoints, " earned by Student ", MaxStudentID
ELSE
OUTPUT "No transactions were completed."
ENDIF

Marking scheme

Max 15 marks total:
- 1 mark: Initialising variables for overall bottle totals, overall can totals, and maximum tracker.
- 1 mark: Set up of a conditional outer loop (WHILE / REPEAT) to run continuously until -1 is entered.
- 2 marks: Validation of Student ID (ensures range 1000 to 9999 is checked correctly without crashing on -1).
- 2 marks: Input and range validation for bottles and cans individually (ensuring range 0 to 50 inclusive).
- 2 marks: Logic to ensure a combination of 0 bottles and 0 cans is rejected and forces re-input.
- 2 marks: Correct points calculation (Bottles * 5 + Cans * 8) and individual user output.
- 1 mark: Correctly accumulating global counts for overall total bottles and overall total cans.
- 2 marks: Storing and updating the maximum points earned in a single run along with the associated student ID.
- 2 marks: Printing the overall summary results (total bottles, total cans, and maximum details) with descriptive, user-friendly labels.

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