An original Thinka practice paper modelled on the structure and difficulty of the Jun 2024 Cambridge International A Level Computer Science paper. Not affiliated with or reproduced from Cambridge.
卷一 (Principles of Computer Science)
Answer all questions. You must not use a calculator.
6 題目 · 79.98 分
題目 1 · Short Answer
13.33 分
Consider the following pseudocode algorithm that processes an array of integers: SET total TO 0; SET count TO 0; SET index TO 0; SET numbers TO [3, -5, 7, 4, 9, -2]; WHILE index < 6 DO; SET current TO numbers[index]; IF current > 0 THEN; IF current MOD 2 != 0 THEN; SET total TO total + current; SET count TO count + 1; ENDIF; ENDIF; SET index TO index + 1; ENDWHILE; IF count > 0 THEN; SET average TO total / count; ELSE; SET average TO 0; ENDIF. (a) Complete a trace table showing the values of index, current, total, count, and average as they change. (8 marks) (b) State the final value of average after execution. (2 marks) (c) Explain why checking count > 0 is necessary before calculating the average. (3.33 marks)
查看答案詳解收起答案詳解
解題
For part (a), tracing execution: Index 0: current=3, positive odd, total=3, count=1. Index 1: current=-5, negative, skipped. Index 2: current=7, positive odd, total=10, count=2. Index 3: current=4, positive even, skipped. Index 4: current=9, positive odd, total=19, count=3. Index 5: current=-2, negative, skipped. Index 6: loop ends. For part (b), average = total / count = 19 / 3 = 6.33. For part (c), if the array has no numbers fitting the condition, count remains 0. Dividing by 0 causes a runtime crash, which this check avoids.
評分準則
(a) 8 marks total: 2 marks for tracking index correctly up to 6, 2 marks for identifying positive odd values (3, 7, 9), 2 marks for updating total to 3, then 10, then 19, 2 marks for updating count to 1, then 2, then 3. (b) 2 marks: 1 mark for showing division 19/3, 1 mark for correct value of 6.33. (c) 3.33 marks: 1.33 marks for identifying division-by-zero risk, 1 mark for explaining that it prevents a program crash, 1 mark for identifying that this scenario occurs when count is 0.
題目 2 · Short Answer
13.33 分
A school is upgrading its Local Area Network (LAN) server connections. The network administrator is comparing physical star and full mesh topologies, and configuring routers. (a) Compare a physical star topology and a full mesh topology by stating two advantages and two disadvantages of a full mesh topology compared to a star topology. (4 marks) (b) Explain the difference between an IP address and a MAC address in terms of their purpose, assignment, and network layer. (6 marks) (c) Explain the role of a router in packet switching. (3.33 marks)
查看答案詳解收起答案詳解
解題
For part (a), full mesh connects every node to every other node, providing backup paths (redundancy) and high bandwidth, but requires excessive cables and ports. For part (b), IP addresses (Logical, Network Layer, changeable) routing packets across subnets, while MAC addresses (Physical, Data Link Layer, unchangeable) route within local segments. For part (c), routers analyze packet headers, find destination IPs, and use routing metrics/tables to forward packets to the next hop.
評分準則
(a) 4 marks: 1 mark for each valid advantage of mesh (max 2), 1 mark for each valid disadvantage of mesh (max 2). (b) 6 marks: 2 marks for contrasting purposes, 2 marks for contrasting assignment, 2 marks for contrasting network layers. (c) 3.33 marks: 1.33 marks for identifying destination IP check, 1 mark for path decision using routing table, 1 mark for forwarding action.
題目 3 · Short Answer
13.33 分
An express delivery company is planning to replace its fleet of diesel delivery vans with fully autonomous electric delivery drones. (a) Discuss two potential positive environmental impacts and two potential negative environmental impacts of this change. (4 marks) (b) From an ethical and legal perspective, discuss how liability is determined if an autonomous drone crashes and causes property damage. (5 marks) (c) Explain how the Right to be Forgotten might apply if drone cameras record members of the public during routes. (4.33 marks)
查看答案詳解收起答案詳解
解題
For part (a), switching to electric drones removes diesel exhaust, improving urban air quality, but battery manufacturing and disposal (toxic lithium) and non-renewable electricity grids present negative environmental trade-offs. For part (b), legal responsibility relies on whether crash causes were code defects (manufacturer) or physical maintenance neglect (operator). For part (c), companies must process requests to erase captured video footage of individuals and should actively mask/blur faces to avoid unauthorized storage of private data.
評分準則
(a) 4 marks: 1 mark for each of two positive environmental impacts, 1 mark for each of two negative environmental impacts. (b) 5 marks: 2 marks for explaining manufacturer vs operator liability, 2 marks for software developers' safety-first engineering duties, 1 mark for compulsory liability insurance needs. (c) 4.33 marks: 1.33 marks for identifying images as personal data, 1 mark for identifying deletion rights, 1 mark for technical mitigation steps (e.g., blurring, low retention), 1 mark for providing pathways for user deletion requests.
題目 4 · Short Answer
13.33 分
(a) Describe the specific role of the following registers during the fetch phase of the FDE cycle: (i) Program Counter (PC), (ii) Memory Address Register (MAR), (iii) Memory Data Register (MDR). (6 marks) (b) Explain how cache memory improves CPU performance, and why having too much cache is impractical. (4 marks) (c) Identify the effect of increasing the bus width of the data bus from 32-bit to 64-bit on system performance. (3.33 marks)
查看答案詳解收起答案詳解
解題
For part (a): (i) PC holds the next instruction address and increments. (ii) MAR copies the PC address via address bus to point to main memory. (iii) MDR receives the binary instruction from RAM via data bus. For part (b), Cache utilizes Static RAM (SRAM) which is extremely fast compared to DRAM (RAM), minimizing CPU idle cycles. SRAM is physically massive per bit and highly expensive, limiting practical sizes on chip dies. For part (c), doubling the data bus width allows 8 bytes to pass simultaneously instead of 4, reducing required read cycles for large values.
評分準則
(a) 6 marks total: 2 marks for explaining PC (holds address, increments), 2 marks for explaining MAR (holds address to access memory), 2 marks for explaining MDR (holds actual data fetched). (b) 4 marks: 2 marks for explaining access speed and locality of cache, 2 marks for cost, physical size, and thermal dissipation limitations of SRAM. (c) 3.33 marks: 1.33 marks for explaining double bandwidth per cycle, 1 mark for reduction in bus cycles, 1 mark for faster data processing throughput.
題目 5 · Short Answer
13.33 分
A security alarm system has inputs W (Window open: 1=open), M (Motion detected: 1=detected), and A (Alarm Active: 1=armed). The output alarm sound (S) is triggered (1) if: (Condition 1) The system is armed (A=1) AND either the window is open (W=1) OR motion is detected (M=1), OR (Condition 2) The system is armed (A=1) AND both window is open (W=1) AND motion is detected (M=1). (a) Write the initial Boolean expression for S. (3 marks) (b) Construct a truth table showing columns for A, W, M, and output S. (6 marks) (c) Simplify the Boolean expression using logical deduction or Boolean algebra, showing your steps. (4.33 marks)
查看答案詳解收起答案詳解
解題
For part (a), the literal translation is \(S = (A \cdot (W + M)) + (A \cdot W \cdot M)\). For part (b), mapping the truth table shows S is 1 for inputs (1,0,1), (1,1,0), and (1,1,1), and 0 for all other 5 combinations. For part (c), we simplify: \(S = A \cdot W + A \cdot M + A \cdot W \cdot M\). Factoring out \(A \cdot W\) yields \(A \cdot W \cdot (1 + M) + A \cdot M\). Since \(1 + M = 1\), the expression becomes \(A \cdot W + A \cdot M\), which factors to \(A \cdot (W + M)\).
評分準則
(a) 3 marks: 1.5 marks for first term, 1.5 marks for second term combined with OR. (b) 6 marks: 2 marks for list of all 8 binary states, 4 marks for the output values (1 mark per 2 correct outputs). (c) 4.33 marks: 1.33 marks for identifying redundant conditions (since both W and M open implies at least one is open), 2 marks for correct algebraic steps, 1 mark for final expression \(S = A \cdot (W + M)\).
題目 6 · Short Answer
13.33 分
(a) A digital sound file is recorded with a sample rate of 48 kHz, a bit depth of 24 bits, and 2 channels (stereo). Calculate the file size in Megabytes (MB) for a 3-minute recording. Assume 1 MB = 1,000,000 bytes. Show your working. (5 marks) (b) Explain the trade-off between audio quality and file size when decreasing the sample rate. (4 marks) (c) Describe how a bitmap image is represented in binary, including the role of metadata and colour depth. (4.33 marks)
查看答案詳解收起答案詳解
解題
For part (a), File size = sample rate × bit depth × channels × seconds. Convert 24 bits to 3 bytes. Convert 3 minutes to 180 seconds. Size = \(48,000 \times 3 \times 2 \times 180 = 51,840,000\) bytes. Dividing by 1,000,000 gives 51.84 MB. For part (b), smaller sample rate captures fewer data points per second, saving storage space, but it fails to capture high-frequency components resulting in poorer, muffled audio. For part (c), an image is a 2D grid of pixels. Colour depth determines bits per pixel (e.g., 8-bit allows 256 colours). Metadata tells the processor the dimensions and structure so it can render the pixels correctly.
評分準則
(a) 5 marks: 1 mark for duration conversion (180s), 1 mark for bit depth conversion (3 bytes), 1 mark for correct formula substitution, 1 mark for correct byte calculation (51,840,000), 1 mark for correct division to 51.84 MB. (b) 4 marks: 2 marks for details of space savings (fewer samples recorded), 2 marks for explanation of sound quality degradation (cannot resolve high frequencies). (c) 4.33 marks: 1.33 marks for describing the pixel grid representation, 1 mark for defining colour depth, 1 mark for defining metadata, 1 mark for describing metadata's role in rendering.
卷二 (Application of Computational Thinking)
Answer all questions. Complete practical tasks on your development workstation.
6 題目 · 79.98 分
題目 1 · Practical Coding & Algorithmic Design
13.33 分
Write a Python subprogram named `validatePassword` that takes a string parameter `password` and returns `True` if it meets all the following security requirements, or `False` otherwise: 1. The password must be at least 8 characters in length. 2. It must contain at least one uppercase letter. 3. It must contain at least one numerical digit. 4. It must not contain the word "school" (case-insensitive) anywhere in the string.
# Rule 4: Case-insensitive check for "school" if "school" in password.lower(): return False
has_upper = False has_digit = False
# Iterate through characters to check Rules 2 and 3 for char in password: if char.isupper(): has_upper = True if char.isdigit(): has_digit = True
return has_upper and has_digit ```
評分準則
- 2 marks: Length check logic (returns `False` if length is less than 8). - 2 marks: Substring check logic (converts to lowercase and checks if "school" is in the password, returning `False` if true). - 3 marks: Iterates through each character to check for at least one uppercase letter (e.g., using `isupper()`). - 3 marks: Iterates through each character to check for at least one digit (e.g., using `isdigit()`). - 3.33 marks: Syntactically correct function structure, using conditional checks, maintaining logic flags, and returning a final Boolean value.
題目 2 · Practical Coding & Algorithmic Design
13.33 分
An algorithm is required to analyze temperature records and locate all "peaks". A peak is an index in a 1D list where the temperature is strictly greater than its adjacent elements. - For index 0, it is a peak if it is strictly greater than the element at index 1. - For the last index, it is a peak if it is strictly greater than the second-to-last element. - For any other index \( i \), it is a peak if it is strictly greater than the elements at \( i-1 \) and \( i+1 \).
Write a Python function `findPeaks(temperatures)` that takes a list of real numbers and returns a list containing all the indices that are peaks.
查看答案詳解收起答案詳解
解題
```python def findPeaks(temperatures): peaks = [] n = len(temperatures) if n == 0: return peaks if n == 1: return [0]
# Check boundary condition: start of list if temperatures[0] > temperatures[1]: peaks.append(0)
# Check internal list elements for i in range(1, n - 1): if temperatures[i] > temperatures[i-1] and temperatures[i] > temperatures[i+1]: peaks.append(i)
# Check boundary condition: end of list if temperatures[n-1] > temperatures[n-2]: peaks.append(n-1)
return peaks ```
評分準則
- 2 marks: Correctly handles empty arrays and single-element arrays to prevent index out of bounds errors. - 3 marks: Correctly checks the first element comparison against only index 1. - 3 marks: Correctly checks the last element comparison against only index \( n-2 \). - 3 marks: Employs a loop from index 1 to \( n-2 \) checking if the element is strictly greater than both its left and right neighbors. - 2.33 marks: Correctly appends matching indices to a tracking list and returns the list of indices.
題目 3 · Practical Coding & Algorithmic Design
13.33 分
A school stores student names and test scores in a comma-separated text file. Each line of the file is formatted as `Name,Score` (e.g., `Alice,85`).
Write a Python function `calculateAverageScore(filename, threshold)` that opens this file, reads its contents line-by-line, and returns the average score of all students who scored strictly above the specified `threshold`.
Your code must handle instances where no students exceed the threshold by returning `0.0`. Ensure the file is safely closed after processing.
查看答案詳解收起答案詳解
解題
```python def calculateAverageScore(filename, threshold): total_score = 0 count = 0 try: # Open file safely using a context manager with open(filename, 'r') as file: for line in file: line = line.strip() if not line: continue # Split line into Name and Score parts = line.split(',') score = float(parts[1]) # Accumulate and count scores strictly exceeding threshold if score > threshold: total_score += score count += 1 except FileNotFoundError: return 0.0
# Prevent division by zero if count == 0: return 0.0 return total_score / count ```
評分準則
- 2 marks: Correctly opens the file in read mode and ensures the file is closed (using `with open` or explicitly calling `.close()` in a finally block). - 3 marks: Safely iterates through lines and splits using `,` as a delimiter. - 3 marks: Correctly extracts and converts the score component to a numeric type (float or integer). - 3 marks: Conditionally adds up the scores and counts elements that strictly exceed the `threshold` variable. - 2.33 marks: Computes division correctly, explicitly preventing division-by-zero errors when no records meet the criteria by returning `0.0`.
題目 4 · Practical Coding & Algorithmic Design
13.33 分
Consider the following run-length encoding (RLE) pseudocode algorithm:
``` SET inputStr TO "AABBBCCCC" SET compressed TO "" SET count TO 1 FOR i FROM 0 TO LENGTH(inputStr) - 2 IF inputStr[i] == inputStr[i+1] THEN count = count + 1 ELSE compressed = compressed + inputStr[i] + STRING(count) count = 1 ENDIF ENDFOR compressed = compressed + inputStr[LENGTH(inputStr)-1] + STRING(count) SEND compressed TO DISPLAY ```
Complete a trace table for this algorithm. Track the value of the loop control variable `i`, `count`, and the variable `compressed` inside the loop for each change in state.
查看答案詳解收起答案詳解
解題
Let's trace step-by-step: - Initialization: `inputStr` = "AABBBCCCC", `compressed` = "", `count` = 1. Length of `inputStr` is 9. The loop variable `i` runs from 0 to 7 (LENGTH - 2). - **i = 0**: `inputStr[0]` is 'A', `inputStr[1]` is 'A'. Match! `count` becomes 2. - **i = 1**: `inputStr[1]` is 'A', `inputStr[2]` is 'B'. No match! `compressed` becomes "" + 'A' + "2" = "A2". `count` reset to 1. - **i = 2**: `inputStr[2]` is 'B', `inputStr[3]` is 'B'. Match! `count` becomes 2. - **i = 3**: `inputStr[3]` is 'B', `inputStr[4]` is 'B'. Match! `count` becomes 3. - **i = 4**: `inputStr[4]` is 'B', `inputStr[5]` is 'C'. No match! `compressed` becomes "A2" + 'B' + "3" = "A2B3". `count` reset to 1. - **i = 5**: `inputStr[5]` is 'C', `inputStr[6]` is 'C'. Match! `count` becomes 2. - **i = 6**: `inputStr[6]` is 'C', `inputStr[7]` is 'C'. Match! `count` becomes 3. - **i = 7**: `inputStr[7]` is 'C', `inputStr[8]` is 'C'. Match! `count` becomes 4. - Loop ends. - After the loop: `compressed` = "A2B3" + `inputStr[8]` ('C') + "4" = "A2B3C4".
評分準則
- 3 marks: Tracking state transitions of `count` correctly at matching indices (increases on consecutive characters). - 4 marks: Correctly tracking changes to `compressed` inside the `ELSE` branch at boundary transitions (when `i = 1` and `i = 4`). - 3 marks: Running the loop correctly up to `i = 7` (preventing off-by-one errors). - 3.33 marks: Correct final post-loop output generation of `"A2B3C4"`.
題目 5 · Practical Coding & Algorithmic Design
13.33 分
The standard bubble sort algorithm has a time complexity of \( O(n^2) \) in the worst and average cases.
1. Modify the bubble sort algorithm in Python below to include an early-stop optimization utilizing a boolean flag `swapped` so that it can terminate early if the array becomes fully sorted prior to completing all passes. 2. State the best-case time complexity of this optimized version, and explain when it occurs.
```python def bubbleSort(arr): n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] ```
查看答案詳解收起答案詳解
解題
```python def bubbleSort(arr): n = len(arr) for i in range(n): # Initialize swapped flag for each outer pass swapped = False for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] swapped = True # If no elements were swapped, array is sorted if not swapped: break ```
**Complexity Explanation:** - Best-case time complexity: \( O(n) \). - This occurs when the list is already sorted. The algorithm makes one complete pass of \( n-1 \) comparisons, finds no elements to swap, and breaks out of the loop.
評分準則
- 3 marks: Declares a boolean variable `swapped` and initializes it to `False` inside the outer loop, before the start of the inner loop. - 3 marks: Sets the `swapped` variable to `True` whenever a physical swap of elements occurs inside the conditional block. - 3 marks: Places a conditional break statement checking if `swapped` is still `False` immediately after the inner loop finishes to terminate the outer loop. - 4.33 marks: Correctly specifies the best-case complexity of \( O(n) \) and explains that it is achieved when the input array is already in sorted order.
題目 6 · Practical Coding & Algorithmic Design
13.33 分
Write a Python subprogram `sumOfPrimes(N)` that calculates and returns the sum of all prime numbers less than or equal to a given integer `N` (where \( N \ge 2 \)).
You must design the algorithm using nested iteration structures: - An outer loop to iterate through numbers from 2 up to `N`. - An inner loop to check if the current number has any factors other than 1 and itself. - A tracker/accumulator to compile the sum of identified prime numbers.
查看答案詳解收起答案詳解
解題
```python def sumOfPrimes(N): total_sum = 0 # Outer loop going up to and including N for num in range(2, N + 1): is_prime = True # Inner loop to check potential factors for factor in range(2, int(num**0.5) + 1): if num % factor == 0: is_prime = False break # Break inner loop if a divisor is found # If is_prime is still True, add to accumulator if is_prime: total_sum += num return total_sum ```
評分準則
- 2 marks: Correctly sets up a function and initializes a summation accumulator to `0`. - 3 marks: Implements an outer loop starting at 2 and correctly terminating at \( N \) (inclusive). - 3 marks: Implements an inner loop checking potential factors from 2 up to \( \sqrt{\text{num}} \) or \( \text{num}-1 \). - 3 marks: Employs standard modulo checking (`%`) and a flag mechanism (boolean variable) to accurately identify non-primes. - 2.33 marks: Correctly accumulates prime values and returns the expected numerical sum at the end.
想知道自己有幾分把握?
Thinka 是 DSE 學生用的 AI 練習應用程式,有無限量練習題、即時自動批改和詳細解題步驟。逾 100,000 名學生用它確認自己真的識,而不只是「以為識」。