Data types, arrays and files – A Level Computer Science (old syllabus, to 2021) (9608)

24 questions · page 1 of 2 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
1
9608/41/O/N/21 · Question 1Oct/Nov 2021Paper 4137 marks
Loading question…
Question text

1
Sandy is writing a program to process data in a stack. The stack is implemented as a 1D array,
DataStack, which has up to 100 elements.
The function Push(Value) stores Value on the stack and returns TRUE if Value was added to
the stack, or FALSE if the stack is full.
The function Pop() returns the item at the top of the stack, or returns –1 if the stack is empty.
DataStack and TopPointer are declared as global.
(a) Show the state of DataStack and its pointer after the following functions are executed on
the current contents.
Pop()
Pop()
Push(19)
Pop()
Push(50)
TopPointer
Index
Data
3
[7]
[6]
[5]
[4]
[3]
8
[2]
6
[1]
20
[0]
10
[2]
(b) Write program code for the function Pop().
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
… [5]
(c) Sandy has also used a queue in her program.
Describe the ways in which a queue differs from a stack.
…
…
…
…
…
… [2]

2
9608/41/O/N/21 · Question 3Oct/Nov 2021Paper 416 marks
Loading question…
Question text

3
The following pseudocode algorithm performs a binary search on the sorted array ThisArray.
The algorithm returns either the location of SearchItem in the array, or –1 if SearchItem is not
in the array.
The function DIV returns the integer value of the division, for example, 11 DIV 2 returns 5.
Complete the algorithm by writing the missing pseudocode statements.
FUNCTION BinarySearch(ThisArray[], LowerBound, UpperBound,
SearchItem : INTEGER) RETURNS INTEGER
DECLARE Flag : BOOLEAN
DECLARE Mid : INTEGER
-2
Flag
WHILE Flag <> -1
LowerBound + ((UpperBound – LowerBound) DIV 2)
Mid
IF … < …
THEN
RETURN …
ELSE
IF ThisArray[Mid] > SearchItem
THEN
Mid …
UpperBound
ELSE
IF ThisArray[Mid] < SearchItem
THEN
Mid …
LowerBound
ELSE
RETURN …
ENDIF
ENDIF
ENDIF
ENDWHILE
ENDFUNCTION
[6]

3
9608/41/O/N/21 · Question 6Oct/Nov 2021Paper 4115 marks
Loading question…
Question text

6
Kobi is writing an application that uses a record structure to store data.
(a) (i)
Describe what is meant by a record structure.
…
…
…
… [2]
(ii)
The record structure stores the unique ID number (a whole number), first name and last
name of a customer.
Write a pseudocode declaration for the record structure CustomerData.
…
…
…
…
…
…
… [2]
(b) Kobi’s application stores the records in a random access file.
The function StoreRecord():
•
takes a customer record as a parameter
•
uses the function CustomerHash() to calculate and return the hash value for its
parameter
•
stores the customer record in the returned hash value address.
Assume there are no collisions.
Complete the following pseudocode algorithm to write a new record to the random access file.
PROCEDURE
StoreRecord(NewData : … )
CustomerHash(NewData.CustomerID)
HashValue
"CustomerRecords.dat"
Filename
OPENFILE Filename FOR …
SEEK Filename, …
PUTRECORD Filename, …
… Filename
[5]
ENDPROCEDURE
(c) Identify two typical features of a debugger and describe how Kobi could use each one during
the development of the application.
Feature 1 …
…
…
…
Feature 2 …
…
…
…
[4]
(d) Give one benefit and one drawback of Kobi using a program generator whilst deve

Advertisement
4
9608/41/O/N/21 · Question 8Oct/Nov 2021Paper 4162 marks
Loading question…
Question text

