Computational thinking: searching, sorting, ADTs and recursion – A Level Computer Science (9618)

15 questions · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
1
9618/31/M/J/26 · Question 10May/June 2026Paper 319 marks
Loading question…
Question text

10 (a) An insertion sort algorithm is used to sort the unique ID numbers of club members into
ascending order. These unique ID numbers are kept in a 1D array MemberID. The
corresponding names of the members are stored in a 1D array Names.
The arrays are declared as:
DECLARE MemberID : ARRAY[0:499] OF INTEGER
DECLARE Names : ARRAY[0:499] OF STRING
The following table defines the variables to be used in this algorithm.
identifier
data type
description
Count
integer
main loop counter to iterate through the whole array
Temp1
integer
temporary holding location for current member ID
Temp2
string
temporary holding location for current member name
Insert
integer
counter to show current insertion position
Write the pseudocode for an insertion sort to arrange the unique ID numbers into ascending
order. Make sure that the data in both arrays is swapped as required so that data with the
same index continues to apply to the same person.
Use the given identifiers. Assume all variables have been declared.
…
…
…
…
…
…
…
…
…
…
…
…
…
… [5]
© Cambridge University Press & Assessment 2026
,
,
(b) Describe the factors, other than changing the algorithm, that affect the time efficiency of the
insertion sort algorithm.
…
…
…
…
…

2
9618/32/M/J/26 · Question 10May/June 2026Paper 329 marks
Loading question…
Question text

