0% found this document useful (0 votes)
4 views16 pages

704148-question-paper-algorithms-and-problem-solving

This document is an AS Level Computer Science exam paper from OCR, dated May 22, 2023, focusing on algorithms and problem-solving. It includes various questions on topics such as bubble sort, program design, software development methodologies, and data structures. The total mark for the paper is 70, and it consists of multiple sections requiring written answers in specified formats.

Uploaded by

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

704148-question-paper-algorithms-and-problem-solving

This document is an AS Level Computer Science exam paper from OCR, dated May 22, 2023, focusing on algorithms and problem-solving. It includes various questions on topics such as bubble sort, program design, software development methodologies, and data structures. The total mark for the paper is 70, and it consists of multiple sections requiring written answers in specified formats.

Uploaded by

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

Oxford Cambridge and RSA

Monday 22 May 2023 – Afternoon


AS Level Computer Science
H046/02 Algorithms and problem solving
Time allowed: 1 hour 15 minutes

Do not use:
* 8 9 3 9 5 0 2 7 6 4 *

• a calculator

* H 0 4 6 0 2 *

Please write clearly in black ink. Do not write in the barcodes.

Centre number Candidate number

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 [601/5030/0] OCR is an exempt Charity


DC (ST) 300308/5 Turn over
2
BLANK PAGE

PLEASE DO NOT WRITE ON THIS PAGE

© OCR 2023
3
1 A program uses a bubble sort to sort data into ascending numerical order.

The data is stored in a 0-indexed 1-dimensional array.

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

© OCR 2023 Turn over


4
(b) A programmer has partially developed a bubble sort algorithm in pseudocode.

This will partially sort an array of numbers called numbers that is passed as a parameter.

01 procedure bubbleSort(numbers : byRef)

02 flag = true

03 for x = 0 to numbers.length – 1

04 if numbers[x] > numbers[x + 1] then

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.

State what is meant by the term ‘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]

(ii) State the name of one other sorting algorithm.

...........................................................................................................................................

...................................................................................................................................... [1]

© OCR 2023 Turn over


6
2 Taylor is designing a program for a client who would like to simulate earthquakes on major cities
around the world in 3D. The client would like to be able to view any stage of an earthquake such
as:
1. the build-up of the earthquake
2. the earthquake taking place
3. the aftershocks of the earthquake.
The client would also like to be able to play the simulation at different speeds. For example, a
slow, normal or fast speed.

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

(i) Identify two different inputs for this program.

1 ........................................................................................................................................

...........................................................................................................................................

2 ........................................................................................................................................

...........................................................................................................................................
[2]

(ii) One decision point in the program will be to decide if the user inputs are suitable or not.

Identify two other example decision points in this program.

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]

(iii) Name and describe one other model of software development.

Name .................................................................................................................................

Description ........................................................................................................................

...........................................................................................................................................
[2]

© OCR 2023 Turn over


8
3* Nina is writing a computer game using an Integrated Development Environment (IDE). Her friend,
James, is writing a computer game using a text-editor which will allow James to create and edit
text. James will use a separate compiler.

Discuss the differences between writing and debugging a program using an IDE and a text-editor.

You should include the following in your answer:

• features that are used when writing code


• features that are used when debugging code
• the benefits of using an IDE instead of a text-editor.

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................
© OCR 2023
9

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..........................................................................................................................................................

..................................................................................................................................................... [9]

© OCR 2023 Turn over


10
4 A function, toBinary(), is needed to calculate the binary value of a denary integer between 0
and 255.

toBinary() needs to:


• take an integer value as a parameter
• divide the number by 2 repeatedly, storing a 1 if it has a remainder and a 0 if it doesn’t
• combine the remainder values (first to last running right to left) to create the binary number
• return the binary number.

For example, to convert 25 to a binary number the steps are as follows:

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

return value = 11001

(a) Write the function toBinary().

You should write your function using pseudocode or program code.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

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

Write the algorithm for the main program.

You should write your algorithm using pseudocode or program code.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................. [4]

© OCR 2023 Turn over


12
5 Layla writes a pseudocode algorithm to:
• input 20 positive numbers into a 0-indexed 1-dimensional array
• output the average (mean) number as a decimal
• output the smallest number
• output the largest number.

The pseudocode algorithm is shown. It contains various errors.

01 total = 1

02 smallest = 9999

03 largest = -1

04 for x = 0 to 21

05 dataArray[x] = input("Enter a number")

06 total = total + dataArray[x]

07 if dataArray[x] < largest then

08 largest = dataArray[x]

09 endif

10 if dataArray[x] < smallest then

11 smallest = dataArray[x]

12 endif

13 next x

14 print("Average = " + total * 20)

15 print("Smallest = " + smallest)

16 print("Largest = " + largest)

(a) (i) Identify the construct used on lines 01 to 03 in the algorithm.

...........................................................................................................................................

...................................................................................................................................... [1]

(ii) Identify the construct used on lines 10 to 12 in the algorithm.

...........................................................................................................................................

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

Error 1 line number ......................

Error 1 correction ......................................................................................................................

Error 2 line number ......................

Error 2 correction ......................................................................................................................

Error 3 line number ......................

Error 3 correction ......................................................................................................................

Error 4 line number ......................

Error 4 correction ......................................................................................................................


[4]

(d) dataArray is defined as a local variable within the main program.

(i) State what is meant by a ‘local variable’.

...........................................................................................................................................

...................................................................................................................................... [1]

(ii) Give one benefit and one drawback of declaring dataArray as a local variable in the
main program.

Benefit ...............................................................................................................................

...........................................................................................................................................

Drawback ..........................................................................................................................

...........................................................................................................................................
[2]

© OCR 2023 Turn over


14
6 A program stores data in a 1-dimensional array.

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

END OF QUESTION PAPER

© 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).

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

..................................................................................................................................................................

Oxford Cambridge and RSA


Copyright Information
OCR is committed to seeking permission to reproduce all third-party content that it uses in its assessment materials. OCR has attempted to identify and contact all copyright holders
whose work is used in this paper. To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced in the OCR Copyright
Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download from our public website (www.ocr.org.uk) after the live examination series.
If OCR has unwittingly failed to correctly acknowledge or clear any third-party content in this assessment material, OCR will be happy to correct its mistake at the earliest possible
opportunity.
For queries or further information please contact The OCR Copyright Team, The Triangle Building, Shaftesbury Road, Cambridge CB2 8EA.
OCR is part of Cambridge University Press & Assessment, which is itself a department of the University of Cambridge.

© OCR 2023

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy