Chapter 1&2 (With Answer) p2
Chapter 1&2 (With Answer) p2
Chapter 2: Programming
Chapter 3: Data (3.4 Encryption)
2019
Ans:
A is not correct because Boolean only has values True and False
D is not correct because it is used for mixed text and numeric data
(d) Give one reason why computer programmers should use comments in their programs.
Page 1 of 46
(e) Describe the difference between a local variable and a global variable in a computer
program.(2)
Ans:
1. Global variables created in the main program / can be accessed from any part of the
program / are in scope throughout the program (1)
Examiner Feedback:
1(g) was probably the least well answered written question on the paper.
Whilst candidates showed some understanding of the need for validation tests, responses
were often too vague to gain credit. What was expected is that candidates would apply
computational thinking to the question and identify tests that could be coded. The examples
of erroneous data often failed more than one criterion given in the question.
Page 2 of 46
Ans:
(b) Explain one drawback of using the merge sort algorithm to sort large data sets.
(2)
Ans:
Because not sorted in place / not efficient / many steps /division of data set / is recursive (1)
Page 3 of 46
2020
Ans:
C (equals) (1)
• T and F (1)
• 0 and 1 (1)
changed (1)
Page 4 of 46
3. Several encryption algorithms have been developed.
• To ensure that the data can only be read by an authorized person / can't be read by an
unauthorised person. (1)
(c)
(ii) Explain one reason why the Rail Fence cipher is a weak encryption algorithm.(2)
movement of characters / so can easily be decoded by trial and error / easy to use brute force
to crack (1)
Page 5 of 46
Ans:
Page 6 of 46
(b) Cerys will need an algorithm to search the table of stock data.
(i) State two advantages of using a linear search algorithm rather than a binary search
algorithm.(2)
Ans:
• If the target is at the beginning of the data structure the search will be faster than a binary
search
(ii) State two disadvantages of using a linear search algorithm rather than a binary search
algorithm.
Ans:
• May need to compare with all items in list before search complete (1)
(i) One similarity between a function and a procedure is that they are both subprograms.
State two other similarities.
Ans:
• A function must always return a result (1) whereas a procedure does not (1)
• A function interface must have a data type (1) to signify the type of data that will be
returned / a procedure does not need this (1)
• The result of a function must always be used (either assigned to a variable or as part of a
condition) (1) whereas a procedure does not explicitly return a result to be used (1)
Page 8 of 46
2021
June
Ans:
1. The only correct answer is B
A is not correct because as it is an arithmetic operator
(b) Describe one difference between a one-dimensional array and a two-dimensional array.(2)
Ans:
• 1D array can only store one type of element (1). 2D array can store multiple elements in it
(1)
Page 9 of 46
Ans:
(b) Explain one reason why the Caesar cipher is a weak encryption algorithm.
Ans:
Answer
• The number of keys are limited/only one shift used (1) making it easy to use brute force to
decrypt (1)
• It can be easy to find commonly used letters (e.g. E) (1) and guess the key (1)
Page 10 of 46
(iii) State what is meant by a built-in subprogram.
Ans:
(b) Zak plans to implement a binary search algorithm to search a table of products.
Ans:
• binary search can be quicker / is more effective than a linear search / is more effective with
larger lists (1) as it does not have to examine each item in the list (1)
• binary search halves the list each time (1) so it can be faster to find an item (1)
• binary search requires fewer comparisons than a linear search to establish an item is not in
the list (1) because the linear list would need to compare each item before establishing this
(1)
(iii) Zak has another list containing the names of five students who attend the after-school
club.
Give the maximum number of names that would need to be examined by the binary search
algorithm to determine whether a name appears in the list.(1)
Ans:
(iv) Give the name of an algorithm that could be used to sort a list.(1)
• bubble sort
• merge sort
Page 11 of 46
1 Programmers write code to solve problems.
(a) Give one technique that programmers use to make their code easy to read and
understand.(1)
Ans: Award 1 mark for any of:
• Comments (1)
• Indentation (1)
Page 12 of 46
Ans:
Ans:
• The list is not sorted (1) Juan should come after Elija if the list was sorted / Elija is
compared with Juan (1), so the bottom half of the list would be discarded (1) after the first
pass through the loop (1)
Page 13 of 46
• Binary search works on a sorted list (1) because it uses divide and
conquer (1) half the list discarded each pass through (1) based on
Ans:
Page 14 of 46
Ans:
(b) Explain one reason why parameters are used to pass data into subprograms.(2)
Ans:
• A library program would not know the names of the calling program’s variables in advance
(1) meaning it would not be a reusable solution (1)
• (Using parameters) enables reusable solutions (1) using different data values/arguments (1)
• Using parameters uses less memory / uses memory more efficiently (1) because it avoids
the use of global variables / because the memory is freed after the subprogram is finished (1)
Page 15 of 46
2022
Ans:
A is not correct because the value can be used more than once
B is not correct because the value does not always have to be input
C is not correct because the value does not always have to be used in a calculation
Page 16 of 46
Ans:
(d) Describe one difference between the data used in boundary testing and the data
used in erroneous testing.(2)
Ans:
• Boundary testing uses the most extreme valid data / minimum and maximum
valid values (1) whereas erroneous testing uses invalid data (1)[Give an example]
Ans: Logic/logical
Page 17 of 46
Ans:
(i) Give the key used in the first stage of the encryption process.(1)
Ans: 5
Ans: TIHYSEMNEEERNA
Page 18 of 46
(iii) Give the name of the encryption algorithm that has been used to produce the ciphertext.
Ans:
(ii) Explain one reason why a bubble sort is very efficient in terms of memory usage.
Ans: • The sorting is done in the same place as the original data (1), which means only
one additional variable is needed to store the value being swapped (when the values are out of
order (1)
• All sort and swapping operations are done on the original data (1) which means the amount
of memory needed is constant (1)
• The list does not need to be split (1), which would use more memory (1)
Page 19 of 46
(c) Describe the steps a linear search algorithm takes to find a search item.
Ans:
Step2: Compare each value in the list with the search item (1)
Stpe3: Repeat until a match is found / the end of the list is reached (1)
2023
(i) Give two reasons to use subprogram libraries when developing code.
Ans:
• Library subprograms can be imported into code when needed / don’t need to write code
themselves (to save a programmer time/work) (1)
• making it more readable / makes code easier to understand (Code files become shorter)
Page 20 of 46
(iii) State what is meant by the term local variable.
Ans: A variable that exists/is accessible only in the subprogram/scope in which it is created
(1)
Ans:
Ans:
• Rows shows how the values of variables change (as the code is executed) (1)
Page 21 of 46
Ans:
Ans:
• Both produce same result (IQNF)(1) because the shift of -6 followed by +8 is the same as
the shift of +2 (1)
• The result is the same (IQNF) (1), but the single shift is more efficient than a double shift
(1)
Practical explanation:
e.g. GOLD (+2) = IQNF (1) which would be same result (1)
Page 22 of 46
(iii) Ann has written a Caesar cipher algorithm.
When the algorithm encrypts the plaintext BYTE with a shift of +5 the result
is GVYJ.
This is incorrect.
Ans:
Ans:
Page 23 of 46
Ans:
Page 24 of 46
1) Ships carry cargo around the world in containers.
Page 25 of 46
Ans: Determining which size shipping container is needed for the indicated cargo.
Page 26 of 46
Page 27 of 46
Cargo ships have maximum weight loads.
The algorithm should identify the size of cargo ship required for any load. There is an error
on line 9
Ans:
Complete the trace table for an input of 50500 to show what happens due to the error on line
9 in the pseudocode in Figure 4.
You may not need to fill in all the rows in the table.(2)
Page 28 of 46
(ii) Construct a single line of pseudocode to correct line 9.(2)
1. Use of AND operator (in the test of relevant conditions) (1)
Use of suitable function to find the length of the array using a correct comparison
to index(1)
Example:
Page 29 of 46
2) A software engineer is working with some algorithms.
(a) An algorithm needs to be developed.
The algorithm must:
• check for a change of hour every minute
• use the library subprogram getHour() to get the hour part of the current time
in the 24-hour clock (0 to 23)
• output “Good morning” when the hour is between 3 and 12, inclusive
• output “Good afternoon” when the hour is between 13 and 19, inclusive
• output “Good night” at all other times.
Complete the flowchart to represent this algorithm, in the space provided on the
next page.
The call to the library subprogram getHour() has already been included.
Use this subprogram symbol to show waiting for 1 minute.
Page 30 of 46
Page 31 of 46
(b) Another algorithm determines when to change the flavoured syrups for a drinks
dispensing machine.
Page 32 of 46
1) Isaac is a program developer.
(i) (a) Figure 3 shows an algorithm Isaac has written.
(i) Complete the trace table. You may not need to use all of the rows.(5)
Page 33 of 46
Page 34 of 46
(ii) Give the purpose of the algorithm.
Ans:
• To reverse the contents of the array (1)
• To reverse the order of the numbers (1)
The algorithm should display the average of the numbers that have been input.
(i) Explain why the Actual result is not the same as the Expected result.(2)
Award two marks for a linked explanation such as:
• Isaac has included the -1 as a number in the addition (1) but the number has not
been added to the count (1)
• Isaac has misunderstood the WHILE loop (1) as it should not execute after the -1
has been input (1)
• Isaac is expecting the wrong result (1) it should be 3 (1)
• The count is 1 too many as the -1 is counted as a number (1) and the total is
incorrect as 1 is subtracted from the total (1)
(ii) Give the number of the line that contains the error.
Line 3 (1)
Line 10 (1)
(iii) Amend a single line of pseudocode to correct the error.(1)
SET count TO -1 (1)
SET average TO (total + 1) / (count – 1)
Page 35 of 46
2) Algorithms can be used to perform calculations and to process data.
(a) State what is meant by the term algorithm.
• a step-by-step description of a process that completes a task (1)
• a set of instructions that describes how to get something done (1)
1) Complete this trace table for the algorithm. You may not need to use all the rows.
(5)
Page 36 of 46
(ii) The benefits of using a trace table include that they allow variable states,
outputs and decisions to be recorded.
Give one other benefit of using a trace table to test an algorithm. (1)
(c) An algorithm is needed to count and display the number of vowels in a word.
The vowels are a, e, i, o, and u.
The completed algorithm must:
• count the number of vowels
• create a message as a single string (e.g. there are number vowels)
• print the message to the display.
Here is a partially completed algorithm written in pseudocode.
Complete the algorithm in the spaces provided. (5)
Page 37 of 46
Page 38 of 46
2) Reba likes writing programs.
(a) She is writing a guessing game.
She needs a flowchart to show the logic of the game.
(i) These are the components needed to draw the flowchart.
Draw the flowchart for the algorithm in the box on the next page.
Page 39 of 46
(ii) Identify an alternative method for writing the algorithm.
(b) Reba wants to develop a program that will convert a temperature in Fahrenheit
to Celsius. Here are four steps in the algorithm. The steps are not in the correct order.
Page 40 of 46
Award one mark for:
•D
(ii) Give the letter of the step that inputs a value.(1)
•B
c) Figure 2 shows the pseudocode for an early version of an algorithm that Reba has written
for another game.
The algorithm:
• asks the user to input a colour or input –1 to end the game
• awards 1 point for red
• awards 8 points for orange
• generates the score for the game
• displays the results of the game.
Page 41 of 46
(ii) Give the line number of the pseudocode that contains the error.(1)
23
Page 42 of 46
5. Kitty Kamp is an animal shelter for cats. It makes sure the cats are healthy before they are
adopted.
When a cat is brought into the shelter, the receptionist enters information into a computerised
form. This information is saved in a database and can be sorted.
(b) When the information is entered, the computer program shows the receptionist which
building the cat should be sent to for an initial assessment.
• If the receptionist enters an invalid gender, an error message is displayed and they must
enter the gender again.
• Female cats are sent to Building 32 and male cats are sent to Building 16.
(i) State one input and one output for this process. (2)
Input
Output
Ans:
Page 43 of 46
The form validates telephone numbers to make sure they are fit for processing. An
(c) State two different validation checks that could be used to validate the
telephone numbers. Provide one example of test data for each type of check to show the error
is caught. (4)
Ans:
Page 44 of 46
Cat health is checked during the assessment. Each individual aspect of health
is rated on a scale of 1 to 5, with 1 being the healthiest and 5 being the least healthy.
An algorithm calculates an overall health score for each cat. The score is between
1.0 and 5.0, inclusive.
Weight contributes 50% to the score and teeth contribute 30% to the score. Eyes and ears
contribute equally to the total score.
Here is a pseudocode version of the algorithm. Line numbers are not part of the pseudocode.
Page 45 of 46
Ans:
Page 46 of 46