BREAKING
Student's code works, nobody knows why, including student★Local teen writes pseudocode, accidentally invents a language★Binary joke told in class, exactly 10 students laugh★
  1. Home
  2. A Level
  3. Computer Science
  4. OCR
  5. Algorithm efficiency and Big O notation

OCR A Level Computer Science

Topic questions Algorithms Algorithm efficiency and Big O notation

Algorithm efficiency and Big O notation

10 questions · 198 marks · about 3.5 hours

Algorithm efficiency and Big O notation questions

OCR H446 Algorithm efficiency and Big O notation 10 questions

Algorithms and programming June 2025, Question 2 14 marks

2* A shopping website requires customers to create a username and password.

(a)

The usernames and passwords are stored securely in a file. The file contains the username and passwords for 50 million users which are sorted in alphabetical order by username.

The file can be searched using a linear search or a binary search.

The big-O complexities for a linear search and a binary search are given in the table:

Search algorithmWorst-case timeAverage-case timeWorst-case space
LinearO(n)O(n)O(1)
BinaryO(log n)O(log n)O(1)

Compare the use of a linear search and a binary search in this scenario.

You should include the following in your answer:

• the features and preconditions of a linear and binary search

• the benefits and drawbacks of each search in this scenario

• a conclusion justifying which search algorithm should be used in this scenario.

You should make reference to the big-O complexities in your answer.

[9]
Reveal mark scheme Mark scheme for question 2(a)
(b)

The website collects data from customers’ activities once they log on. For example, the items they view and purchase. The company that owns the website would like to use data mining to improve their website and customer experience.

(b)(i)

Describe what data mining means.

[3]
Reveal mark scheme Mark scheme for question 2(b)(i)
(b)(ii)

Explain how the company can make use of data mining to improve their website and customer experience.

[2]
Reveal mark scheme Mark scheme for question 2(b)(ii)

Algorithms and programming June 2024, Question 6 15 marks

The following strings are stored in an array.

Figure for question 6
(a)

Explain how a linear search would search the array for the index that stores "clouds".

[3]
Reveal mark scheme Mark scheme for question 6(a)
(b)

State why a binary search cannot be used in this example.

[1]
Reveal mark scheme Mark scheme for question 6(b)
(c)

Show how an insertion sort will sort the given data into ascending alphabetical order.

Figure for question 6
[5]
Reveal mark scheme Mark scheme for question 6(c)
(d)
(d)(i)

A sorting algorithm has a best time complexity of O(n).

Describe what is meant by the best time complexity O(n) for a sorting algorithm.

[2]
Reveal mark scheme Mark scheme for question 6(d)(i)
(d)(ii)

Another sorting algorithm has a worst space complexity of O(log(n)).

Describe what is meant by the worst space complexity O(log(n)) for a sorting algorithm.

[2]
Reveal mark scheme Mark scheme for question 6(d)(ii)
(d)(iii)

Identify the time complexity that means the time will not change even when the number of items increases.

[1]
Reveal mark scheme Mark scheme for question 6(d)(iii)
(d)(iv)

Identify the space complexity that means the amount of memory (space) used will double each time a new item is included.

[1]
Reveal mark scheme Mark scheme for question 6(d)(iv)

Algorithms and programming June 2023, Question 7 26 marks

(a)

7* (a) A program designer needs to decide on an algorithm to use from a choice of three. The table shows the worst-case Big O complexities for each algorithm.

AlgorithmTime ComplexitySpace Complexity
1LinearExponential
2ExponentialConstant
3LogarithmicLogarithmic

The program will be used to analyse data that can range from 2 items to 2 billion items.

Compare the use of all three algorithms and suggest which the programmer should use.

You should include the following in your answer:

• the meaning of constant, logarithmic, linear and exponential complexity

• how well each algorithm scales as the amount of data increases

• which algorithm is the most suitable for the given task.

[9]
Reveal mark scheme Mark scheme for question 7(a)
(b)

