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. Standard searching algorithms

OCR A Level Computer Science

Topic questions Algorithms Standard searching algorithms

Standard searching algorithms

7 questions · 144 marks · about 2.5 hours

Standard searching algorithms questions

OCR H446 Standard searching algorithms 7 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 2022, Question 1 21 marks

Also involves Variables, constants, inputs, outputs and assignment

A computer program stores data in an array named words.

(a)

The data in the array needs to be searched for a value that the user inputs.

(a)(i)

One example of a searching algorithm is a binary search.

Identify the precondition for a binary search.

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

A second example of a searching algorithm is a linear search.

Describe how a linear search works.

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

The array words is defined as a global variable and contains these values:

Figure for question 1

The pseudocode function useWords() here uses the global array words.

The number of words in the array words is passed as a parameter.

Figure for question 1
(b)(i)

Identify two variables in the function useWords().

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

numberOfWords is a parameter passed by value.

Describe the difference between passing a parameter by value and by reference.

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

Rewrite the function useWords() to use a while loop instead of a for loop.

The function header and close have been written for you.

Write your answer using pseudocode or program code.

function useWords(numberOfWords: byVal)

endfunction

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

Give one benefit and one drawback of declaring the array as a global variable instead of a local variable.

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

Describe one feature of an Integrated Development Environment (IDE) that can be used to help write the program and one feature that can be used to help test the program.

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

Functions and procedures are reusable components.

Give two benefits of writing a program with reusable components.

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

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 3 16 marks

Also involves Trace tables

Hugh has written a recursive function called thisFunction() using pseudocode.

Figure for question 3

The function DIV calculates integer division, e.g. 5 DIV 3 = 1

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

State the name of the standard algorithm thisFunction() performs.

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

Hugh could have written thisFunction() using iteration instead of recursion.

Compare two differences between recursion and iteration.

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

The recursive function thisFunction() is printed again here for your reference.

Figure for question 3

Rewrite the function thisFunction() so that it uses iteration instead of recursion.

You should write your answer using pseudocode or program code.

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

Algorithms and programming June 2018, Question 5 29 marks

Also involves String manipulation

A computer program stores data input on a stack named dataItems. The stack has two sub-programs to add and remove data items from the stack. The stack is implemented as a 1D array, dataArray.

Figure for question 5

The current contents of dataItems are shown:

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

The main program asks a user to push or pop an item from the stack. If the user chooses β€˜push’, the data item is added to the stack. If the user chooses β€œpop”, the next item is removed from the stack, multiplied by 3 and output.

The main program is shown:

Figure for question 5
(b)(i)

Before the sub-programs, push() and pop(), can add or remove items from the stack, a selection statement is used to decide if each action is possible.

Describe the decision that needs to be made in each sub-program and how this impacts the next process.

Question 5, shown as an image
Question 5, shown as an image
[4]
Reveal mark scheme Mark scheme for question 5(b)(i)
(b)(ii)

The algorithm does not work when the user enters "PUSH" or "Push". The algorithm needs to be changed in order to accept these inputs.

Identify the line number to be changed and state the change that should be made.

Question 5, shown as an image
[2]
Reveal mark scheme Mark scheme for question 5(b)(ii)
(c)

The stack is implemented as a 1D array, dataArray.

Describe how a 1D array can be set up and used to push and pop items as a stack.

Figure for question 5

maths symbol

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

As an array, the data in dataArray is sorted and then searched for a specific value.

(d)(i)

The data in dataArray is sorted into ascending order using an insertion sort.

The current contents of dataArray are shown:

Figure for question 5

Show the steps of an insertion sort on the current contents of the array dataArray.

Figure for question 5

maths symbol

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

The array dataArray can now be searched using a binary search.

Describe the stages of a binary search on an array of size n.

Figure for question 5

maths symbol

[7]
Reveal mark scheme Mark scheme for question 5(d)(ii)
(d)(iii)

The array has 50 items.

The function, searchItem(), performs a linear search for a data item.

Figure for question 5

Rewrite the function using a while loop.

Figure for question 5

maths symbol

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

Algorithms and programming June 2017, Question 2 35 marks

Also involves Trace tables Β· Arrays Β· Linked lists

A programmer is developing an ordering system for a fast food restaurant. When a member of staff inputs an order, it is added to a linked list for completion by the chefs.

(a)

Explain why a linked list is being used for the ordering system.

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

Order 158 has been made, and needs adding to the end of the linked list.

Add the order, 158, to the linked list as shown in Fig. 2.1. Show the contents of the linked list in the following table.

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

Order 159 has been made. This order has a high priority and needs to be the second order in the linked list. Add the order, 159, to the original linked list as shown in Fig. 2.1. Show the contents of the linked list in the following table.

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

The linked list is implemented using a 2D array, theOrders:

β€’ Row 0 stores orderNo

β€’ Row 1 stores next

The data now stored in theOrders is shown in Fig. 2.2.

Figure for question 2

The following algorithm is written:

Figure for question 2
(c)(i)

Outline why nodeNo does not need to be stored in the array.

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

Complete the trace table for procedure x, for the data shown in Fig. 2.2.

Figure for question 2
[3]
Reveal mark scheme Mark scheme for question 2(c)(ii)
(c)(iii)

Describe the purpose of procedure x.

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

A new order, 190, is to be added to theOrders. It needs to be the third element in the list. The current contents of the array are repeated here for reference:

Figure for question 2

Describe how the new order, 190, can be added to the array, so the linked list is read in the correct order, without rearranging the array elements.

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

The user needs to be able to search for, and find, a specific order number.

State an appropriate search algorithm that could be used, and justify your choice against an alternative Search algorithm.

Appropriate Search Algorithm........

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

The programmer is writing the program using an IDE.

Identify three features of an IDE that the programmer would use when writing the code and describe how the features benefit the programmer.

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

(f*) The programmer is considering using concurrent programming.

Discuss how concurrent programming can be applied to the food ordering system and the

benefits and limitations of doing so.

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

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