8
Data entered into a computer is stored in an ordered binary tree.
The binary tree is stored in a 2D array, BinaryTree.
The first element of the array is index 0.
(a) The current contents of the binary tree are:
50
35
67
2
43
52
77
Complete the LeftPointer and RightPointer values in the following table for the binary
tree shown.
A null pointer is represented by –1.
RootNode
Index
LeftPointer
Data
RightPointer
0
[0]
50
[1]
67
[2]
77
[3]
35
[4]
2
[5]
43
[6]
52
[7]
[8]
[9]
[10]
[2]
(b) A post-order tree traversal outputs the left node, then the right node, then the root node.
In the tree given in part (a), the post-order tree traversal would output:
2
43
35
52
77
67
50
Complete the following recursive pseudocode algorithm PostOrder().
PROCEDURE PostOrder( … : INTEGER)
IF BinaryTree[RootNode, 0] <> -1
THEN
… (BinaryTree[RootNode, … ])
ENDIF
IF BinaryTree[RootNode, 2] <> -1
THEN
… (BinaryTree[RootNode, 2])
ENDIF
OUTPUT BinaryTree[RootNode, … ]
ENDPROCEDURE
[5]

5
9608/41/O/N/21 · Question 9Oct/Nov 2021Paper 4110 marks
Loading question…
Question text

9
A program uses a hashing algorithm to store data in the global array, StoredData.
The first element of the array is index 0. The array has 10 000 integer elements.
(a) Write a pseudocode declaration for the array StoredData and initialise each element to –1.
…
…
…
… [3]
(b) The hashing algorithm calculates the remainder after dividing the data by 1000, and then
adds 6 to it.
The function AddItem() takes the data as a parameter. It calculates the index to store the
data using the hashing algorithm.
If there is a collision, the function:
•
checks the next index until it finds an index that does not have data in it
•
continues to search from the start of the array, if it reaches the end of the array.
The function returns TRUE if the item was successfully added, and FALSE if the array is full.
Write program code for the function AddItem().
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

6
9608/42/O/N/21 · Question 1Oct/Nov 2021Paper 429 marks
Loading question…
Question text

1
An array, NumberArray, stores 100 integer values. The array needs to be sorted into ascending
numerical order.
(a) Describe how an insertion sort will sort the data in NumberArray.
…
…
…
…
…
…
…
…
…
… [4]
(b) Another type of sorting algorithm is a bubble sort.
The procedure Bubble() takes an array as a parameter. It performs a bubble sort on the
array. The sorting algorithm stops as soon as all the elements are in ascending order.
Complete the procedure Bubble().
PROCEDURE Bubble(BYREF NumberArray : ARRAY[0 : 99] OF INTEGER)
DECLARE Outer : INTEGER
DECLARE Swap : BOOLEAN
DECLARE Inner : INTEGER
DECLARE Temp : INTEGER
LENGTH(NumberArray) - 1
Outer
REPEAT
…
Inner
FALSE
Swap
REPEAT
IF NumberArray[Inner] > NumberArray[Inner + 1]
THEN
NumberArray[Inner]
Temp
NumberArray[Inner + 1]
NumberArray[Inner]
Temp
NumberArray[Inner + 1]
…
Swap
ENDIF
Inner + 1
Inner
UNTIL Inner = …
Outer - 1
Outer
UNTIL Swap = … OR Outer = …
ENDPROCEDURE
[5]

7
9608/42/O/N/21 · Question 4Oct/Nov 2021Paper 4242 marks
Loading question…
Question text

