Data types, records, arrays and abstract data types – A Level Computer Science (9618)

162 questions · page 11 of 11

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
151
9618/22/O/N/21 · Question 6Oct/Nov 2021Paper 2219 marks
Loading question…
Question text

6
A mobile phone has a touchscreen. The screen is represented by a grid, divided into 800 rows
and 1280 columns.
The grid is represented by a 2D array Screen of type INTEGER. An array element will be set to 0
unless the user touches that part of the screen.
Many array elements will set to 1 by a single touch of a finger or a stylus.
The following diagram shows a simplified touchscreen. The dark line represents a touch on the
screen. All grid elements that are wholly or partly inside the outline will be set to 1. These elements
are shaded.
The element shaded in black represents the centre point of the touch.
11
6
A program is needed to find the coordinates (the row and column) of the centre point. The centre
point on the diagram shown is row 6, column 11.
Assume:
•
the user may only touch one area at a time
•
screen rotation does not affect the touchscreen.
The programmer has decided to use global values CentreRow and CentreCol as coordinate
values for the centre point.
The programmer has started to define program modules as follows:
Module
Description
• Searches for the first row that has an array element set to 1
• Returns the index of that row (1 is the first row)
FirstRowSet()
• Returns −1 if there are no elements set to 1
• Searches for the last row that has an array element set to 1
• Returns the index of that row
LastRowSet()
• Returns −1 if there are no elements set to 1
• Searches for the first column that has an array element set to 1
• Returns the index of that column (1 is the first column)
FirstColSet()
• Returns −1 if there are no elements set to 1
• Searches for the last column that has an array element set to 1
• Returns the index of that column
LastColSet()
• Returns −1 if there are no elements set to 1
(a) Write efficient pseudocode for the module FirstRowSet().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

152
9618/41/O/N/21 · Question 1Oct/Nov 2021Paper 4117 marks
Loading question…
Question text

1
Study the following pseudocode for a recursive function.
FUNCTION Unknown(BYVAL X, BYVAL Y : INTEGER) RETURNS INTEGER
IF X < Y THEN
OUTPUT X + Y
RETURN (Unknown(X + 1, Y) * 2)
ELSE
IF X = Y THEN
RETURN 1
ELSE
OUTPUT X + Y
RETURN (Unknown(X - 1, Y) DIV 2)
ENDIF
ENDIF
ENDFUNCTION
The operator DIV returns the integer value after division e.g. 13 DIV 2 would give 6
(a) Write program code to declare the function Unknown().
Save your program as question 1.
Copy and paste the program code into part 1(a) in the evidence document.
[3]
(b) The main program needs to run all three of the following function calls and output the result
of each call:
Unknown(10, 15)
Unknown(10, 10)
Unknown(15, 10)
(i)
For each of the three function calls, the main program needs to:
•
output the value of the two parameters
•
call the function with those parameters
•
output the return value.
Write the program code for the main program.
Save your program.
Copy and paste the program code into part 1(b)(i) in the evidence document.
[3]
(ii)
Take a screenshot to show the output from part (b)(i).
Copy and paste the screenshot into part 1(b)(ii) in the evidence document.
[2]
(c) Rewrite the function Unknown() as an iterative function, IterativeUnknown().
Save your program.
Copy and paste the program code into part 1(c) in the evidence document.
[7]
(d) The iterative function needs to be called three times with the same parameters as in part (b).
(i)
For each of the three function calls, the main program needs to:
•
output the value of the two parameters
•
call the iterative function with those parameters
•
output the return value.
Amend the main program to perform these tasks.
Save your program.
Copy and paste the program code into part 1(d)(i) in the evidence document.
[1]
(ii)
Take one or more screenshots to show the output of both functions for each set of
parameters.
Copy and paste the screenshot(s) into part 1(d)(ii) in the evidence document.
[1]

153
9618/41/O/N/21 · Question 3Oct/Nov 2021Paper 4134 marks
Loading question…
Question text

