704148-question-paper-algorithms-and-problem-solving
704148-question-paper-algorithms-and-problem-solving
Do not use:
* 8 9 3 9 5 0 2 7 6 4 *
• a calculator
* H 0 4 6 0 2 *
First name(s)
Last name
INSTRUCTIONS
• Use black ink.
• Write your answer to each question in the space provided. If you need extra space use
the lined pages at the end of this booklet. The question numbers must be clearly shown.
• Answer all the questions.
INFORMATION
• The total mark for this paper is 70.
• The marks for each question are shown in brackets [ ].
• Quality of extended response will be assessed in questions marked with an asterisk (*).
• This document has 16 pages.
ADVICE
• Read each question carefully before you start your answer.
© OCR 2023
3
1 A program uses a bubble sort to sort data into ascending numerical order.
(a) Show each stage of a bubble sort to sort this data into ascending numerical order:
1 5 3 9 2 7
You should clearly show and label each pass in your answer.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [4]
This will partially sort an array of numbers called numbers that is passed as a parameter.
02 flag = true
03 for x = 0 to numbers.length – 1
05 holdValue = numbers[x]
06 numbers[x] = numbers[x + 1]
07 numbers[x + 1] = holdValue
08 flag = false
09 endif
10 next x
11 endprocedure
(i) Explain why the procedure bubbleSort accepts the array numbers by reference and
not by value.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [3]
(ii) The programmer has used a for loop on line 3 in the procedure bubbleSort. A for
loop is a count controlled loop.
...........................................................................................................................................
...................................................................................................................................... [1]
© OCR 2023
5
(iii) State the purpose of the variable holdValue in the procedure bubbleSort.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [3]
(iv) The procedure bubbleSort will only partially sort the array numbers into order.
Describe what the programmer would need to add to the algorithm to enable it to fully
sort the numbers into order.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
(c) (i) The array numbers contains 356 numbers to be sorted by the bubble sort algorithm.
State the maximum number of passes a bubble sort would need to complete to sort 356
numbers into order.
...........................................................................................................................................
...................................................................................................................................... [1]
...........................................................................................................................................
...................................................................................................................................... [1]
(a) Give three examples of where abstraction can be used in the design of this program.
1 ................................................................................................................................................
...................................................................................................................................................
2 ................................................................................................................................................
...................................................................................................................................................
3 ................................................................................................................................................
...................................................................................................................................................
[3]
(b) The program will need to accept inputs from the user before playing the simulation.
1 ........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
...........................................................................................................................................
[2]
(ii) One decision point in the program will be to decide if the user inputs are suitable or not.
1 ........................................................................................................................................
...........................................................................................................................................
2 ........................................................................................................................................
...........................................................................................................................................
[2]
© OCR 2023
7
(c) Taylor is deciding which software development methodology to use to write the program.
The client has stated that they would like the program as soon as possible and want to be
heavily involved during the program creation.
(i) Describe the difference between the spiral model and the waterfall model.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [4]
(ii) Give two reasons why the waterfall model is not suitable for Taylor.
1 .........................................................................................................................................
...........................................................................................................................................
2 .........................................................................................................................................
...........................................................................................................................................
[2]
Name .................................................................................................................................
Description ........................................................................................................................
...........................................................................................................................................
[2]
Discuss the differences between writing and debugging a program using an IDE and a text-editor.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
© OCR 2023
9
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..................................................................................................................................................... [9]
25 / 2 = 12 remainder 1
12 / 2 = 6 remainder 0
6/2=3 remainder 0
3/2=1 remainder 1
1/2=0 remainder 1
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [6]
© OCR 2023
11
(b) The main program:
• asks the user to enter a denary number between 1 and 255
• checks that the input is valid between 1 and 255
• If valid call the function toBinary() and pass the input as a parameter
• outputs the return value
• If not valid, repeatedly asks the user to input a number until the number is valid.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [4]
01 total = 1
02 smallest = 9999
03 largest = -1
04 for x = 0 to 21
08 largest = dataArray[x]
09 endif
11 smallest = dataArray[x]
12 endif
13 next x
...........................................................................................................................................
...................................................................................................................................... [1]
...........................................................................................................................................
...................................................................................................................................... [1]
© OCR 2023
13
(b) Identify two variables used in this algorithm.
1 ................................................................................................................................................
2 ................................................................................................................................................
[2]
(c) The algorithm that Layla has written has many errors.
Identify the line number of four different errors and write the corrected line of code.
...........................................................................................................................................
...................................................................................................................................... [1]
(ii) Give one benefit and one drawback of declaring dataArray as a local variable in the
main program.
Benefit ...............................................................................................................................
...........................................................................................................................................
Drawback ..........................................................................................................................
...........................................................................................................................................
[2]
(a) The program needs to search the array for a number that is input by the user.
(i) Describe how a linear search will search the data in the array for a number that has
been input.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [5]
(ii) State why you would use a linear search rather than a binary search.
...........................................................................................................................................
...................................................................................................................................... [1]
© OCR 2023
15
(b) Describe how an array can be used to store and access data in a stack data structure.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [4]
© OCR 2023
16
ADDITIONAL ANSWER SPACE
If additional space is required, you should use the following lined page(s). The question number(s)
must be clearly shown in the margin(s).
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
© OCR 2023