Computational thinking: searching, sorting, ADTs and recursion – A Level Computer Science (9618)
27 questions · page 1 of 2 · Clear filters
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.
…
…
…
…
…
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
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
Question text
9
(a) A stack has been implemented using pseudocode to store a maximum of 100 string items
using the global variables in the following table:
Initialisation
Identifier
Data type
Description
value
Base
INTEGER
0
pointer for the bottom of the stack
Top
INTEGER
‑1
pointer for the top of the stack
StackArray
STRING
[0:99]
1D array to implement the stack
Max
INTEGER
100
maximum number of items in the stack
The value of Top is incremented each time a data item is added to the stack and decremented
every time a data item is removed.
(i)
Complete the pseudocode for the function to remove a data item from the stack.
FUNCTION Pop() …
DECLARE DataItem : STRING
""
DataItem
IF … THEN
…
DataItem
…
Top
ELSE
"You cannot remove data; the stack is empty"
DataItem
ENDIF
…
ENDFUNCTION
[5]
(ii)
Write the pseudocode to output the data item removed from the stack with an appropriate
message.
…
… [1]
ĬÛú¾Ġ´íÈõÏĪÅĊÝùµĀ×
,
,
(b) A stack is used to implement recursion.
State the three essential features of recursion.
1 …
…
2 …
…
3 …
…
[3]
Question text
12 (a) A stack has been implemented using pseudocode to store a maximum of 100 string items
using the global variables in the following table:
Initialisation
Identifier
Data type
Description
value
Base
INTEGER
0
pointer for the bottom of the stack
Top
INTEGER
-1
pointer for the top of the stack
StackArray
STRING
[0:99]
1D array to implement the stack
Max
INTEGER
100
maximum number of items in the stack
The value of Top is incremented each time a data item is added to the stack and decremented
each time a data item is removed. If the stack is full, an appropriate error message is output.
(i)
Complete the pseudocode for the procedure to add a data item onto the stack.
PROCEDURE Push( … )
IF Top < Max – 1 THEN
Top ← …
… ← NewData
ELSE
OUTPUT …
ENDIF
ENDPROCEDURE
[4]
(ii)
Write pseudocode to input a new data item and add it to the stack using Push().
…
…
…
… [2]
(b) Explain the reasons why a stack is used when a recursive algorithm is executed.
…
…
…
…
…
… [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
ĬÍĊ®Ġ´íÈõÏĪÅĊÝú¶Ą×
Question text
10 A stack, StackArray, is to be implemented using pseudocode, to store a maximum of 100 string
items in an appropriate array. Declarations are required so that the stack has a beginning, an end
and a maximum size. An array is also required to store the data.
(a) Write pseudocode to declare the variables, constant and array required to implement the
stack.
…
…
…
…
…
… [3]
(b) Write pseudocode for a procedure to initialise the top and bottom pointers of the stack to
appropriate values.
…
…
…
…
…
… [3]
ĬÙú¾Ġ´íÈõÏĪÅĊàù¶Ā×
Question text
11
Describe when the use of recursion would be beneficial and give an example.
Description …
…
…
…
Example …
…
[3]
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]
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]
ĬÓĊ®Ġ´íÈõÏĪÅĊÞû¸þ×
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]
ĬÏĊ®Ġ´íÈõÏĪÅĊàûµĂ×
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
ĬÍĊ®Ġ´íÈõÏĪÅĊÞùµĄ×
Question text
11
The following diagram shows an ordered binary tree.
Red
Green
Yellow
Blue
Orange
Violet
Indigo
(a) A linked list of nodes is used to store the data. Each node consists of a left pointer, the data
and a right pointer.
–1 is used to represent a null pointer.
Complete this linked list to represent the given binary tree.
RootPtr
LeftPtr
Data
RightPtr
Red
Green
–1
Blue
–1
[4]
ĬÑĊ®Ġ´íÈõÏĪÅĊàú·Ā×
,
,
(b) A user-defined record structure is used to store the nodes of the linked list in part (a).
Complete the diagram, using your answer for part (a).
RootPtr
Index
LeftPtr
Data
RightPtr
0
Red
0
Green
1
Yellow
2
Blue
3
Orange
4
Indigo
5
Violet
FreePtr
6
7
[4]
(c) The linked list in part (a) is implemented using a 1D array of records. Each record contains a
left pointer, data and a right pointer.
The following pseudocode represents a function that searches for an element in the array of
records BinTree. It returns the index of the record if the element is found, or it returns a null
pointer if the element is not found.
Complete the pseudocode for the function.
FUNCTION SearchTree(Item : STRING) …
…
NowPtr
WHILE NowPtr <> -1
IF … THEN
NowPtr
BinTree[NowPtr].LeftPtr
ELSE
IF BinTree[NowPtr].Data < Item THEN
…
ELSE
RETURN NowPtr
ENDIF
ENDIF
ENDWHILE
RETURN NowPtr
ENDFUNCTION
[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
ĬÍĊ®Ġ´íÈõÏĪÅĊÝû¶Ą×
Question text
11
This binary tree shows an ordered list of integers.
25
4
36
1
16
64
9
49
(a) A linked list of nodes is used to store the data. Each node consists of a left pointer, the data
and a right pointer.
−1 is used to represent a null pointer.
Complete this linked list to represent the given binary tree organisation.
RootPtr
LeftPtr
Data RightPtr
25
4
–1
1
–1
[4]
ĬÑĊ®Ġ´íÈõÏĪÅĊàù¸Ā×
,
,
(b) A 2D array is used to store the nodes of the linked list in part (a).
Complete the diagram using your answer for part (a).
RootPtr
Index
LeftPtr
Data
RightPtr
0
25
0
4
1
36
2
1
3
16
4
64
5
9
FreePtr
6
49
7
8
[4]
(c) The linked list in part (a) is implemented using a 1D array of records. Each record contains a
left pointer, data and a right pointer.
The following pseudocode represents a function that searches for an element in the array of
records LinkList. It returns the index of the record if the element is found, or it returns a
null pointer if the element is not found.
Complete the pseudocode for the function.
FUNCTION SearchList(Item : INTEGER) …
−1
NullPtr
RootPtr
…
WHILE NowPtr <> NullPtr
IF LinkList[NowPtr].Data < Item THEN
NowPtr
LinkList[NowPtr].RightPtr
ELSE
IF … THEN
NowPtr
…
ELSE
RETURN NowPtr
ENDIF
ENDIF
ENDWHILE
RETURN NullPtr
ENDFUNCTION
[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
ĬÍĊ®Ġ´íÈõÏĪÅĊÝüµĄ×
Question text
11
The following diagram shows an ordered binary tree.
Red
Green
Yellow
Blue
Orange
Violet
Indigo
(a) A linked list of nodes is used to store the data. Each node consists of a left pointer, the data
and a right pointer.
–1 is used to represent a null pointer.
Complete this linked list to represent the given binary tree.
RootPtr
LeftPtr
Data
RightPtr
Red
Green
–1
Blue
–1
[4]
ĬÑĊ®Ġ´íÈõÏĪÅĊßû·Ā×
,
,
(b) A user-defined record structure is used to store the nodes of the linked list in part (a).
Complete the diagram, using your answer for part (a).
RootPtr
Index
LeftPtr
Data
RightPtr
0
Red
0
Green
1
Yellow
2
Blue
3
Orange
4
Indigo
5
Violet
FreePtr
6
7
[4]
(c) The linked list in part (a) is implemented using a 1D array of records. Each record contains a
left pointer, data and a right pointer.
The following pseudocode represents a function that searches for an element in the array of
records BinTree. It returns the index of the record if the element is found, or it returns a null
pointer if the element is not found.
Complete the pseudocode for the function.
FUNCTION SearchTree(Item : STRING) …
…
NowPtr
WHILE NowPtr <> -1
IF … THEN
NowPtr
BinTree[NowPtr].LeftPtr
ELSE
IF BinTree[NowPtr].Data < Item THEN
…
ELSE
RETURN NowPtr
ENDIF
ENDIF
ENDWHILE
RETURN NowPtr
ENDFUNCTION
[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
ĬÍĊ®Ġ´íÈõÏĪÅĊÞú¶Ą×
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]