3
An ordered binary tree stores integer data in ascending numerical order.
The data for the binary tree is stored in a 2D array with the following structure:
LeftPointer
Data
RightPointer
Index
[0]
[1]
[2]
[0]
1
10
2
[1]
-1
5
-1
[2]
-1
16
-1
Each row in the table represents one node on the tree.
The number -1 represents a null pointer.
(a) The 2D array, ArrayNodes, is declared with space for 20 nodes.
Each node has a left pointer, data and right pointer.
The program also initialises the:
•
RootPointer to -1 (null); this points to the first node in the binary tree
•
FreeNode to 0; this points to the first empty node in the array.
Write program code to declare ArrayNodes, RootPointer and FreeNode in the main
program.
If you are writing in Python programming language, include attribute declarations using
comments.
Save your program as question 3.
Copy and paste the program code into part 3(a) in the evidence document.
[4]
(b) The procedure AddNode() adds a new node to the array ArrayNodes.
The procedure needs to:
•
take the array, root pointer and free node pointer as parameters
•
ask the user to enter the data and read this in
•
add the node to the root pointer if the tree is empty
•
otherwise, follow the pointers to find the position for the data item to be added
•
store the data in the location and update all pointers.
There are six incomplete statements in the following pseudocode for the procedure AddNode().
PROCEDURE AddNode(BYREF ArrayNodes[] : ARRAY OF INTEGER,
BYREF RootPointer : INTEGER, BYREF FreeNode : INTEGER)
OUTPUT "Enter the data"
INPUT NodeData
IF FreeNode <= 19 THEN
←
-1
ArrayNodes[FreeNode, 0]
←
…
ArrayNodes[FreeNode, 1]
←
-1
ArrayNodes[FreeNode, 2]
IF RootPointer = … THEN
←
0
RootPointer
ELSE
←
FALSE
Placed
←
RootPointer
CurrentNode
WHILE Placed = FALSE
IF NodeData < ArrayNodes[CurrentNode, 1] THEN
IF ArrayNodes[CurrentNode, 0] = -1 THEN
←
…
ArrayNodes[CurrentNode, 0]
←
TRUE
Placed
ELSE
←
ArrayNodes[CurrentNode, 0]
…
ENDIF
ELSE
IF ArrayNodes[CurrentNode, 2] = -1 THEN
←
FreeNode
ArrayNodes[CurrentNode, 2]
←
…
Placed
ELSE
←
ArrayNodes[CurrentNode, 2]
CurrentNode
ENDIF
ENDIF
ENDWHILE
ENDIF
←
… + 1
FreeNode
ELSE
OUTPUT("Tree is full")
ENDIF
ENDPROCEDURE
Write program code for the procedure AddNode().
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[8]
(c) The procedure PrintAll() outputs the data in each element in ArrayNodes, in the order
they are stored in the array.
Each element is printed in a row in the order:
LeftPointer
Data
RightPointer
For example:
1
20
-1
-1
10
-1
Write program code for the procedure PrintAll().
Save your program.
Copy and paste the program code into part 3(c) in the evidence document.
[4]
(d) The main program should loop 10 times, each time calling the procedure AddNode(). It
should then call the procedure PrintAll().
(i)
Edit the main program to perform the actions described.
Save your program.
Copy and paste the program code into part 3(d)(i) in the evidence document.
[3]
(ii)
Test the program by entering the data:
10
5
15
8
12
6
20
11
9
4
Take a screenshot to show the output after the given data are entered.
Copy and paste the screenshot into part 3(d)(ii) in the evidence document.
[1]
(e) An in-order tree traversal visits the left node, then the root (and outputs this), then visits the
right node.
(i)
Write a recursive procedure, InOrder(), to perform an in-order traversal on the tree
held in ArrayNodes.
Save your program.
Copy and paste the program code into part 3(e)(i) in the evidence document.
[7]
(ii)
Test the procedure InOrder() with the same data entered in part (d)(ii).
Take a screenshot to show the output after entering the data.
Copy and paste the screenshot into part 3(e)(ii) in the evidence document.
[1]
Permission to reproduce items where third-party owned materia

Advertisement
154
9618/42/O/N/21 · Question 3Oct/Nov 2021Paper 4234 marks
Loading question…
Question text

