0% found this document useful (0 votes)
84 views28 pages

2.1.1 and 2.1.3 - Algorithms + Answers

The document is an exam paper for a Computer Science course, focusing on algorithms, data structures, and programming concepts. It includes various questions related to searching algorithms, sorting techniques, and program design, along with instructions for candidates on how to answer. The paper consists of multiple sections, each assessing different aspects of computer science knowledge and skills.

Uploaded by

xagipo2218
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)
84 views28 pages

2.1.1 and 2.1.3 - Algorithms + Answers

The document is an exam paper for a Computer Science course, focusing on algorithms, data structures, and programming concepts. It includes various questions related to searching algorithms, sorting techniques, and program design, along with instructions for candidates on how to answer. The paper consists of multiple sections, each assessing different aspects of computer science knowledge and skills.

Uploaded by

xagipo2218
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/ 28

Computer Science (9-1)

2.1.1 & 2.1.3 Algorithms


Salman Uddin
Please note that you may see slight differences between
this paper and the original.
Duration: Not set
Candidates answer on the Question paper.

OCR supplied materials:


Additional resources may be supplied with this paper.

Other materials required:


• Pencil
• Ruler (cm/mm)

Candidate Candidate

forename surname

Centre number Candidate number

INSTRUCTIONS TO CANDIDATES
• Write your name, centre number and candidate number in the boxes above. Please write clearly and in capital letters.
• Use black ink. HB pencil may be used for graphs and diagrams only.
• Answer all the questions, unless your teacher tells you otherwise.
• Read each question carefully. Make sure you know what you have to do before starting your answer.
• Where space is provided below the question, please write your answer there.
• You may use additional paper, or a specific Answer sheet if one is provided, but you must clearly show your candidate
number, centre number and question number(s).

INFORMATION FOR CANDIDATES


• The quality of written communication is assessed in questions marked with either a pencil or an asterisk. In History and
Geography a Quality of extended response question is marked with an asterisk, while a pencil is used for questions in
which Spelling, punctuation and grammar and the use of specialist terminology is assessed.
• The number of marks is given in brackets [ ] at the end of each question or part question.
• The total number of marks for this paper is 64.
• The total number of marks may take into account some 'either/or' question choices.

© OCR 2022. You may photocopy this page. 1 of 28 Created in ExamBuilder


1(a) The following names of students are stored in an array with the identifier studentnames.

studentnames = ["Rob", "Anna", "Huw", "Emma", "Patrice", "Iqbal"]

Describe the steps that a linear search would take to find Anna in studentnames

"Rob", "Anna", "Huw", "Emma", "Patrice", "Iqbal"


"Rob", "Anna", "Huw", "Emma", "Patrice", "Iqbal"

Start at Rob
is Rob equal to anna
No so move to the next item anna
is Anna equal to Anna
yes so stop program
[4]

© OCR 2022. You may photocopy this page. 2 of 28 Created in ExamBuilder


(b) The names of students are sorted into ascending alphabetical order using an insertion sort.

Complete the following diagram to show the stages an insertion sort would take to complete this task.

Each row represents one pass of the insertion sort algorithm. You may not need to use all empty rows.

Rob Anna Huw Emma Patrice Iqbal

[5]

© OCR 2022. You may photocopy this page. 3 of 28 Created in ExamBuilder


2 The following table contains several definitions of terms that are used in Computer Science.

Letter Definition
A Cleaning up data entered by removing non-standard characters
B Hiding or removing irrelevant details from a problem to reduce complexity
C Checking that the user is allowed to access the program
D Breaking a complex problem down into smaller problems
E Repeating elements of a program
F Converting one data type to another, for example converting an integer to a real number

Write the letter of the definition that matches each keyword in each space.

Decomposition ..................

Abstraction ..................

Input sanitisation ..................

Casting ..................

[4]

3(a) A computer game is written in a high-level programming language.

State why the computer needs to translate the code before it is executed.

[1]

© OCR 2022. You may photocopy this page. 4 of 28 Created in ExamBuilder


(b) Either a compiler or an interpreter can translate the code.