4
Each node of a binary tree is a record. Each record has a left pointer, an integer data value
between 0 and 100 inclusive, and a right pointer.
For example:
Item
Example data
LeftPointer
2
Data
34
RightPointer
3
(a) Write pseudocode to declare the record with the identifier Node.
…
…
…
…
…
…
… [2]
(b) Write pseudocode to declare a new node, Node100, and assign 100 to its data value, 1 to
the left pointer and 4 to the right pointer.
…
…
…
…
…
…
… [3]
(c) The ordered binary tree is stored as a 1D global array named BinaryTree of type Node.
RootNode and FreePointer are declared as global variables.
A null pointer is represented by –1.
The current state of the binary tree is shown in the following table:
RootNode
Index
LeftPointer
Data
RightPointer
0
[0]
1
23
3
FreePointer
6
[1]
-1
5
2
[2]
-1
8
4
[3]
5
100
-1
[4]
-1
9
-1
[5]
-1
88
-1
[6]
-1
null
-1
[7]
-1
null
-1
(i)
State the purpose of the free pointer.
…
… [1]
(ii)
Identify an appropriate integer value to represent null data.
… [1]
(iii)
Draw the current state of the binary tree.
[2]
(iv)
The procedure AddData():
•
takes the node to be added to the tree as a parameter
•
finds the location for the node to be stored
•
stores the node in the next free array index
•
stores –1 in the new node’s LeftPointer and RightPointer
•
updates the pointers in the other nodes
•
updates FreePointer.
Complete the pseudocode for the procedure AddData().
PROCEDURE AddData(NewNode)
…
BinaryTree[FreePointer]
BinaryTree[FreePoi

8
9608/42/O/N/21 · Question 6Oct/Nov 2021Paper 4216 marks
Loading question…
Question text

6
Details of errors generated in a program are stored in a stack.
Details of each error are stored in a record structure, Error.
(a) State which error will be the first retrieved from the stack.
…
… [1]
(b) The stack is implemented as a 1D array with the identifier ErrorArray.
The pointer LastItem stores the position of the last error in the array.
(i)
The function, AddItemToStack, takes the next error, the array, and pointer as
parameters.
If the stack is full, the function returns FALSE; otherwise it adds the error to the stack,
changes the pointer’s value and returns TRUE.
Complete the following pseudocode for the function AddItemToStack.
FUNCTION AddItemToStack(BYREF ErrorArray : ARRAY[0 : 99] OF Error,
BYREF LastItem : INTEGER,
BYVALUE Error1 : Error) RETURNS BOOLEAN
IF LastItem = …
THEN
RETURN …
ELSE
…
ErrorArray[LastItem + 1]
…
LastItem
RETURN …
ENDIF
ENDFUNCTION
[4]
(ii)
Explain the reasons why ErrorArray and LastItem are passed by reference, but
Error1 is passed by value.
…
…
…
…
…
… [3]
(iii)
The function RemoveItem takes the next error from the stack and returns it.
If there are no errors in the stack, it returns the global record NullError.
Complete the pseudocode algorithm RemoveItem.
FUNCTION RemoveItem(BYREF ErrorArray : ARRAY[0 : 99] OF Error,
BYREF LastItem : INTEGER) RETURNS Error
DECLARE ItemToRemove : Error
IF …
THEN
RETURN …
ELSE
ErrorArray[ … ]
ItemToRemove
LastItem - 1
LastItem
RETURN …
ENDFUNCTION
[3]
(iv)
The errors that have been processed are stored in a global queue, ErrorComplete.
The function Enqueue adds a record to ErrorComplete:
Enqueue(ErrorToAdd)
Enqueue() returns TRUE if the record is successfully added to the queue, and returns
FALSE if the queue is full.
The procedure RunError() should:
•
remove a record from the stack using the function RemoveItem()
•
output an appropriate message if there were no records in the stack
•
if an error record is returned, add the record to the queue using the function
Enqueue()
•
if the record is added to the queue, output an appropriate message
•
if the record is not added to the queue, output an appropriate message.
Complete the pseudocode procedure RunError().
PROCEDURE RunError(BYREF ErrorComplete : ARRAY[0 : 99] OF Error,
BYREF ErrorArray : ARRAY[0 : 99] OF Error)
…
…

Advertisement
9
9608/41/O/N/20 · Question 6Oct/Nov 2020Paper 4116 marks
Loading question…
Question text

6
Consider the following diagram that represents a linked list:
Data
Pointer
A
B
C
D
Ø
The symbol Ø represents a null pointer.
(a) A new node with the data value E is added between the nodes that have the data values B
and C.
Show the state of the linked list after the node with the data value E is added.
[2]
(b) State why the node with the data value D has a null pointer.
…
… [1]
(c) A 1D array, LinkedList, is used to implement the linked list. The array is declared as a
record data type with two fields, Data and Pointer.
The global variable StartPointer stores the index of the first node in the list.
(i)
The following pseudocode algorithm finds a value in a linked list. The algorithm is
incomplete.
The function FindValue(), takes as a parameter, the value to be searched for in the
linked list. The function follows the pointers in the linked list. It either returns -1 if the
value is not found, or it returns the pointer to the value if it is found.
Complete the algorithm.
FUNCTION FindValue(Value : INTEGER) …
DECLARE CurrentPointer : INTEGER
StartPointer
CurrentPointer
WHILE … <> NULL
AND LinkedList[CurrentPointer]. … <> …
LinkedList[ … ].Pointer
CurrentPointer
ENDWHILE
IF LinkedList[CurrentPointer].Data = Value
THEN
RETURN …
ELSE
RETURN -1
ENDIF
ENDFUNCTION
[6]
(ii)
The function DeleteNode() takes the data to be removed from LinkedList as a
parameter.
The function starts at the first node and follows the pointers to check the data in each
node.
If the data is found, it removes the node containing that data, updates the pointer and
returns TRUE. Otherwise, it returns FALSE.
Write pseudocode for DeleteNode().
…
…
…
…
…
…
…
…
…
…
…
…
…
…

10
9608/41/O/N/20 · Question 7Oct/Nov 2020Paper 418 marks
Loading question…
Question text

7
The following table shows part of the instruction set for a processor that has one general purpose
register, the Accumulator (ACC), and an Index Register (IX).
Instruction
Explanation
Op code
Operand
LDM
#n
Immediate addressing. Load the number n to ACC.
Direct addressing. Load the contents of the location at the given
LDD
<address>
address to ACC.
Indirect addressing. The address to be used is at the given address.
LDI
<address>
Load the contents of this second address to ACC.
Indexed addressing. Form the address from <address> + the contents
LDX
<address>
of the Index Register. Copy the contents of this calculated address to
ACC.
LDR
#n
Immediate addressing. Load the number n to IX.
STO
<address>
Store the contents of ACC at the given address.
Indexed addressing. Form the address from <address> + the contents
STX
<address>
of the Index Register. Copy the contents of ACC to this calculated
address.
ADD
<address>
Add the contents of the given address to ACC.
INC
<register>
Add 1 to the contents of the register (ACC or IX).
DEC
<register>
Subtract 1 from the contents of the register (ACC or IX).
JMP
<address>
Jump to the given address.
CMP
<address>
Compare the contents of ACC with the contents of <address>.
CMP
#n
Compare the contents of ACC with number n.
Following a compare instruction, jump to <address> if the compare
JPE
<address>
was True.
Following a compare instruction, jump to <address> if the compare
JPN
<address>
was False.
IN
Key in a character and store its ASCII value in ACC.
OUT
Output to the screen the character whose ASCII value is stored in ACC.
END
Return control to the operating system.
The assembly language program in the table on the opposite page allows a username to be input
as a string of up to 8 characters in length.
For strings of less than 8 characters, the user enters the exclamation mark (!) character to
indicate that no more characters will be entered. The exclamation mark is not saved as part of the
username.
The program then outputs each character of the username in the order input.
The program will use consecutive memory locations, starting at the address labelled USERNAME,
storing one character in each location.
The program in the table is incomplete. The comment column contains descriptions for some
program instructions.
Complete the program using the given instruction set.
Instruction
Label
Comment
Op code
Operand
LDR
#0
LDM
#0
// initialise LENGTH to 0
STO
LENGTH
LOOP:
IN
// is character = EXCLAMATION(!)?
// if TRUE, jump to OUTPUT
// store character in USERNAME +
contents of IX
INC
IX
// increment Index Register
// increment LENGTH
// is LENGTH = MAX ?
// if FALSE, jump to LOOP
OUTPUT:
LDR
#0
// initialise COUNT to 0
LDX
USERNAME
OUT
INC
IX
LDD
COUNT
INC
ACC
// increment COUNT
STO
COUNT
// is COUNT = LENGTH ?
JPN
OUTPUT
END
// end program
LENGTH:
EXCLAMATION:
B0010001
MAX:
8
COUNT:
USERNAME:
[8]

11
9608/42/O/N/20 · Question 1Oct/Nov 2020Paper 4212 marks
Loading question…
Question text

1
There are several different searching and sorting algorithms.
(a) Identify two sorting algorithms.
1 …
2 …
[2]
(b) Consider the following pseudocode algorithm.
0
LowerBound
LengthOfList – 1
UpperBound
FALSE
ValueFound
OUTPUT "Value to find: "
INPUT ValueToFind
WHILE ValueFound = FALSE AND UpperBound <> LowerBound
(LowerBound + UpperBound)DIV 2
MidPoint
IF List[MidPoint] = ValueToFind
THEN
TRUE
ValueFound
ELSE
IF List[MidPoint] < ValueToFind
THEN
MidPoint + 1
LowerBound
ELSE
MidPoint – 1
UpperBound
ENDIF
ENDIF
ENDWHILE
IF ValueFound = FALSE
THEN
(LowerBound + UpperBound) DIV 2
MidPoint
IF List[MidPoint] = ValueToFind
THEN
OUTPUT "Item in position " & MidPoint & " in list"
ELSE
OUTPUT "Not in list"
ENDIF
ELSE
OUTPUT "Item in position " & MidPoint & " in list"
ENDIF
Note: DIV is an operator that performs integer division.
The array List contains the following values:
2, 5, 21, 25, 36, 48, 51, 59, 65, 70
(i)
Complete the trace table to show a dry run of the algorithm, when the value 21 is input.
LowerBound
UpperBound
ValueFound
ValueToFind
MidPoint
[3]
(ii)
Identify this type of searching algorithm.
… [1]
(iii)
The value 59 is input.
State the number of times the while loop condition is executed.
… [1]
(iv)
State the minimum number of times the while loop condition will be executed to search
for a value.
… [1]
(v)
MidPoint is calculated and checked again after the while loop is terminated.
Explain why this additional calculation and check is necessary.
…
…
…
… [2]
(vi)
A new data set is used as follows:
5, 9, 10, 12, 15, 13, 17, 19, 20, 2
Explain why the algorithm will not find the value 2 in this data set.
…
…
…
… [2]

12
9608/42/O/N/20 · Question 5Oct/Nov 2020Paper 428 marks
Loading question…
Question text

5
The following table shows part of the instruction set for a processor that has one general purpose
register, the Accumulator (ACC), and an Index Register (IX).
Instruction
Explanation
Op code
Operand
LDM
#n
Immediate addressing. Load the number n to ACC.
Direct addressing. Load the contents of the location at the given
LDD
<address>
address to ACC.
Indirect addressing. The address to be used is at the given address.
LDI
<address>
Load the contents of this second address to ACC.
Indexed addressing. Form the address from <address> + the contents
LDX
<address>
of the Index Register. Copy the contents of this calculated address to
ACC.
LDR
#n
Immediate addressing. Load the number n to IX.
STO
<address>
Store the contents of ACC at the given address.
Indexed addressing. Form the address from <address> + the contents
STX
<address>
of the Index Register. Copy the contents of ACC to this calculated
address.
ADD
<address>
Add the contents of the given address to ACC.
INC
<register>
Add 1 to the contents of the register (ACC or IX).
DEC
<register>
Subtract 1 from the contents of the register (ACC or IX).
JMP
<address>
Jump to the given address.
CMP
<address>
Compare the contents of ACC with the contents of <address>.
CMP
#n
Compare the contents of ACC with number n.
Following a compare instruction, jump to <address> if the compare
JPE
<address>
was True.
Following a compare instruction, jump to <address> if the compare
JPN
<address>
was False.
IN
Key in a character and store its ASCII value in ACC.
OUT
Output to the screen the character whose ASCII value is stored in ACC.
END
Return control to the operating system.
Consider the following pseudocode algorithm:
0
Length
INPUT Character
WHILE Character <> "."
Message
Message & Character
Length
Length + 1
INPUT Character
ENDWHILE
Complete the table by writing assembly language code for the algorithm, using the given instruction
set.
Instruction
Label
Comment
Op code
Operand
// initialise IX to zero
// initialise LENGTH
LOOP:
// input character
// is character a FULLSTOP (.) ?
// jump to ENDP if TRUE
// store character in MESSAGE +
contents of IX
// increment IX
// increment LENGTH
// jump to LOOP
ENDP:
END
// end program
LENGTH:
FULLSTOP:
B01100000
// ASCII code for a full stop (.)
MESSAGE:
[8]

13
9608/42/O/N/20 · Question 6Oct/Nov 2020Paper 4216 marks
Loading question…
Question text

6
The following diagram represents a linked list.
Data
Pointer
A
B
C
D
Ø
The symbol Ø represents a null pointer.
(a) The node with the data value C is removed from the list.
Show the new state of the linked list.
[2]
(b) State what happens to the node with the data value C when it is removed from the list.
…
… [1]
(c) State what is meant by a null pointer.
… [1]
(d) The linked list is implemented as a 1D array, LinkedList. The array is declared as a record
data type, with two fields, Data and Pointer.
The function FindValue() takes as a parameter, the value to be searched for in the linked
list. The function follows the pointers in the linked list. It returns -1 if the value is not found, or
it returns the pointer to the value if it is found.
The global variable StartPointer points to the first element in the list.
Write pseudocode for the function FindValue().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [8]
9608/42/O/N/

Advertisement
14
9608/41/O/N/19 · Question 1Oct/Nov 2019Paper 4160 marks
Loading question…
Question text

1
Each student at CIE University needs a printing account to print documents from university
computers.
The university is developing software to manage each student’s printing account and the printing
process.
(a) Developing the software will include the following activities.
Time in
Activity
Description
Predecessor
weeks
A
Identify requirements
1
-
B
Produce design
3
A
C
Write code
10
B
D
Test modules
7
B
E
Final system black-box testing
3
C, D
F
Install software
1
E
G
Acceptance testing
2
F
H
Create user documentation
2
F
(i)
Add the correct activities and times to the following Program Evaluation Review
Technique (PERT) chart for the software development.
Two activities and times have been done for you.
4
A
1
2
3
5
6
1
1
F
7
8
9
[6]
(ii)
State what is meant by the critical path in a PERT chart.
…
… [1]
(iii)
Identify and describe a project planning technique, other than a PERT chart.
…
…
…
… [2]
(b) When a student prints a document, a print job is created. The print job is sent to a print server.
The print server uses a queue to hold each print job waiting to be printed.
(i)
The queue is circular and has six spaces to hold jobs.
The queue currently holds four jobs waiting to be printed. The jobs have arrived in the
order A, B, D, C.
Complete the diagram to show the current contents of the queue.
Start Pointer
End Pointer
[1]
(ii)
Print jobs A and B are now complete. Four more print jobs have arrived in the
order E, F, G, H.
Complete the diagram to show the current contents and pointers for the queue.
[3]
(iii)
State what would happen if another print job is added to the queue in the status
in part (b)(ii).
…
… [1]
(iv)
The queue is stored as an array, Queue, with six elements. The following algorithm
removes a print job from the queue and returns it.
Complete the following pseudocode for the function Remove.
FUNCTION Remove RETURNS STRING
DECLARE PrintJob : STRING
IF … = EndPointer
THEN
RETURN "Empty"
ELSE
PrintJob
Queue[ … ]
IF StartPointer = …
THEN
…
StartPointer
ELSE
StartPointer
StartPointer + 1
ENDIF
RETURN PrintJob
ENDIF
ENDFUNCTION
[4]
(v)
Explain why the circular queue could not be implemented as a stack.
…
…
…

15
9608/42/O/N/19 · Question 2Oct/Nov 2019Paper 4212 marks
Loading question…
Question text

2
The number of cars that cross a bridge is recorded each hour. This number is placed in a circular
queue before being processed.
(a) The queue is stored as an array, NumberQueue, with eight elements. The function
AddToQueue adds a number to the queue. EndPointer and StartPointer are global
variables.
Complete the following pseudocode algorithm for the function AddToQueue.
FUNCTION AddToQueue(Number : INTEGER) RETURNS BOOLEAN
DECLARE TempPointer : INTEGER
CONSTANT FirstIndex = 0
CONSTANT LastIndex = …
EndPointer + 1
TempPointer
IF … > LastIndex
THEN
…
TempPointer
ENDIF
IF TempPointer = StartPointer
THEN
RETURN …
ELSE
TempPointer
EndPointer
…
NumberQueue[EndPointer]
RETURN TRUE
ENDIF
ENDFUNCTION
[5]
(b) Describe how a number is removed from the circular queue to be processed.
…
…
…
…
…
…
…
… [4]
(c) A queue is one example of an Abstract Data Type (ADT).
Identify three other Abstract Data Types.
1 …
2 …
3 …
[3]

Advertisement