The program designer is investigating the use of concurrent processing.

(b)(i)

Describe what is meant by the term ‘concurrent processing’.

[2]
Reveal mark scheme Mark scheme for question 7(b)(i)
(b)(ii)

Give two benefits of using concurrent processing.

[2]
Reveal mark scheme Mark scheme for question 7(b)(ii)
(c)

The programmer needs to use a merge sort in one part of the problem to sort items in ascending order.

(c)(i)

Describe how a merge sort works.

[5]
Reveal mark scheme Mark scheme for question 7(c)(i)
(c)(ii)

Give one benefit and one drawback of the programmer using a merge sort instead of a bubble sort.

[2]
Reveal mark scheme Mark scheme for question 7(c)(ii)
(d)

The programmer uses an Integrated Development Environment (IDE).

Complete the table by identifying and describing three IDE features that can help the programmer to develop, or debug a program.

Figure for question 7
[6]
Reveal mark scheme Mark scheme for question 7(d)

Algorithms and programming June 2022, Question 3 22 marks

Also involves Arrays

A bubble sort will sort an array of 50 integer values called numberArray.

(a)

State why the integer values are stored in an array instead of separate variables.

[1]
Reveal mark scheme Mark scheme for question 3(a)
(b)

This bubble sort algorithm is written to sort numberArray into ascending numerical order.

Complete this bubble sort algorithm.

Figure for question 3
[5]
Reveal mark scheme Mark scheme for question 3(b)
(c)

One section of numberArray is shown here.

Figure for question 3

A second sorting algorithm that could be used to sort this data is a merge sort.

Show how a merge sort will sort this section of the array numberArray into ascending numerical order.

[4]
Reveal mark scheme Mark scheme for question 3(c)
(d)

* Another sorting algorithm is insertion sort.

The number of values stored in the array numberArray has been reduced to 10.

Compare the use of bubble, merge and insertion sorts on the array numberArray.

You should include the following in your answer:

• how each algorithm works

• the Big O complexities for each algorithm

• the suitability of each algorithm for sorting the 10 values.

[12]
Reveal mark scheme Mark scheme for question 3(d)

Algorithms and programming November 2021, Question 2 14 marks

The pseudocode function binarySearch() performs a binary search on the array dataArray that is passed as a parameter. The function returns the array index of searchValue within the array, and-1 if it is not in the array.

(a)

The pseudocode binary search algorithm is incomplete.

(a)(i)

Complete the algorithm by filling in the missing statements.

Figure for question 2
[6]
Reveal mark scheme Mark scheme for question 2(a)(i)
(a)(ii)

The algorithm uses a while loop.

State a different type of loop that could be used instead of the while loop in the given algorithm.

[1]
Reveal mark scheme Mark scheme for question 2(a)(ii)
(b)

The tables below show possible Big O complexities for the worst-case space, best-case space and average time for search algorithms.

Tick the worst-case space complexity for a binary and linear search.

Figure for question 2

Tick the best-case space complexity for a binary and linear search.

Figure for question 2

Tick the average time complexity for a binary and linear search.

Figure for question 2
[6]
Reveal mark scheme Mark scheme for question 2(b)
(c)

Identify one situation where a linear search is more appropriate than a binary search.

[1]
Reveal mark scheme Mark scheme for question 2(c)

Algorithms and programming November 2020, Question 4 20 marks

The following pseudocode procedure performs an insertion sort on the array parameter.

Figure for question 4
(a)

Explain why dataArray is passed by reference and not by value.

[2]
Reveal mark scheme Mark scheme for question 4(a)
(b)

State whether the procedure insertionSort sorts the data into ascending or descending order and explain your choice.

[3]
Reveal mark scheme Mark scheme for question 4(b)
(c)

* Two other sorting algorithms are merge sort and quick sort.

Compare the use of merge sort, quick sort and insertion sort on an array with a small number of elements, and on an array with a very large number of elements.

You should make reference to the time complexities of each algorithm using the Big O notation in your answer.

[9]
Reveal mark scheme Mark scheme for question 4(c)
(d)

A fourth sorting algorithm is a bubble sort.

Describe how a bubble sort will sort an array of 10 elements.

[6]
Reveal mark scheme Mark scheme for question 4(d)

Algorithms and programming June 2019, Question 1 17 marks

Also involves Stacks and queues

The temperatures of an ocean are input into a computer system. They are recorded, and will be accessed, in the order in which they arrive. The data for one week is shown:

5, 5.5, 5, 6, 7, 6.5, 6

(a)

The data is to be stored in a data structure. The programmer stores the data in a queue.

Explain why a queue is used instead of a stack.

[2]
Reveal mark scheme Mark scheme for question 1(a)
(b)

The data is processed. After processing, the value for the first day is stored as 0. The value for each following day is stored as an increase, or decrease, from the first day.

For example: if the first day was 7, the second was 6 and the third was 9, after processing it would be stored as 0, –1, 2.

(b)(i)

The queue uses dequeue() to return the first element of the queue.

dequeue() is a function.

Explain why dequeue() is a function, not a procedure.

[1]
Reveal mark scheme Mark scheme for question 1(b)(i)
(b)(ii)
Figure for question 1
[3]
Reveal mark scheme Mark scheme for question 1(b)(ii)
(b)(iii)

The contents of processedData are shown.

Figure for question 1

The data needs to be sorted into ascending order.

Explain how a bubble sort algorithm sorts data. Use the current contents of processedData in your explanation.

[5]
Reveal mark scheme Mark scheme for question 1(b)(iii)
(b)(iv)
Figure for question 1 Figure for question 1 Figure for question 1
[6]
Reveal mark scheme Mark scheme for question 1(b)(iv)

Algorithms and programming June 2019, Question 5 8 marks

A 1-dimensional array stores the following data:

Index012345
Data21864123
(a)

The array needs sorting into descending order.

Describe how a merge sort would sort the given array into descending order.

[6]
Reveal mark scheme Mark scheme for question 5(a)
(b)

An insertion sort can be used to sort the array instead of a merge sort.

Explain why an insertion sort might use less memory than a merge sort.

[2]
Reveal mark scheme Mark scheme for question 5(b)

Algorithms and programming June 2017, Question 1 22 marks

A programmer needs to sort an array of numeric data using an insertion sort.

(a)(i)

The following, incomplete, algorithm performs an insertion sort.

Complete the algorithm.

Figure for question 1
[3]
Reveal mark scheme Mark scheme for question 1(a)(i)
(a)(ii)

Show how an insertion sort would sort the following data:

Figure for question 1
[6]
Reveal mark scheme Mark scheme for question 1(a)(ii)
(b)(i)

Using Big-O notation state the best case complexity of insertion sort.

[1]
Reveal mark scheme Mark scheme for question 1(b)(i)
(b)(ii)

Explain what your answer to part (b)(i) means.

[3]
Reveal mark scheme Mark scheme for question 1(b)(ii)
(c)

(c*) The number of data items in the array is continually increasing.

Insertion sort has a worst case time complexity of O(n2) and space complexity of O(1).

An alternative sorting algorithm that could be used is bubble sort which also has a worst case time complexity of O(n2) and space complexity of O(1).

Briefly outline how the bubble sort algorithm works. Discuss the relationship between the complexities and the two sorting algorithms and justify which of the two algorithms is best

suited to sorting the array.

[9]
Reveal mark scheme Mark scheme for question 1(c)

Algorithms and programming June 2017, Question 6 40 marks

A software developer is creating a Virtual Pet game.

The user can choose the type of animal they would like as their pet, give it a name and then they are responsible for caring for that animal. The user will need to feed, play with, and educate their pet.

The aim is to keep the animal alive and happy, for example if the animal is not fed over a set period of time then the pet will die.

• The game tells the user how hungry or bored the animal is as a percentage (%) and the animal’s intelligence is ranked as a number between 0 and 150 (inclusive).

• Hunger and boredom increase by 1% with every tick of a timer.

• When the feed option is selected, hunger is reduced to 0.

• When the play option is selected, bored is reduced to 0.

• When the read option is selected, the intelligence is increased by 0.6% of its current value.

An example of the game is shown:

Figure for question 6

Fig. 1.1

(a)

Identify three inputs that the user will have to enter to start, and/or play the game.

[3]
Reveal mark scheme Mark scheme for question 6(a)
(b)

The developer is using decomposition to design the game.

(b)(i)

Describe the process of decomposition.

[2]
Reveal mark scheme Mark scheme for question 6(b)(i)
(b)(ii)
Figure for question 6
[6]
Reveal mark scheme Mark scheme for question 6(b)(ii)
(c)

The developer needs to write procedures for the options play and read. Each of the options changes its corresponding value, and outputs the results to the screen.

(c)(i)

Write a procedure, using pseudocode, to reset bored and output the new value in an appropriate message.

[3]
Reveal mark scheme Mark scheme for question 6(c)(i)
(c)(ii)

Write a procedure, using pseudocode, to increase intelligence by 0.6% and output the new intelligence in an appropriate message.

[3]
Reveal mark scheme Mark scheme for question 6(c)(ii)
(d)

The developer is extending the game to allow users to have multiple pets of different types. The developer has written a class, Pet.

The attributes and methods in the class are described in the table:

Figure for question 6

Part of the class declaration is given:

Figure for question 6
(d)(i)
Figure for question 6
[4]
Reveal mark scheme Mark scheme for question 6(d)(i)
(d)(ii)

Write a line of code that creates a new instance of Pet for a Tiger called “Springy”.

[2]
Reveal mark scheme Mark scheme for question 6(d)(ii)
(d)(iii)

The method outputGreeting for the superclass is written as follows:

Figure for question 6

A class is needed for Tiger. The class needs to:

• inherit the methods and attributes from pet

• in the constructor, set type to Tiger, intelligence to 10, hunger to 50 and bored to 10

• extend the method outputGreeting, by outputting an additional line that says “I like to eat meat and roar”

Write, using pseudocode, the class Tiger.

[5]
Reveal mark scheme Mark scheme for question 6(d)(iii)
(e)

(e*) The developer made use of abstraction when creating the Virtual Pet game.

Discuss the need for and purpose of abstraction and how abstraction will be used in the

development of the game.

[9]
Reveal mark scheme Mark scheme for question 6(e)
(f)

The developer is storing the user’s pets in a 1-dimensional array. At each timer interval, the array is searched, using a linear search, to check if any pets’ hunger or bored values are greater than 90%. If they are, an alert is displayed to the user.

(f)(i)

State the complexity of searching the pets in Big-O notation.

[1]
Reveal mark scheme Mark scheme for question 6(f)(i)
(f)(ii)

A given computer takes 4 milliseconds (ms) to search an array of 20 pets. Calculate an estimate of how long the computer will take to search an array of 100 pets.

Show your working.

[2]
Reveal mark scheme Mark scheme for question 6(f)(ii)

Report a problem with a question on this page
What is wrong?

Goes to whoever maintains the question split. No account needed and nothing is published on this page.

Memes

Certified Computer Science memes. Peer-reviewed by nobody.

Laugh now. Cry in the exam hall later. Then come back and do a past paper.

Write a proper algorithm
Write ‘sort it’ and leave
Me on the 6-mark pseudocode question
Debugging with print statements
Using a trace table
Knowing the difference between = and ==
Explaining recursion by explaining recursion
Code enlightenment, ranked

Mum 💖

can you fix the wifi since you do computers 🥰

that's not what computer science is

so that's a no then

📱 Screen time this week · Discord8h 2m

Turned it off and on again

Computer Science starter pack

Laptop with 47 tabs openPython error on line 1Counting binary on fingersThis website
Compiled with zero errors