Describe two differences between how a compiler and an interpreter would translate the code.

[4]

4(a) A program creates usernames for a school. The first design of the program is shown in the flowchart in Fig. 2.

© OCR 2022. You may photocopy this page. 5 of 28 Created in ExamBuilder


Fig. 2

For example, using the process in Fig. 2, Tom Ward’s username would be TomWa.

State, using the process in Fig. 2, the username for Rebecca Ellis.

[1]

(b) The program design is updated to create usernames as follows:

• If the person is a teacher, their username is the last 3 letters of their surname and then the first 2 letters of
their first name.
• If the person is a student, their username is the first 3 letters of their first name and then the first 2 letters of
their surname.

© OCR 2022. You may photocopy this page. 6 of 28 Created in ExamBuilder


(i) What would be the username for a teacher called Fred Biscuit using the updated process?

[1]

(ii) Write an algorithm for the updated program design shown in (i).

[6]

© OCR 2022. You may photocopy this page. 7 of 28 Created in ExamBuilder


5 A school uses a mobile phone app to allow parents to book appointments for parents’ evenings.

Parents must log in before they can use the system. They then choose to book a new appointment, view all
appointments already made or update their personal details. If parents choose to view their appointments, they
can either view them on-screen or print them off.

Each teacher has the assessment grades for each student. These grades are stored in numerical order.

(i) The grades for one student are shown:

2 3 4 5 6 7 8

Show the steps that a binary search would take to check whether the student has achieved a grade 7 in any
assessment.

Your answer must refer to the grades provided.

2345678
2345678
678
7

[4]

(ii) Explain how a binary search would determine that a value does not appear in a given array.

When the there is only one item


left after the binary search and it
is not equal to the wanted value
© OCR 2022. You may photocopy this page. 8 of 28 Created in ExamBuilder
[2]

(iii) Give one advantage of a binary search over a linear search.

faster / more efficient


[1]

© OCR 2022. You may photocopy this page. 9 of 28 Created in ExamBuilder


6 A car dealership uses a computer system to record details of the cars that it has for sale. Each car has a make,
model, age and number of miles driven.

Each car is given a star rating of 1 to 5, based on the age of the car and the number of miles it has been driven.
This rating is recorded in the computer system.

(i) Define the term abstraction.

Removing detail to
understand a question better [1]

(ii) Give one example of how abstraction has been used in the design of this star rating system.

focus on age
[1]

(iii) Explain how authentication could be used as part of the defensive design considerations for this computer
system.

[2]

© OCR 2022. You may photocopy this page. 10 of 28 Created in ExamBuilder


7(a) A program uses a file to store a list of words that can be used in a game.

A sample of this data is shown in Fig. 3.

crime bait fright victory nibble loose


Fig. 3

Show the stages of a bubble sort when applied to data shown in Fig. 3.

[4]

© OCR 2022. You may photocopy this page. 11 of 28 Created in ExamBuilder


(b) A second sample of data is shown in Fig. 4.

amber house kick moose orange range tent wind zebra


Fig. 4

Show the stages of a binary search to find the word zebra using the data shown in Fig. 4.

AHKMORTWZ
AHKMORTWZ
RTWZ
RTWZ
Z
[4]

© OCR 2022. You may photocopy this page. 12 of 28 Created in ExamBuilder


8 Elliott plays football for OCR FC. He wants to create a program to store the results of each football match they
play and the names of the goal scorers. Elliott wants individual players from the team to be able to submit this
information.

(i) Define what is meant by abstraction.

removing details to make a


problem easier to solve [2]

(ii) Give one example of how abstraction could be used when developing this program.

focus on the names of the [1]

goal scores

© OCR 2022. You may photocopy this page. 13 of 28 Created in ExamBuilder


9 OCR Land is a theme park aimed at children and adults. Entrance tickets are sold online. An adult ticket to OCR
Land costs £19.99, with a child ticket costing £8.99. A booking fee of £2.50 is added to all orders.

OCR Land regularly emails discount codes to customers. Each discount code includes a check digit as the last
character.

A list of valid discount codes is shown below.