10 (a) Two examples of searching algorithms are a linear search and a binary search.
Describe how increasing the number of data items in the file to be searched affects the time
efficiency of these search algorithms. Refer to Big O notation in your answer.
…
…
…
…
…
… [3]
© Cambridge University Press & Assessment 2026
,
,
(b) A temperature in degrees Celsius (°C) is recorded every minute for one day in a random
file, Temperatures.dat.
A function is required to find the temperature for a specific time in the day to check if it
was freezing. The position of each temperature in the file corresponds to the number
of minutes after midnight, for example, the temperature at 10:00 am would be stored at
position 600 (10 × 60).
Write the pseudocode to complete the algorithm to check a temperature stored in
Temperatures.dat, by passing its position in the file as a parameter and using file
handling commands to find the relevant data item. Once the temperature is found, it is
checked to see if it is above or below freezing, and an appropriate message is returned.
Some of the blank lines may not be used.
FUNCTION TempCheck( …
DECLARE Temperature : REAL
DECLARE Response : STRING
OPENFILE …
…
…
…
…
…
…
…
…
…
…
…
ENDFUNCTION
[6]
© Cambridge University Press & Assessment 2026

3
9618/33/M/J/26 · Question 10May/June 2026Paper 339 marks
Loading question…
Question text

10 (a) A program declares a 1D array globally as PartName[1:1000000] OF STRING, and sorts
its contents in ascending alphabetical order. The function PartSearch performs a binary
search on the array. The item to be found is passed as a parameter. If it is found, its location
in the array is returned, otherwise, –1 is returned.
(i)
Complete the following table to define the variables used in the function.
identifier
data type
description
Left
Right
Mid
Target
[2]
© Cambridge University Press & Assessment 2026
,
,
(ii)
Complete the pseudocode for the function to perform a binary search on PartName
using all the variables from the table in 10(a)(i).
Some lines may be left blank.
FUNCTION PartSearch( …
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
ENDFUNCTION
[5]
(b) Describe how the time efficiency of a binary search changes as the number of items in the
search list increases. Refer to Big O notation in your answer.
…
…
…
… [2]
© Cambridge Unive

Advertisement
4
9618/31/M/J/25 · Question 4May/June 2025Paper 317 marks
Loading question…
Question text

4
(a) A linked list of nodes is used to store an ordered list of integers. Each node consists of the
data, a left pointer and a right pointer, for example:
Left pointer Data
Right pointer
20
The linked list will be organised as a binary tree.
−1 is used to represent a null pointer.
Complete the binary tree, including null pointers, to show how the data will be organised after
the following integers have been added:
6, 15, 41, 66
Root pointer
36
12
40
– 1
3
[4]
(b) Describe what is meant by recursion.
…
…
…
… [2]
ĬÏĊ®Ġ´íÈõÏĪÅĊÞû·Ā×
,
,
(c) A binary tree is a suitable Abstract Data Type (ADT) that a designer can implement using
recursive algorithms.
Identify one other ADT that a designer can implement using recursive algorithms.
… [1]

5
9618/32/M/J/25 · Question 11May/June 2025Paper 326 marks
Loading question…
Question text

11
(a) A linked list of nodes is used to store an ordered list of strings. Each node consists of the
data, a left pointer and a right pointer.
Left pointer Data Right pointer
Pp
The linked list will be organised as a binary tree.
0 is used to represent a null pointer.
Complete the binary tree, including null pointers, to show how the data will be organised after
the following strings have been added:
Aa, Mm, Ss, Xx
Root pointer
Pp
Gg
Rr
0
Kk
[4]
ĬÑĊ®Ġ´íÈõÏĪÅĊÞù¸þ×
,
,
(b) A binary tree can be used to implement recursion.
Identify one feature of an algorithm that makes it beneficial to use recursion.
Give one example of an application that could use a recursive algorithm.
Feature …
…
Example …
[2]
ĬÓĊ®Ġ´íÈõÏĪÅĊÞû¸þ×

6
9618/33/M/J/25 · Question 12May/June 2025Paper 337 marks
Loading question…
Question text

12 (a) An array is an Abstract Data Type (ADT).
Identify two other ADTs.
1 …
2 …
[1]
(b) A 1D array DataArray holds up to 1000 elements of type integer and needs to be sorted in
ascending order.
Write the pseudocode for an insertion sort to sort the array into ascending order.
Use the identifiers from the table in your algorithm.
You do not need to declare any arrays or variables for this algorithm. You may assume this
has already been done.
Identifier
Data type
Description
Index
INTEGER
counter for outer loop
Position
INTEGER
counter for inner loop – insertion position
DataArray
INTEGER
1D array to store up to 1000 integers
Value
INTEGER
value to insert
The first line has been written for you.
← 2 to 1000
FOR Index
…
…
…
…
…
…
…
…
…
… [4]
ĬÍĊ®Ġ´íÈõÏĪÅĊàùµĂ×
,
,
(c) Describe two ways in which the performance of a sort routine is affected by the data to be
sorted.
1 …
…
2 …
…
[2]
ĬÏĊ®Ġ´íÈõÏĪÅĊàûµĂ×

7
9618/33/M/J/25 · Question 13May/June 2025Paper 33114 marks
Loading question…
Question text

13 The recursive procedure Delete() is defined as follows:
PROCEDURE Delete(Index, Target)
IF Numbers[Index] > 0 THEN
IF Numbers[Index] >= Target THEN
←
Numbers[Index + 1]
Numbers[Index]
ENDIF
←
Index + 1
Index
CALL Delete(Index, Target)
ENDIF
ENDPROCEDURE
An array Numbers is used to store a sorted data set of non-zero positive integers.
Unused cells contain zero.
The contents of the array at the start of the algorithm are:
Numbers
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
[10]
2
3
7
11
15
17
19
23
0
0
Complete the trace table for the algorithm for the procedure call:
CALL Delete(1, 15)
Numbers
Index
Target
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
[10]
2
3
7
11
15
17
19
23
0
0
[4]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
ĬÍĊ®Ġ´íÈõÏĪÅĊÞùµĄ×

8
9618/31/M/J/24 · Question 10May/June 2024Paper 318 marks
Loading question…
Question text

10 (a) State a condition that must be true for an array to be searchable for a binary search.
…
… [1]
(b) Complete the given pseudocode to find an item in a 1D array Names of type STRING using a
binary search.
DECLARE Names : ARRAY[1:100000] OF STRING
DECLARE TopOfList : INTEGER
DECLARE EndOfList : INTEGER
DECLARE CurrentItem : INTEGER
DECLARE ToFind : STRING
DECLARE Found : BOOLEAN
DECLARE NotInList : BOOLEAN
←
1
TopOfList
←
100000
EndOfList
OUTPUT "Which name do you wish to find? "
INPUT ToFind
…
← FALSE
NotInList
WHILE … AND …
←
(TopOfList + EndOfList) DIV 2
CurrentItem
IF … THEN
←
TRUE
Found
ELSE
IF TopOfList >= EndOfList THEN
…
ELSE
IF ToFind > Names[CurrentItem] THEN
…
ELSE
←
CurrentItem – 1
EndOfList
ENDIF
ENDIF
ENDIF
ENDWHILE
IF Found = TRUE THEN
OUTPUT "Item found at position ", CurrentItem, " in array"
ELSE
OUTPUT "Item not in array"
ENDIF
[5]
(c) Describe the performance of a binary search in relation to the number of data items in the
array being searched. Refer to Big O notation in your answer.
…
…
…
… [2]

Advertisement
9
9618/32/M/J/24 · Question 8May/June 2024Paper 328 marks
Loading question…
Question text

(a) Complete the pseudocode to find an item in a 1D array Widgets of type STRING, using a
8
linear search.
DECLARE Widgets : ARRAY[1:50000] OF STRING
DECLARE TopOfList : INTEGER
DECLARE EndOfList : INTEGER
DECLARE Count : INTEGER
DECLARE ToFind : STRING
DECLARE Found : BOOLEAN
DECLARE NotInList : BOOLEAN
1
TopOfList
50000
EndOfList
OUTPUT "Enter the name of the item you wish to find "
INPUT ToFind
…
FALSE
NotInList
TopOfList
Count
WHILE … AND …
IF … THEN
TRUE
Found
ENDIF
Count + 1
Count
IF … THEN
TRUE
NotInList
ENDIF
ENDWHILE
IF Found = TRUE THEN
OUTPUT "Item found at position ", Count - 1, " in array"
ELSE
OUTPUT "Item not in array"
ENDIF
[4]
(b) Compare the methods used by the linear and binary search algorithms to find an item in an
array. Refer to Big O notation in your answer.
…
…
…
…
…
…
…
… [4]

10
9618/33/M/J/24 · Question 10May/June 2024Paper 338 marks
Loading question…
Question text

10 (a) State a condition that must be true for an array to be searchable for a binary search.
…
… [1]
(b) Complete the given pseudocode to find an item in a 1D array Names of type STRING using a
binary search.
DECLARE Names : ARRAY[1:100000] OF STRING
DECLARE TopOfList : INTEGER
DECLARE EndOfList : INTEGER
DECLARE CurrentItem : INTEGER
DECLARE ToFind : STRING
DECLARE Found : BOOLEAN
DECLARE NotInList : BOOLEAN
←
TopOfList
1
←
EndOfList
100000
OUTPUT "Which name do you wish to find? "
INPUT ToFind
…
← FALSE
NotInList
WHILE … AND …
←
CurrentItem
(TopOfList + EndOfList) DIV 2
IF … THEN
←
Found
TRUE
ELSE
IF TopOfList >= EndOfList THEN
…
ELSE
IF ToFind > Names[CurrentItem] THEN
…
ELSE
←
EndOfList
CurrentItem – 1
ENDIF
ENDIF
ENDIF
ENDWHILE
IF Found = TRUE THEN
OUTPUT "Item found at position ", CurrentItem, " in array"
ELSE
OUTPUT "Item not in array"
ENDIF
[5]
,
,
(c) Describe the performance of a binary search in relation to the number of data items in the
array being searched. Refer to Big O notation in your answer.
…
…
…
… [2]

11
9618/31/M/J/23 · Question 11May/June 2023Paper 3111 marks
Loading question…
Question text

11
Pseudocode is to be written to implement a queue Abstract Data Type (ADT) with items of the
string data type. This will be implemented using the information in the table.
Identifier
Data type
Description
FrontPointer
INTEGER
points to the start of the queue
RearPointer
INTEGER
points to the end of the queue
Length
INTEGER
the current size of the queue
Queue
STRING
1D array to implement the queue
A constant, with identifier MaxSize, limits the size of the queue to 60 items.
(a) Write the pseudocode to declare MaxSize, FrontPointer, RearPointer, Length and
Queue.
…
…
…
…
…
… [3]
(b) Complete the following pseudocode for the function Dequeue to remove the front item from
the queue.
FUNCTION Dequeue RETURNS STRING
DECLARE Item : STRING
… > 0 THEN
Item ← …
…
IF Length = 0 THEN
CALL Initialise // reset the pointers
ELSE
IF FrontPointer > MaxSize THEN
… ← 1
ENDIF
ENDIF
ELSE
OUTPUT "The print queue was empty – error!"
Item ← ""
ENDIF
RETURN Item
ENDFUNCTION
[4]
(c) Explain how a new element can be added to the queue if it is implemented using two stacks.
…
…
…
…
…
… [4]

12
9618/31/M/J/23 · Question 12May/June 2023Paper 317 marks
Loading question…
Question text

12 (a) Describe what is meant by recursion.
…
…
…
… [2]
(b) A Fibonacci sequence is a series of numbers formed by adding together the two preceding
numbers, for example:
0, 1, 1, 2, …
This function calculates and returns values in the Fibonacci sequence and uses recursion.
FUNCTION Fib(Number : INTEGER) RETURNS INTEGER
IF Number <= 1 THEN
Result ← Number
ELSE
Result ← Fib(Number – 1) + Fib(Number – 2)
ENDIF
RETURN Result
ENDFUNCTION
Complete the trace table for the function when it is called as Fib(5).
Call number
Function call
Number
Result
Return value
5
[5]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge

13
9618/32/M/J/23 · Question 11May/June 2023Paper 3210 marks
Loading question…
Question text

11
(a) The pseudocode shown represents a queue Abstract Data Type (ADT) with procedures for
initialisation and to add new items. It is incomplete.
CONSTANT MaxLength = 50
DECLARE FrontPointer : INTEGER
DECLARE RearPointer : INTEGER
DECLARE Length : INTEGER
DECLARE Queue : ARRAY[0 : MaxLength – 1] OF STRING
// initialisation of queue
PROCEDURE Initialise
‑1
FrontPointer
…
…
0
ENDPROCEDURE
// adding a new item to the queue
PROCEDURE Enqueue(NewItem : STRING)
IF … THEN
…
RearPointer
IF RearPointer > MaxLength – 1 THEN
0
RearPointer
ENDIF
…
Length + 1
Length
ENDIF
ENDPROCEDURE
(i)
Study the pseudocode and insert the identifiers to complete this table.
Identifier
Data type
Description
STRING
An array to store the contents of the queue.
INTEGER
Points to the last item of the queue.
INTEGER
Indicates the number of items in the queue.
INTEGER
Points to the first item of the queue.
[2]
(ii)
Complete the given pseudocode.
[5]
(b) Explain the reasons why a queue ADT works better than a stack ADT in organising print jobs.
…
…
…
…
…
… [3]
Permission to reproduce items where third‑party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer‑related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge

Advertisement
14
9618/32/M/J/22 · Question 8May/June 2022Paper 3213 marks
Loading question…
Question text

8
A binary search or a linear search can be used to look for a specific value in an array.
(a) Complete this pseudocode algorithm for a linear search.
DECLARE
MyList : ARRAY[0:9] OF INTEGER
DECLARE
MaxIndex : INTEGER
DECLARE
Index : INTEGER
DECLARE
Found : BOOLEAN
ValueToFind : …
DECLARE
INPUT ValueToFind
←
FALSE
Found
←
0
Index
←
…
MaxIndex
REPEAT
IF MyList[Index] = ValueToFind THEN
←
TRUE
Found
ENDIF
←
…
Index
UNTIL Found OR Index > MaxIndex
IF Found THEN
OUTPUT "Value found at position ", Index
ELSE
OUTPUT …
ENDIF
[4]
(b) (i)
State the necessary condition for a binary search.
…
… [1]
(ii)
Describe how to perform a binary search.
…
…
…
…
…
…
…
… [4]
(iii)
Explain how the performance of a binary search varies according to the number of values
in the array.
…
…
… [1]
(c) Compare the performance of the algorithms for a binary search and a linear search using
Big O notation for order of time complexity.
…
…
…
…
…
…

15
9618/31/M/J/21 · Question 8May/June 2021Paper 318 marks
Loading question…
Question text

8
(a) State two factors that may affect the performance of a sorting algorithm.
…
…
…
… [2]
(b) The given algorithm is a simple bubble sort that arranges a set of scores stored in a one-
dimensional array into descending order, and orders the corresponding students’ names
stored into a two-dimensional array in the same order as the scores. All the arrays are indexed
from 1.
The contents of both arrays after sorting are shown.
Name
Score
1
2
1
1
98
Smithfield
Tom
2
2
97
Johnson
Jane
…
…
248 5
248 Peters
Jade
249 3
249 Allen
John
←
249
YearSize
←
TRUE
Flag
WHILE Flag = TRUE
←
FALSE
Flag
←
1 TO YearSize - 1
FOR Student
IF Score[Student] < Score[Student + 1] THEN
←
Score[Student]
Temp1
←
Name[Student,1]
Temp2
←
Name[Student,2]
Temp3
←
Score[Student + 1]
Score[Student]
←
Name[Student + 1,1]
Name[Student,1]
←
Name[Student + 1,2]
Name[Student,2]
←
Temp1
Score[Student + 1]
←
Temp2
Name[Student + 1,1]
←
Temp3
Name[Student + 1,2]
←
TRUE
Flag
ENDIF
NEXT Student
ENDWHILE
Write an algorithm, using pseudocode, that will perform the same task using an insertion sort.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement