0% found this document useful (0 votes)
43 views46 pages

Chapter 1&2 (With Answer) p2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views46 pages

Chapter 1&2 (With Answer) p2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 46

Chapter 1: Problem Solving

Chapter 2: Programming
Chapter 3: Data (3.4 Encryption)
2019

Ans:

The only correct answer is C

A is not correct because Boolean only has values True and False

B is not correct because it only allows for one character

D is not correct because it is used for mixed text and numeric data

(b) Give a definition of a logic error.

(d) Give one reason why computer programmers should use comments in their programs.

Ans: Any one from:

1. explain how the program works (1)

2. improve readability of the program (1)

3. make code more understandable (1)

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)

2. Local variables are declared/created inside a function/blocked code (indented, brackets)


and are only accessible there / are only in scope within the function in which they’re declared
(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.

Be careful about this question

Page 2 of 46
Ans:

(b) Explain one drawback of using the merge sort algorithm to sort large data sets.
(2)

Ans:

More memory/storage required (1)

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)

(b) State the values used by the Boolean data type.

Ans: Award one mark for any of:

• TRUE and FALSE (1)

• Yes and No (1)

• T and F (1)

• 0 and 1 (1)

(d) State what is meant by the term ‘variable’.

Ans: Award one mark for any of:

• (Symbolic name associated with) a value that may be

changed (1)

• A container used to store data (1)

• A data store whose contentscan change whilst a program is executing (1)

Page 4 of 46
3. Several encryption algorithms have been developed.

(a) State what is meant by the term ‘encryption’.

Ans: Award one mark for any of:

• Conversion of plain text into cipher (1)

• Converting information/data into a code (1)

• Converting information/data into an unreadable format (1)

(b) Give one reason why data may need to be encrypted.

Ans: Award one mark for any of:

• 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)

Ans: Limited number of usable keys(1) to allow for sufficient

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:

Award 1 mark each for any of:

• Simple implementation (1)

• Can be used for sorted or unsorted lists (1)

• 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:

Award 1 mark each for any of:

• May need to compare with all items in list before search complete (1)

• May need longer time for searching a large list (1)

(c) Cerys will use functions and procedures in her program.

(i) One similarity between a function and a procedure is that they are both subprograms.
State two other similarities.

Ans:

• Both can use arguments /parameter passing (1)

• Both can use local variables (1)

• Both can be called from anywhere within the program(1)

• Code can be reused without being rewritten (1)

• Both can be library files (1)

• The code can be independently tested for both (1)

(ii) Explain one difference between a function and a procedure.


Page 7 of 46
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)

• A function produces information (1) whereas a procedure performs a task (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

C is not correct because as it is a relational operator

D is not correct because as it is a relational operator

(b) Describe one difference between a one-dimensional array and a two-dimensional array.(2)
Ans:

Award up to 2 marks for a linked description such as:

• 1D represents items as a list (1), 2D as a table / 2D as rows and columns (1)

• 1D is a row/column (1), 2D is a table / 2D has rows and columns (1)

• Each element in 1D is a single value (1), each element in 2D is a 1D array (1)

• 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

Award up to 2 marks for a linked explanation such as:

• 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:

Award 1 mark for any of:

• subprogram that is already defined

• subprogram that is already written

• subprogram that is already compiled

• subprogram that can be called without having to write code for it

(b) Zak plans to implement a binary search algorithm to search a table of products.

(i) Explain one advantage of a binary search compared to a linear search.(2)

Ans:

Award up to 2 marks for a linked explanation:

• 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)

Ans: Award 1 mark for any of:

• 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)

• Meaningful variable/constant/subprogram names (1)

• White space (1)

Page 12 of 46
Ans:

The only correct answer is D

A is not correct because as it is a data structure

B is not correct because as there is no arrow looping back to the condition

C is not correct because as the flowchart does not include an operator

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

comparison of search item with middle item (1)

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:

The only correct answer is D

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

Ans: The only correct answer is B

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]

(e) A program should output the value 2


However, there is an error in the code and the actual output is 4 Name this type of
error.(1)

Ans: Logic/logical

Ans: The only correct answer is B

A is not correct because this is decryption

C is not correct because this is not an encryption

D is not correct because this is not an encryption

Page 17 of 46
Ans:

(i) Give the key used in the first stage of the encryption process.(1)

Ans: 5

(ii) Give the ciphertext that is produced by the encryption algorithm.(1)

Ans: TIHYSEMNEEERNA

Page 18 of 46
(iii) Give the name of the encryption algorithm that has been used to produce the ciphertext.

Ans: Rail (Fence cipher)

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:

Step1: Start at the beginning of the list (1)

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

2 Solutions to problems are made up of many different components.

(a) Programmers use subprograms when developing code.

(i) Give two reasons to use subprogram libraries when developing code.

Ans:

• The code in the library has already been

debugged/tested/optimised / library code less likely to have errors (1)

• May include specialised/proprietary functions (1)

• 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)

Ans: The only correct answer is A

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:

3 Algorithms can be represented in flowcharts, pseudocode or program code.

(a) Trace tables can be used with flowcharts or pseudocode.

Give two characteristics of a trace table.1

Ans:

• Each column represents a variable/output (1)

• Rows shows how the values of variables change (as the code is executed) (1)

• Values are filled in manually/by hand (1)

Page 21 of 46
Ans:

(ii) Plaintext is encrypted using a Caesar cipher.

Compare the ciphertexts produced for the plaintext GOLD by:

• a shift of –6 followed by a shift of +8

• a single shift of +2. (2)

Ans:

Award two marks for a comparison such as:

• 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:

GOLD (-6) = AIFX (+8) = IQNF (1)

GOLD (+2) = IQNF (1)

can have 1 mark from MP and 1 mark from Practical

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.

Explain the error. (2)

Ans:

Ans:

Page 23 of 46
Ans:

Page 24 of 46
1) Ships carry cargo around the world in containers.

(a) Containers come in two sizes.

Figure 2 shows an algorithm written using flowchart symbols.

(i) Complete the table to


show the output for
each cargo item. (3)

(ii) State the purpose of the algorithm in Figure 2. (1)

Page 25 of 46
Ans: Determining which size shipping container is needed for the indicated cargo.

(b) Each ship is registered to a state.

Figure 3 shows a partially completed algorithm written in pseudocode.

The completed algorithm must:


• print each state to the display on a new line
• count the number of states
• create a message as a single string (e.g. there are number states)
• print the message to the display.
Complete the algorithm in the space provided in Figure 3. (4)

Page 26 of 46
Page 27 of 46
Cargo ships have maximum weight loads.

Figure 4 shows an algorithm written using pseudocode.

The algorithm should identify the size of cargo ship required for any load. There is an error
on line 9

Ans:

Showing that index goes up to 4 and does not exceed 4 (1)

Showing correspondence between values of index and loadWeight[index] (1)

(i) Trace tables are used to identify errors in algorithms.

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:

WHILE ((NOT found) AND (index < LENGTH (loadWeight))) DO

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.

Figure 4 shows this algorithm written in pseudocode.

(i) Give the output produced by the algorithm.

The algorithm works with a fixed number of flavours.


(iii) Give the number of the line in the algorithm that would need to be amended to
allow for any number of flavours.

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)

(iii) Explain why the variable Temp is needed(2)


Ans:
• You need to swap the contents of array values (1) and without Temp one of the
values would be lost (1)

(b) Figure 4 shows an algorithm Isaac has written using pseudocode.

The algorithm should display the average of the numbers that have been input.

Isaac uses the input 2, 3, 5, 2, −1 to test the algorithm. He discovers an error.

(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)

(b) Figure 3 shows an algorithm.

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)

• helps visualise how the algorithm works (1)

• helps detect (logic) errors (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.

Use each component once.

Do not add any additional components.

Use as many arrows and yes/no labels as you need. (5)

Page 39 of 46
(ii) Identify an alternative method for writing the algorithm.

The only correct answer is C

(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.

(i) Give the letter of the step that initialises a variable.(1)

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.

Reba inputs: red, orange, red, red, orange, –1

The outputs are not as she expects.

(i) Complete the trace table to show the outputs.(4)

Page 41 of 46
(ii) Give the line number of the pseudocode that contains the error.(1)
 23

(iii) Write a replacement line of pseudocode to correct the error.(1)


• Pseudodode that replaces OrangePoints with NumOranges on line 23 (1)
SEND ("Number of oranges: "& NumOranges) TO DISPLAY

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:

(ii) Draw a flowchart showing the logic described in part 5(b).(5)

Page 43 of 46
The form validates telephone numbers to make sure they are fit for processing. An

example of correctly entered data is 01745920043.

All telephone numbers begin with a 0.

(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:

Be careful about type of check and validation test

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

You might also like