[NIC12B, LOR11S, STU12M, VIC08E, KEI99M, WES56O, DAN34S]

(i) State one reason why a binary search would not be able to be used with this data.

not in order

[1]

(ii) Give the name of one searching algorithm that would be able to be used with this data.

binary search [1]

© OCR 2022. You may photocopy this page. 14 of 28 Created in ExamBuilder


10 A library gives each book a code made from the first three letters of the book title in upper case, followed by the
last two digits of the year the book was published.

For example, “Poetry from the War”, published in 2012 would be given the code POE12.

The library sorts their books based on the book code.

(i) Show the steps that a merge sort would take to put the following list of book codes into ascending
alphabetical order (from A to Z).

POE12 , BAC97 , FLY77 , JAV16 , TAL86 , AND18 , ZAR09 , HOP86

PBFJTAZH
PBFJ TAZH
PB FJ TA ZH
PBFJTASH
BP FJ AT HS
BFJP AHST
ABFHJPST

© OCR 2022. You may photocopy this page. 15 of 28 Created in ExamBuilder


[4]

(ii) Explain one advantage of a merge sort compared to a bubble sort.

Faster
Better for larger lists

[2]

© OCR 2022. You may photocopy this page. 16 of 28 Created in ExamBuilder


11(a) Willow has created a hangman program that uses a file to store the words the program can select from. A
sample of this data is shown in Fig. 3.

Show the stages of a bubble sort when applied to data shown in Fig. 3.

cbfvni
bcfvni
bcfnvi
bcfniv
bcfinv [4]
(b)
A second sample of data is shown in Fig. 4.

Show the stages of a binary search to find the word ‘zebra’ when applied to the data shown in Fig. 4.

[4]

© OCR 2022. You may photocopy this page. 17 of 28 Created in ExamBuilder


END OF QUESTION PAPER

© OCR 2022. You may photocopy this page. 18 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

1 a 1 mark per bullet to max 6 4 Answer must refer to this array, not a
generic description of linear search.
Access “Rob” / studentnames[0]… AO2 “Access first item” is NE for BP1 or BP3.
…does not equal “Anna” // not desired 1b(4) Must refer to this scenario.
item // move on
Access “Anna” / studentnames[1] Max 1 for “Compare ‘Anna’ to each item in
…does equal “Anna” // stop // item list” if nothing else credited.
found

b Anna inserted before Rob as first two 5 Rob Anna Huw Emma Patrice Iqbal
elements…
Anna Rob Huw Emma Patrice Iqbal
…Huw correctly inserted into sorted AO2
list… 1b(5) Anna Huw Rob Emma Patrice Iqbal
…Emma correctly inserted into sorted Anna Emma Huw Rob Patrice Iqbal
list …
Anna Emma Huw Patrice Rob Iqbal
…Patrice correctly inserted into sorted
list … Anna Emma Huw Iqbal Patrice Rob
…Iqbal correctly inserted into sorted
list and no further changes made. Sorted list highlighted

Total 9

2 1 mark for each letter 4 Accept answers that write the definition
instead of the letter.
AO1
Decomposition D 1a(4)
Abstraction B
Input Sanitisation A
Casting F

Total 4

3 a To convert it to binary/machine code 1 Maximum 1 mark


The processor can only understand (AO1 1a)
machine code

b Compiler translates all the code in one 4 1 mark to be awarded for the correct
go… (AO1 1b) identification and one for a valid description
…whereas an interpreter translates up to a maximum of 4 marks.
one line at a time No more than 2 marks for answers relating
Compiler creates an executable… only to interpreters and no more than 2
…whereas an interpreter does marks for answers only relating to
not/executes one line at a time compilers.
Compiler reports errors at the end…
…whereas an interpreter stops when it
finds an error

Total 5

© OCR 2022. You may photocopy this page. 19 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

4 a RebEl 1 Correct Answer Only (allow any case)


(AO2 1b)

b i uitFr 1 Correct Answer Only (allow any case)


(AO2 1b)