3
An ordered binary tree stores integer data in ascending numerical order.
The data for the binary tree is stored in a 2D array with the following structure:
LeftPointer
Data
RightPointer
Index
[0]
[1]
[2]
[0]
1
10
2
[1]
-1
5
-1
[2]
-1
16
-1
Each row in the table represents one node on the tree.
The number -1 represents a null pointer.
(a) The 2D array, ArrayNodes, is declared with space for 20 nodes.
Each node has a left pointer, data and right pointer.
The program also initialises the:
•
RootPointer to -1 (null); this points to the first node in the binary tree
•
FreeNode to 0; this points to the first empty node in the array.
Write program code to declare ArrayNodes, RootPointer and FreeNode in the main
program.
If you are writing in Python programming language, include attribute declarations using
comments.
Save your program as question 3.
Copy and paste the program code into part 3(a) in the evidence document.
[4]
(b) The procedure AddNode() adds a new node to the array ArrayNodes.
The procedure needs to:
•
take the array, root pointer and free node pointer as parameters
•
ask the user to enter the data and read this in
•
add the node to the root pointer if the tree is empty
•
otherwise, follow the pointers to find the position for the data item to be added
•
store the data in the location and update all pointers.
There are six incomplete statements in the following pseudocode for the procedure AddNode().
PROCEDURE AddNode(BYREF ArrayNodes[] : ARRAY OF INTEGER,
BYREF RootPointer : INTEGER, BYREF FreeNode : INTEGER)
OUTPUT "Enter the data"
INPUT NodeData
IF FreeNode <= 19 THEN
←
-1
ArrayNodes[FreeNode, 0]
←
…
ArrayNodes[FreeNode, 1]
←
-1
ArrayNodes[FreeNode, 2]
IF RootPointer = … THEN
←
0
RootPointer
ELSE
←
FALSE
Placed
←
RootPointer
CurrentNode
WHILE Placed = FALSE
IF NodeData < ArrayNodes[CurrentNode, 1] THEN
IF ArrayNodes[CurrentNode, 0] = -1 THEN
←
…
ArrayNodes[CurrentNode, 0]
←
TRUE
Placed
ELSE
←
ArrayNodes[CurrentNode, 0]
…
ENDIF
ELSE
IF ArrayNodes[CurrentNode, 2] = -1 THEN
←
FreeNode
ArrayNodes[CurrentNode, 2]
←
…
Placed
ELSE
←
ArrayNodes[CurrentNode, 2]
CurrentNode
ENDIF
ENDIF
ENDWHILE
ENDIF
←
… + 1
FreeNode
ELSE
OUTPUT "Tree is full"
ENDIF
ENDPROCEDURE
Write program code for the procedure AddNode().
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[8]
(c) The procedure PrintAll() outputs the data in each element in ArrayNodes, in the order
they are stored in the array.
Each element is printed in a row in the order:
LeftPointer
Data
RightPointer
For example:
1
20
-1
-1
10
-1
Write program code for the procedure PrintAll().
Save your program.
Copy and paste the program code into part 3(c) in the evidence document.
[4]
(d) The main program should loop 10 times, each time calling the procedure AddNode(). It
should then call the procedure PrintAll().
(i)
Edit the main program to perform the actions described.
Save your program.
Copy and paste the program code into part 3(d)(i) in the evidence document.
[3]
(ii)
Test the program by entering the data:
10
5
15
8
12
6
20
11
9
4
Take a screenshot to show the output after the given data are entered.
Copy and paste the screenshot into part 3(d)(ii) in the evidence document.
[1]
(e) An in-order tree traversal visits the left node, then the root (and outputs this), then visits the
right node.
(i)
Write a recursive procedure, InOrder(), to perform an in-order traversal on the tree
held in ArrayNodes.
Save your program.
Copy and paste the program code into part 3(e)(i) in the evidence document.
[7]
(ii)
Test the procedure InOrder() with the same data entered in part (d)(ii).
Take a screenshot to show the output after entering the data.
Copy and paste the screenshot into part 3(e)(ii) in the evidence document.
[1]
Permission to reproduce items where third-party owned material

155
9618/21/M/J/21 · Question 3May/June 2021Paper 2110 marks
Loading question…
Question text

3
(a) A concert venue uses a program to calculate admission prices and store information about
ticket sales.
A number of arrays are used to store data. The computer is switched off overnight and data
has to be input again at the start of each day before any tickets can be sold. This process is
very time consuming.
(i)
Explain how the program could use text files to speed up the process.
…
…
…
…
…
… [2]
(ii)
State the characteristic of text files that allow them to be used as explained in part (a)(i).
…
… [1]
(iii)
Information about ticket sales will be stored as a booking. The booking requires the
following data:
•
name of person booking
•
number of people in the group (for example a family ticket or a school party)
•
event type.
Suggest how data relating to each booking may be stored in a text file.
…
…
…
… [2]
(b) A procedure Preview() will:
•
take the name of a text file as a parameter
•
output a warning message if the file is empty
•
otherwise output the first five lines from the file (or as many lines as there are in the file if
this number is less than five).
Write pseudocode for the procedure Preview().
…
…
…
…
…
…
…
…
…

156
9618/21/M/J/21 · Question 5May/June 2021Paper 218 marks
Loading question…
Question text

5
A global 2D array Result of type INTEGER is used to store a list of exam candidate numbers
together with their marks. The array contains 2000 elements, organised as 1000 rows and
2 columns.
Column 1 contains the candidate number and column 2 contains the mark for the corresponding
candidate. All elements contain valid exam result data.
A procedure Sort() is needed to sort Result into ascending order of mark using an efficient
bubble sort algorithm.
Write pseudocode for the procedure Sort().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

157
9618/21/M/J/21 · Question 6May/June 2021Paper 216 marks
Loading question…
Question text

6
The following diagram represents an Abstract Data Type (ADT) for a linked list.
A
C
D
E
Ø
The free list is as follows:
Ø
(a) Explain how a node containing data value B is added to the list in alphabetic sequence.
…
…
…
…
…
…
… [4]
(b) Describe how the linked list in part (a) may be implemented using variables and arrays.
…
…
…
… [2]

158
9618/22/M/J/21 · Question 3May/June 2021Paper 226 marks
Loading question…
Question text

3
The following diagram represents an Abstract Data Type (ADT).
A
B
Dolphin
Cat
Fish
Elk
(a) Identify this type of ADT.
… [1]
(b) Give the technical term for the item labelled A in the diagram.
… [1]
(c) Give the technical term for the item labelled B in the diagram.
Explain the meaning of the value given to this item.
Term …
Meaning …
…
…
[2]
(d) Complete the diagram to show the ADT after the data has been sorted in alphabetical order.
Dolphin
Cat
Fish
Elk
[2]

Advertisement
159
9618/22/M/J/21 · Question 5May/June 2021Paper 2215 marks
Loading question…
Question text

5
(a) A student is learning about arrays.
She wants to write a program to:
•
declare a 1D array RNum of 100 elements of type INTEGER
•
assign each element a random value in the range 1 to 200 inclusive
•
count and output how many numbers generated were between 66 and 173 inclusive.
(i)
Write pseudocode to represent the algorithm.
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
(ii)
The student decides to modify the algorithm so that each element of the array will contain
a unique value.
Describe the changes that the student needs to make to the algorithm.
…
…
…
…
…
… [3]
(b) The following is a pseudocode function.
Line numbers are given for reference only.
01
FUNCTION StringClean(InString : STRING) RETURNS STRING
02
03
DECLARE NextChar : CHAR
04
DECLARE OutString : STRING
05
DECLARE Counter : INTEGER
06
""
07
OutString
08
1 TO LENGTH(InString)
09
FOR Counter
MID(InString, Counter, 1)
10
NextChar
LCASE(NextChar)
11
NextChar
12
IF NOT((NextChar < 'a') OR (NextChar > 'z')) THEN
OutString & NextChar
13
OutString
14
ENDIF
15
NEXT Counter
16
17
RETURN OutString
18
19
ENDFUNCTION
(i)
Examine the pseudocode and complete the following table.
Answer
Give a line number containing an example of an initialisation statement.
Give a line

160
9618/22/M/J/21 · Question 6May/June 2021Paper 228 marks
Loading question…
Question text

6
A procedure CountVowels() will:
•
be called with a string containing alphanumeric characters as its parameter
•
count and output the number of occurrences of each vowel (a, e, i, o, u) in the string
•
count and output the number of occurrences of the other alphabetic characters (as a single
total).
The string may contain both upper and lower case characters.
Each count value will be stored in a unique element of a global 1D array CharCount of type
INTEGER. The array will contain six elements.
Write pseudocode for the procedure CountVowels().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

