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

41 questions · page 2 of 3

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
16
9618/41/M/J/25 · Question 3May/June 2025Paper 4130 marks
Loading question…
Question text

3
A program stores data in a binary tree that is designed using Object‑Oriented Programming
(OOP).
The tree stores data in ascending numerical order, for example:
30
20
45
1
21
33
63
The class Node stores data about the nodes.
Node
NodeData : Integer
stores the node’s integer data
LeftNode : Node
stores the node that is stored to the left of the current
node, or a null value if there is no node to the left
RightNode : Node
stores the node that is stored to the right of the current
node, or a null value if there is no node to the right
Constructor()
initialises NodeData to its parameter value; initialises
LeftNode and RightNode to a null value
GetLeft()
returns LeftNode
GetRight()
returns RightNode
GetData()
returns NodeData
SetLeft()
takes an object of type Node as a parameter and stores
it in LeftNode
SetRight()
takes an object of type Node as a parameter and stores
it in RightNode
Write program code to declare the class Node and its constructor.
(a) (i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question3_J25.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[4]
(ii)
Write program code for the three get methods.
Save your program.
Copy and paste the program code into part 3(a)(ii) in the evidence document.
[3]
The method SetLeft() takes an object of type Node as a parameter. The method
(iii)
stores the parameter in the attribute LeftNode
The method SetRight() takes an object of type Node as a parameter. The method
stores the parameter in the attribute RightNode
Write program code for SetLeft() and SetRight()
Save your program.
Copy and paste the program code into part 3(a)(iii) in the evidence document.
[3]
(b) Write the main program to declare five objects of type Node :
•
Node 1 with the data 10
•
Node 2 with the data 20
•
Node 3 with the data 5
•
Node 4 with the data 15
•
Node 5 with the data 7
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[2]
(c) The class Tree stores the tree.
Tree
FirstNode : Node
stores the root node in the tree
Constructor()
initialises FirstNode to its parameter value
GetRootNode()
returns the node stored in FirstNode
Insert()
stores its parameter node in the correct position in the
tree
Write program code to declare the class Tree and its constructor.
(i)
Do not declare the other methods.
Use your programming language appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 3(c)(i) in the evidence document.
[2]
Write program code for GetRootNode()
(ii)
Save your program.
Copy and paste the program code into part 3(c)(ii) in the evidence document.
[1]
The method Insert() takes a node as a parameter and then searches the tree to find
(iii)
the position to insert the new node by:
•
checking whether the node’s data is less than or greater than the root node’s data
•
moving to the left node if the data is less than the root node’s data
•
moving to the right node if the data is greater than or equal to the root node’s data
•
repeating until the final position of the node is found and stores the node in that
position.
Write program code for Insert()
Save your program.
Copy and paste the program code into part 3(c)(iii) in the evidence document.
[6]
(d) The recursive procedure OutputInOrder() outputs the data stored in the binary tree in
ascending numerical order.
The procedure takes a Node object as a parameter and then:
•
checks if the left node is null. If there is a left node, the function calls itself with the left
node
•
outputs the data of the current node
•
checks if the right node is null. If there is a right node, the function calls itself with the
right node.
Write program code for OutputInOrder()
Save your program.
Copy an

17
9618/43/M/J/25 · Question 2May/June 2025Paper 4320 marks
Loading question…
Question text

A program sorts the data in the 1D array DataArray and searches DataArray for specific
2
values.
DataArray stores 14 integer values and is declared local to the main program.
(a) Write program code to create DataArray and initialise it with the following data values in the
order they are written:
0
3
4
56
67
44
43
32
31
345
45
6
54
1
Save your program as Question2_J25.
Copy and paste the program code into part 2(a) in the evidence document.
[1]
(b) The function InsertionSort() takes an array of integers as a parameter. The function
sorts the data in the array into ascending numerical order using an insertion sort. The function
returns the sorted array.
Write program code for InsertionSort()
You must not use any inbuilt sorting functions for your programming language.
Save your program.
Copy and paste the program code into part 2(b) in the evidence document.
[5]
(c) The procedure OutputArray() takes an array of integers as a parameter. The procedure
outputs each element in the array from the first element to the last element. The output is on
one line with a space between each number.
An example output is:
"0 3 4 56 67 44 43 32 31 345 45 6 54 1"
Write program code for OutputArray()
Save your program.
Copy and paste the program code into part 2(c) in the evidence document.
[2]
(d) (i)
The main program needs extending to:
•
output the content of the unsorted array using OutputArray()
•
sort the array using InsertionSort()
•
output the content of the sorted array using OutputArray()
Write program code to extend the main program.
Save your program.
Copy and paste the program code into part 2(d)(i) in the evidence document.
[2]
(ii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 2(d)(ii) in the evidence document.
[1]
(e) The function Search() performs a binary search to find ItemToFind in DataArray
The function takes two parameters:
•
DataArray, an array of integers
•
ItemToFind, an integer to find in DataArray
The function returns:
•
the index of ItemToFind if it is in DataArray
•
–1 if ItemToFind is not in DataArray
Write program code for Search()
You must not use any inbuilt searching functions for your programming language.
Save your program.
Copy and paste the program code into part 2(e) in the evidence document.
[6]
The main program needs extending to call Search() with the sorted array four times:
(f)
(i)
•
the first time to find the index of the integer 0
•
the second time to find the index of the integer 345
•
the third time to find the index of the integer 67
•
the fourth time to find the index of the integer 2
If the integer is found in the array, output an appropriate message that includes the index.
If the integer is not found, output that it was not found.
Write program code to extend the main program.
Save your program.
Copy and paste the program code into part 2(f)(i) in the evidence document.
[2]
(ii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 2(f)(ii) in the evidence document.
[1]

18
9618/31/O/N/24 · Question 11Oct/Nov 2024Paper 3112 marks
Loading question…
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
ĬÍĊ®Ġ´íÈõÏĪÅĊÝû¶Ą×

Advertisement
19
9618/32/O/N/24 · Question 11Oct/Nov 2024Paper 3212 marks
Loading question…
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
ĬÍĊ®Ġ´íÈõÏĪÅĊÝüµĄ×

20
9618/33/O/N/24 · Question 11Oct/Nov 2024Paper 3312 marks
Loading question…
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
ĬÍĊ®Ġ´íÈõÏĪÅĊÞú¶Ą×

21
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]

22
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]

23
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]