ii Taking firstname, surname and teacher 6 1 mark for each correct bullet to a
or student as input (AO3 2b) maximum of 6.
Checking IF role is teacher/student
(using appropriate selection) If used, a flowchart should represent the
For teacher ...Generating last 3 letters bulleted steps in the answer column.
of surname using appropriate string
manipulation
...Generating first 2 of letters of
firstname and adding to previous
For student.... correctly calculating as
before
Correct concatenation and output

e.g.
Ask the user to input the data, store in
variables firstname, surname and role.
Check whether the role entered is teacher.
If it is, join the right 3 most letters in
surname with the left 2 letters in firstname.
Store this in username.
If it is not teacher, join the left 3 letters from
firstname with the left 2 letters from
surname. Store this in username. Output
the value in username.

Total 8

© OCR 2022. You may photocopy this page. 20 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

5 i 1 mark per bullet, max 4 4 Do not accept generic answers that do not
refer to the data given.
Compare 5 (middle value) to 7
5 is smaller than 7 / 7 is larger than 7
so…
discard lower part of list / repeat with
upper part of list
…compare 7 to 7 (item found)

ii 1 mark per bullet, max 2 2 Do not accept answers relating to "end of


list" – this is linear search.
List of size 1 to compare
…and item not matched to search term

iii More efficient // Less time taken (to find 1 Accept reference to big O notation as
item) // fewer comparisons to make equivalent to more efficient.
(with large lists)

Total 7

6 i Hiding / ignoring / removing detail // 1


focussing on certain parts of a problem

ii Focus on age / number of miles 1 Allow other examples of factors to ignore /


Ignore other factors (such as make, remove for BP2
model, etc)

iii Ensures only certain users can access 2 Allow other examples of authentication for
the system BP2
Using password / other example of
authentication technique

Total 4

© OCR 2022. You may photocopy this page. 21 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

7 a 4 1 mark for each row from rows 2–5. Allow


(AO2 1b) multiple swaps in one stage, where it is
clear that a bubble sort has been applied.

b Comparing zebra to orange 4 1 mark per bullet (multiple ways through,


Greater, so split and take right side (AO2 1b) marks awarded for appropriate comparison
Further comparison (1 or 2 depending and creation of sub groups).
on choices made)
Correct identification of zebra using
methodology above

e.g.

compare zebra to orange

greater, split right

compare to wind

greater, split right

compare to zebra

Total 8

© OCR 2022. You may photocopy this page. 22 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

8 i 1 mark per bullet to max 2 2 Accept answers relating to using fewer


AO1 1a computational resources
Removing / hiding / obscuring (1)
unnecessary detail AO1 1b Must be the programmer making the
Focusing on the important detail (1) decision.
Simplifies the problem // reduces
complexity // Easy to solve /
understand

ii 1 mark per bullet to max 1 1 Mark first answer only


AO2 1a
Suitable example of what can be (1) Allow any suitable example of abstraction
focused on (e.g. player name, match as long it is relevant to the system.
results, goals scored)
Suitable example of what to Allow either first name or surname to be
remove/hide (anything relevant that is removed as an example, but do not allow
not results/goals scored) both to be removed.
Suitable example of a simplification
made Examiner’s Comments

As a topic new to the J276 specification,


abstraction as a concept is obviously well
understood by candidates who were
generally able to give a definition for (i)
around removing unnecessary detail and
focussing on the important details in a
problem.

A small number then went on to state that


this is done to simplify a problem or reduce
complexity which shows a perhaps deeper
understanding.

Answers for (ii) were slightly less well


completed as answers had to be linked to
the scenario given; examiners were
generous in their interpretation and
accepted a wide range of answers that
could potentially be removed or focused
on.

Total 3

© OCR 2022. You may photocopy this page. 23 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

9 i Not in order / sorted 1 Mark first answer only


AO2 1b
(1) Examiner’s Comments

This question required candidates to


understand that one of the pre-requisites of
a binary search is that the data must be in
some form of order. Where this was
understood, candidates were able to
identify that the data presented was not in
order and so could be searched using this
algorithm.

Extremely common wrong answers


included that only numeric data could be
used or that data had to be in binary.

Misconception

A binary search can be carried out on non-


numeric data.

