GCSE Computer Science J277/02: Computational thinking, algorithms and programming Notes
Section A
Question 1
- (a) Identifying programming language types:
- The table requires ticking one box per row to indicate whether a statement describes a low-level or high-level programming language.
- Statement 1: "The same language can be used on computers that use different hardware" describes a high-level language.
- Statement 2: "It allows the user to directly manipulate memory" describes a low-level language.
- Statement 3: "It allows the user to write English-like words" describes a high-level language.
- Statement 4: "It always needs to be translated into object code or machine code" is true for both low-level and high-level languages, but more commonly associated with high-level languages in this context.
- (b) Pseudocode for adding two integers:
- The task is to write pseudocode to add integers stored in
num1 and num2, storing the result in total.
total = num1 + num2
- (c) Arithmetic operators in pseudocode:
- (i) Outputting 12 to the power of 2:
- The missing operator is the exponentiation operator.
print(12 ^ 2)
- (ii) Checking for odd or even numbers:
- The missing operator is the modulo operator to check the remainder after division by 2.
if number % 2 == 0 then
print("Even number")
else
print("Odd number")
endif
- (iii) Finding the difference between two measurements:
- The missing operator is the subtraction operator.
difference = measurement1 - measurement2
- (d) Trace table for a pseudocode algorithm:
- The algorithm prints the value of
start and decrements it until it reaches -1, then prints "Finished". - Trace Table:
| Line number | start | Output |
| :---------- | :---- | :---------- |
| 01 | 3 | |
| 03 | 3 | 3 |
| 04 | 2 | |
| 02 | 2 | |
| 03 | 2 | 2 |
| 04 | 1 | |
| 02 | 1 | |
| 03 | 1 | 1 |
| 04 | 0 | |
| 02 | 0 | |
| 03 | 0 | 0 |
| 04 | -1 | |
| 02 | -1 | |
| 06 | -1 | "Finished" |
Question 2
- (a) Syntax and Logic Errors:
- Syntax Error: An error in the structure or grammar of the code that prevents it from being compiled or executed. For example, misspelling a keyword or missing a required punctuation mark.
- Logic Error: An error in the algorithm’s design that causes the program to produce incorrect results, even though the code runs without crashing. For example, using the wrong formula or an incorrect conditional statement.
- (b) Logic Errors in Pseudocode:
- Error 1:
- Line number: 02
- Corrected line:
for scoreCount = 0 to scores.length - 1 (The loop should start from 0 as the array is 0-indexed.)
- Error 2:
- Line number: 03
- Corrected line:
total = total + scores[scoreCount] (The code should add the current score to the total, not the total to itself.)
Question 3
- (a) Purpose of the
temp variable in Insertion Sort:- The
temp variable is used to temporarily store the value of names[pos] during the swapping process. This allows the value to be moved to its correct position without overwriting data.
- (b) Reason for Condition-Controlled Inner Loop:
- The inner loop needs to be condition-controlled because the number of shifts required to insert an element into its sorted position is not fixed. The loop continues as long as
pos > 0 (to avoid going out of bounds) and names[pos] < names[pos – 1] (meaning the element is smaller than the one before it and needs to be moved further left).
- (c) Insertion Sort vs. Bubble Sort:
- (i) Difference:
- Insertion sort works by iteratively inserting elements into a sorted sub-array, while bubble sort repeatedly compares adjacent elements and swaps them if they are in the wrong order, causing larger elements to