Advertisement
24
9618/42/M/J/24 · Question 2May/June 2024Paper 4230 marks
Loading question…
Question text

2
A binary tree stores data in ascending order. For example:
15
8
19
3
10
A computer program stores integers in a binary tree in ascending order. The program uses
Object‑Oriented Programming (OOP).
The binary tree is stored as a 1D array of nodes. Each node contains a left pointer, a data value
and a right pointer.
The class Node stores the data about a node.
Node
LeftPointer : INTEGER
stores the index of the node to the left in the binary tree
Data : INTEGER
stores the node’s data
RightPointer : INTEGER
stores the index of the node to the right in the binary tree
Constructor()
initialises Data to its parameter value
initialises LeftPointer and RightPointer to −1
GetLeft()
returns the left pointer
GetRight()
returns the right pointer
GetData()
returns the data value
SetLeft()
assigns the parameter to the left pointer
SetRight()
assigns the parameter to the right pointer
SetData()
assigns the parameter to the data
Write program code to declare the class Node and its constructor.
(a) (i)
Do not declare the other methods.
Use the appropriate constructor for your programming language.
If you are writing in Python, include attribute declarations using comments.
Save your program as Question2_J24.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[4]
The get methods GetLeft(), GetRight()and GetData()each return the relevant
(ii)
attribute.
Write program code for the three get methods.
Save your program.
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[3]
The set methods SetLeft(), SetRight()and SetData()each take a parameter and
(iii)
then store this in the relevant attribute.
Write program code for the three set methods.
Save your program.
Copy and paste the program code into part 2(a)(iii) in the evidence document.
[3]
(b) The class TreeClass stores the data about the binary tree.
TreeClass
Tree[0:19] : Node
an array of 20 elements of type Node
FirstNode : INTEGER
stores the index of the first node in the tree
NumberNodes : INTEGER
stores the quantity of nodes in the tree
Constructor()
initialises FirstNode to −1 and NumberNodes to 0
initialises each element in Tree to a Node object with the
data value of −1
InsertNode()
takes a Node object as a parameter, inserts it in the array
and updates the pointer for its parent node
OutputTree()
outputs the left pointer, data and right pointer of each
node in Tree
Nodes cannot be deleted from this tree.
Write program code to declare the class TreeClass and its constructor.
(i)
Do not declare the other methods.
Use the appropriate constructor for your programming language.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 2(b)(i) in the evidence document.
[4]
The method InsertNode()takes a Node object, NewNode, as a parameter and inserts
(ii)
it into the array Tree.
InsertNode()first checks if the tree is empty.
If the tree is empty, InsertNode():
•
stores NewNode in the array Tree at index NumberNodes
•
increments NumberNodes
•
stores 0 in FirstNode.
If the tree is not empty, InsertNode():
•
stores NewNode in the array Tree at index NumberNodes
•
accesses the data in the array Tree at index FirstNode and compares it to the
data in NewNode
•
repeatedly follows the pointers until the correct position for NewNode is found
•
once the position is found, InsertNode()sets the left or right pointer of its parent
node
•
increments NumberNodes.
Write program code for InsertNode().
Save your program.
Copy and paste the program code into part 2(b)(ii) in the evidence document.
[6]
The method OutputTree()outputs the left pointer, the data and the right pointer for
(iii)
each node that has been inserted into the tree. The outputs are in the order they are
saved in the array.
If there are no nodes in the array, the procedure outputs ‘No nodes’.
Write program code for OutputTree().
Save your program.
Copy and paste the progra

25
9618/42/M/J/24 · Question 3May/June 2024Paper 4223 marks
Loading question…
Question text

3
A program sorts an array of integers and searches the array for a particular value.
(a) The array of integers, NumberArray, stores the following data in the order given:
100
85
644
22
15
8
1
The array is declared and initialised local to the main program.
Write program code to declare and initialise the array.
Save your program as Question3_J24.
Copy and paste the program code into part 3(a) in the evidence document.
[1]
(b) (i)
The following recursive pseudocode function sorts the array into ascending order using
an insertion sort and returns the sorted array.
DECLARE LastItem : INTEGER
DECLARE CheckItem : INTEGER
DECLARE LoopAgain : BOOLEAN
FUNCTION RecursiveInsertion(IntegerArray : ARRAY[] OF INTEGER,
NumberElements : INTEGER) RETURNS ARRAY[] OF INTEGER
IF NumberElements <= 1 THEN
RETURN IntegerArray
ELSE
CALL RecursiveInsertion(IntegerArray, NumberElements - 1)
LastItem
IntegerArray[NumberElements - 1]
CheckItem
NumberElements - 2
ENDIF
LoopAgain
TRUE
IF CheckItem < 0 THEN
LoopAgain
FALSE
ELSE
IF IntegerArray[CheckItem] < LastItem THEN
LoopAgain
FALSE
ENDIF
ENDIF
WHILE LoopAgain
IntegerArray[CheckItem + 1]
IntegerArray[CheckItem]
CheckItem
CheckItem - 1
IF CheckItem < 0 THEN
LoopAgain
FALSE
ELSE
IF IntegerArray[CheckItem] < LastItem THEN
LoopAgain
FALSE
ENDIF
ENDIF
ENDWHILE
IntegerArray[CheckItem + 1]
LastItem
RETURN IntegerArray
ENDFUNCTION
Write the program code for the pseudocode function RecursiveInsertion().
Save your program.
Copy and paste the program code into part 3(b)(i) in the evidence document.
[4]
(ii)
Amend the main program to:
•
call RecursiveInsertion()with the initialised array NumberArray and the
number of elements as parameters
•
output the word ‘Recursive’
•
output the content of the returned array.
Save your program.
Copy and paste the program code into part 3(b)(ii) in the evidence document.
[2]
(iii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 3(b)(iii) in the evidence document.
[1]
(c) The function RecursiveInsertion()can be changed to use iteration instead of recursion.
Write program code for the function IterativeInsertion()to perform the same
(i)
processes as RecursiveInsertion()but using iteration instead of recursion.
Save your program.
Copy and paste the program code into part 3(c)(i) in the evidence document.
[4]
(ii)
Write program code to amend the main program to also:
•
call IterativeInsertion()with the original initialised array NumberArray
•
output the word ‘iterative’
•
output the content of the returned array.
Save your program.
Copy and paste the program code into part 3(c)(ii) in the evidence document.
[1]
(iii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 3(c)(iii) in the evidence document.
[1]
(d) The recursive function BinarySearch()takes the parameters:
•
IntegerArray – an array of integers
•
First – the index of the first array element
•
Last – the index of the last array element
•
ToFind – an integer to search for in the array.
The function uses recursion to perform a binary search for ToFind in IntegerArray.
The function returns the index where ToFind is stored or returns −1 if ToFind is not in the
array.
Write program code for the recursive function BinarySearch().
(i)
Save your program.
Copy and paste the program code into part 3(d)(i) in the evidence document.
[6]
(ii)
Write program code to amend the main program to:
•
call BinarySearch()with the sorted array and the integer 644 as the search value
•
output ‘Not found’ if 644 is not found in the array
•
output the index if 644 is found in the array.
Save your program.
Copy and paste the program code into part 3(d)(ii) in the evidence document.
[2]
(iii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot into part 3(d)(iii) in the evidence document.
[1]

26
9618/31/O/N/23 · Question 10Oct/Nov 2023Paper 3110 marks
Loading question…
Question text

10 A stack is to be set up using the information in the table.
Identifier
Data type
Description
BasePointer
INTEGER
points to the bottom of the stack
TopPointer
INTEGER
points to the top of the stack
Stack
REAL
1D array to implement the stack
A constant, with identifier Capacity, limits the size of the stack to 25 items.
(a) Write the pseudocode for the required declarations.
…
…
…
…
…
… [3]
(b) Complete the pseudocode function Pop() to pop an item from Stack.
// popping an item from the stack
FUNCTION Pop() …
DECLARE Item : REAL
0
Item
… BasePointer THEN
…
Item
…
TopPointer
ELSE
OUTPUT "The stack is empty – error"
ENDIF
…
ENDFUNCTION
[5]
(c) Compare and contrast the queue and stack Abstract Data Types (ADT).
…
…
…
…
…
… [2]

27
9618/32/O/N/23 · Question 9Oct/Nov 2023Paper 3213 marks
Loading question…
Question text

9
(a) A stack Abstract Data Type (ADT) is to be implemented using pseudocode, with procedures
to initialise it and to push new items onto the stack.
A 1D array Stack stores the contents of the stack.
(i)
Study the pseudocode in part (a)(ii) and complete the table of identifiers by writing the
missing data types and descriptions.
Identifier
Data type
Description
BasePointer
TopPointer
Stack
REAL
[2]
(ii)
Complete the pseudocode.
CONSTANT MaxSize = 40
DECLARE BasePointer : INTEGER
DECLARE TopPointer : INTEGER
DECLARE Stack : ARRAY[1:40] OF REAL
// initialisation of stack
PROCEDURE Initialise()
…
1
…
0
ENDPROCEDURE
// push an item onto the stack
PROCEDURE Push(NewItem : REAL)
… MaxSize THEN
…
…
Stack[TopPointer]
ENDIF
ENDPROCEDURE
[5]
(b) Justify the use of a linked list instead of an array to implement a stack.
…
…
…
… [2]
(c) Explain how a compiler makes use of a stack when translating recursive programming code.
…
…
…
…
…
…
…
… [4]

28
9618/41/O/N/23 · Question 1Oct/Nov 2023Paper 4116 marks
Loading question…
Question text

1
This iterative pseudocode algorithm for the function IterativeVowels() takes a string as a
parameter and counts the number of lower-case vowels in this string.
The vowels are the letters a, e, i, o and u.
FUNCTION IterativeVowels(Value : STRING) RETURNS INTEGER
DECLARE Total : INTEGER
DECLARE LengthString : INTEGER
DECLARE FirstCharacter : CHAR
← 0
Total
← LENGTH(Value)
LengthString
← 0 TO LengthString - 1
FOR X
FirstCharacter ← MID(Value, 0, 1)
IF FirstCharacter = 'a' OR FirstCharacter = 'e' OR
FirstCharacter = 'i' OR FirstCharacter = 'o' OR
FirstCharacter = 'u' THEN
← Total + 1
Total
ENDIF
← MID(Value, 1, LENGTH(Value)-1)
Value
NEXT X
RETURN Total
ENDFUNCTION
The pseudocode function MID(X, Y, Z) returns Z number of characters from string X, starting
at the character in position Y. The first character in a string is in position 0, for example:
MID("computer", 0, 3) returns "com"
The pseudocode function LENGTH(X) returns the number of characters in the string X, for
example:
LENGTH("computer") returns 8
(a) (i)
Write program code for the function IterativeVowels().
Save your program as Question1_N23.
Copy and paste the program code into part 1(a)(i) in the evidence document.
[5]
(ii)
Write program code to call the function IterativeVowels() with the parameter
"house" from the main program.
Output the return value.
Save your program.
Copy and paste the program code into part 1(a)(ii) in the evidence document.
[2]
(iii)
Test your program.
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 1(a)(iii) in the evidence document.
[1]
(b) (i)
Rewrite the function IterativeVowels() as a recursive function with the identifier
RecursiveVowels().
Save your program.
Copy and paste the program code into part 1(b)(i) in the evidence document.
[6]
(ii)
Write program code to call the function RecursiveVowels() with the parameter
"imagine" from the main program.
Output the return value.
Save your program.
Copy and paste the program code into part 1(b)(ii) in the evidence document.
[1]
(iii)
Test your program.
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 1(b)(iii) in the evidence document.
[1]

Advertisement
29
9618/42/O/N/23 · Question 2Oct/Nov 2023Paper 4217 marks
Loading question…
Question text

2
An integer is said to be divisible by another integer if the result of the division is also an integer.
For example:
10 is divisible by 1, 2, 5 and 10:
•
10 ÷ 1 = 10
•
10 ÷ 2 = 5
•
10 ÷ 5 = 2
•
10 ÷ 10 = 1
10 is not divisible by 4:
•
10 ÷ 4 = 2.5
1, 2, 5 and 10 are said to be the divisors of 10.
The iterative function IterativeCalculate() totals all the divisors of its integer parameter and
returns this total.
Example 1: if the parameter is 10, the total will be 18 (1 + 2 + 5 + 10) .
Example 2: if the parameter is 4, the total will be 7 (1 + 2 + 4) .
A pseudocode algorithm for IterativeCalculate() is shown.
FUNCTION IterativeCalculate(Number : INTEGER) RETURNS INTEGER
DECLARE Total : Integer
DECLARE ToFind : Integer
← Number
ToFind
Total ← 0
WHILE Number <> 0
IF ToFind MODULUS Number = 0 THEN
← Total + Number
Total
ENDIF
← Number - 1
Number
ENDWHILE
RETURN Total
ENDFUNCTION
The operator MODULUS calculates the remainder when one number is divided by another.
(a) (i)
Write program code for IterativeCalculate().
Save your program as Question2_N23.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[5]
(ii)
Write program code to call IterativeCalculate() with 10 as the parameter and
output the return value.
Save your program.
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[2]
(iii)
Test your program.
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 2(a)(iii) in the evidence document.
[1]
(b) IterativeCalculate() has been rewritten as the recursive function RecursiveValue().
A pseudocode algorithm for RecursiveValue() is given. The function is incomplete.
FUNCTION RecursiveValue(Number : INTEGER, ToFind : INTEGER)
RETURNS INTEGER
IF Number = … THEN
RETURN 0
ELSE
IF ToFind … Number = 0 THEN
RETURN … + RecursiveValue(Number - 1, ToFind)
ELSE
… RecursiveValue(Number - 1, … )
ENDIF
ENDIF
ENDFUNCTION
(i)
Write program code for RecursiveValue().
Save your program.
Copy and paste the program code into part 2(b)(i) in the evidence document.
[7]
(ii)
Write program code to call RecursiveValue() with 50 as the first parameter and 50
as the second parameter and output the return value.
Save your program.
Copy and paste the program code into part 2(b)(ii) in the evidence document.
[1]
(iii)
Test your program.
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 2(b)(iii) in the evidence document.
[1]

30
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]

Advertisement