If the data is ordered in some way (e.g.


alphabetically) then this algorithm will be
able to efficiently find data.

ii Linear (search) 1 Mark first answer only


AO1 1b Allow other valid searching algorithms as
(1) long as they work on an unsorted list (e.g
front and back search)

Total 2

© OCR 2022. You may photocopy this page. 24 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

10 i 1 mark per bullet, max 4. 4 Candidates can describe how the merge
sort would work rather than showing output
values at each stage.
List split into individual elements (may
be done over several steps or just as a Ignore intermediate steps.
starting point)
Merge individual elements into sorted Do not give final mark for simply showing
lists of size 2 the list sorted. Must have the (correct) idea
Merge lists of size 2 into sorted lists of of where it being merged from previous
size 4 lists.
Merge lists of size 4 into final sorted
list. Candidates’ answers describing / showing
other sorting algorithms (e.g. bubble sort,
insertion sort) are worth 0 marks.

© OCR 2022. You may photocopy this page. 25 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

ii 1 mark per bullet, max 2. 2 Accept (correct) reference to big O notation


for 2nd mark on either mark point although
this is beyond scope of GCSE
Faster/quicker (to sort)… specification.
…for large lists // for lists that are more
unordered Allow “more efficient” for BOD on first bullet
point.
Has a consistent running time (for a
lists of same length)…
…doesn’t depend on how ordered
original list is
Examiner’s Comments

Large numbers of candidates understood


the divide and conquer strategy applied by
the merge sort algorithm; the list is
continually divided in half until lists of size
1 are achieved before the lists are then
merged together to achieve the sort, with
the size of lists doubling with every
iteration (i.e. when two lists of size 2 are
merged, the result is a list of size 4). Many
candidates achieved good marks on this
question.

Where mistakes were made, they generally


fell into one of three categories. One was
applying a different algorithm than had
been asked (e.g. showing a bubble sort).
Another was misunderstanding where the
sorting takes place; some candidates
showed the lists being split up correctly,
but then these being merged and the list
sorted in place afterwards – this is
incorrect, it is the act of merging that sorts
the values. A third and more common
issue was that examiners found it
extremely tough to decide where lists were
split up or merged from candidate
responses that seemed to list all values in
one row with no seeming differentiation
between one list of eight values and eight
lists of one value. Where examiners were
not able to see this, marks could not be
given.

© OCR 2022. You may photocopy this page. 26 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

Misconception

When using merge sort to merge together


[1, 3] and [2, 4] into ascending order, the
algorithm will take the lowest value from
the front of either list (in this case 1) and
place it into the new, merged list. This will
then repeat meaning that the new list will
be [1, 2, 3, 4]. It does not merge the lists to
be [1, 3, 2, 4] and then sort this list.

Exemplar 5

The exemplar above shows an ideal way to


respond to this question. The list is
obviously and clearly split up in successive
passes into lists of a single value. Each
pair of lists is then merged, with the
process of merging resulting in sorted lists.
Each time the lists are merged, the result is
a larger list in ascending order. The
candidate response shown here not only
shows this process but makes it very clear
that the values are held in separate lists
and even includes arrows to illustrate the
process of merging. This achieved full
marks [4 out of 4].

Total 6

© OCR 2022. You may photocopy this page. 27 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

11 a crim bait fright victor nym loose 4 1 mark for each row from row 2-5. Allow
e y ph multiple swaps in one stage, where it is
clear that a bubble sort has been applied.
bait crim fright victor nym loose
e y ph
bait crim fright nym victor loose
e ph y
bait crim fright nym loose victor
e ph y
bait crim fright loose nym victor
e ph y

b Comparing zebra to orange 4 1 mark per bullet (multiple ways through,


Greater, so split and take right side marks awarded for appropriate comparison
Further comparison (1 or 2 depending and creation of sub groups).
on choices made)
Correct identification of zebra using
methodology above

e.g.
compare zebra to orange

greater, split right

compare to wind

greater, split right

compare to zebra

Total 8

© OCR 2022. You may photocopy this page. 28 of 28 Created in ExamBuilder

Powered by TCPDF (www.tcpdf.org)

You might also like