161
9618/41/M/J/21 · Question 1May/June 2021Paper 4124 marks
Loading question…
Question text

1
An unordered linked list uses a 1D array to store the data.
Each item in the linked list is of a record type, node, with a field data and a field nextNode.
The current contents of the linked list are:
startPointer
data
nextNode
0
Index
0
1
1
emptyList
5
1
5
4
2
6
7
3
7
-1
4
2
2
5
0
6
6
0
8
7
56
3
8
0
9
9
0
-1
(a) The following is pseudocode for the record type node.
TYPE node
DECLARE data : INTEGER
DECLARE nextNode : INTEGER
ENDTYPE
Write program code to declare the record type node.
Save your program as question1.
Copy and paste the program code into part 1(a) in the evidence document.
[2]
(b) Write program code for the main program.
Declare a 1D array of type node with the identifier linkedList, and initialise it with the data
shown in the table on page 2. Declare the pointers.
Save your program.
Copy and paste the program code into part 1(b) in the evidence document.
[4]
(c) The procedure outputNodes() takes the array and startPointer as parameters. The
procedure outputs the data from the linked list by following the nextNode values.
(i)
Write program code for the procedure outputNodes().
Save your program.
Copy and paste the program code into part 1(c)(i) in the evidence document.
[6]
(ii)
Edit the main program to call the procedure outputNodes().
Take a screenshot to show the output of the procedure outputNodes().
Save your program.
Copy and paste the screenshot into part 1(c)(ii) in the evidence document.
[1]
(d) The function, addNode(), takes the linked list and pointers as parameters, then takes as
input the data to be added to the end of the linkedList.
The function adds the node in the next available space, updates the pointers and returns
True. If there are no empty nodes, it returns False.
(i)
Write program code for the function addNode().
Save your program.
Copy and paste the program code into part 1(d)(i) in the evidence document.
[7]
(ii)
Edit the main program to:
•
call addNode()
•
output an appropriate message depending on the result returned from addNode()
•
call outputNodes() twice; once before calling addNode() and once after calling
addNode().
Save your program.
Copy and paste the program code into part 1(d)(ii) in the evidence document.
[3]
(iii)
Test your program by inputting the data value 5 and take a screenshot to show the
output.
Save your program.
Copy and paste the screenshot into part 1(d)(iii) in the evidence document.
[1]

162
9618/41/M/J/21 · Question 2May/June 2021Paper 4120 marks
Loading question…
Question text

2
A program stores the following ten integers in a 1D array with the identifier arrayData.
10
5
6
7
1
12
13
15
21
8
(a) Write program code for a new program to:
•
declare the global 1D array, arrayData, with ten elements
•
initialise arrayData in the main program using the data values shown.
Save your program as question2.
Copy and paste the program code into part 2(a) in the evidence document.
[2]
(b) (i)
A function, linearSearch(), takes an integer as a parameter and performs a linear
search on arrayData to find the parameter value. It returns True if it was found and
False if it was not found.
Write program code for the function linearSearch().
Save your program.
Copy and paste the program code into part 2(b)(i) in the evidence document.
[6]
(ii)
Edit the main program to:
•
allow the user to input an integer value
•
pass the value to linearSearch() as the parameter
•
output an appropriate message to tell the user whether the search value was found
or not.
Save your program.
Copy and paste the program code into part 2(b)(ii) in the evidence document.
[4]
(iii)
Test your program with one value that is in the array and one value that is not in the
array.
Take a screenshot to show the result of each test.
Save your program.
Copy and paste the screenshots into part 2(b)(iii) in the evidence document.
[2]
(c) The following bubble sort pseudocode algorithm sorts the data in theArray into descending
numerical order. There are five incomplete statements.
PROCEDURE bubbleSort()
DECLARE temp : INTEGER
0 to …
FOR x
0 to …
FOR y
IF theArray[y] … theArray[y + 1] THEN
theArray[y]
temp
…
theArray[y]
…
theArray[y + 1]
ENDIF
NEXT y
NEXT x
ENDPROCEDURE
Write program code for the procedure bubbleSort() to sort the data in arrayData into
descending order.
Save your program.
Copy and paste the program code into part 2(c) in the evidence document.
[6]

Advertisement