Data types, arrays and files – A Level Computer Science (old syllabus, to 2021) (9608)
48 questions · page 3 of 4 · Clear filters
Question text
6
An Abstract Data Type (ADT) is used to create a linked list. The linked list is created as an array of
records. The records are of type ListNode.
An example of a record of ListNode is shown in the following table.
Data Field
Value
Player
"Alvaro"
Pointer
1
(a) (i)
Use pseudocode to write a definition for the record type, ListNode.
…
…
…
…
… [3]
(ii)
An array, Scorers, will hold 10 nodes of type ListNode. Use pseudocode to write an
array declaration for this array. The lower bound subscript is 0.
… [2]
(b) The linked list stores ListNode records in alphabetical order of player. The last node in the
linked list always has a Pointer value of –1. The position of the first node in the linked list is
held in the variable ListHead.
After some processing, the array and variables are in the state as follows:
Scorers
ListHead
Player
Pointer
0
0
"Alvaro"
1
1
"Antoine"
3
2
"Dimitri"
7
3 "Cristiano"
2
4
"Gareth"
5
5
"Graziano"
6
6
"Olivier"
8
7
"Erik"
4
8
"Yaya"
9
9
"Zoto"
-1
A recursive function traverses the linked list to search for a player.
An example of calling the function, using pseudocode, is:
SearchList("Gareth", ListHead)
Position
Complete the following pseudocode to implement the function SearchList().
The function will return a value of 99 when a player is not found.
FUNCTION SearchList(Find : STRING, Position : INTEGER) RETURNS INTEGER
IF Scorer[Position].Player = …
THEN
RETURN …
ELSE
IF Scorer[Position].Pointer <> –1
THEN
SearchList(Find, … )
Position
RETURN …
ELSE
RETURN …
ENDIF
ENDIF
ENDFUNCTION
[5]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Question text
3
The arrays PollData[1:10] and CardData[1:10] store data.
PollData
12
85
52
57
25
11
33
59
56
91
CardData
11
12
25
33
52
56
57
59
91
85
An insertion sort sorts these data.
(a) State why it will take less time to complete an insertion sort on CardData than on PollData.
…
… [1]
(b) The following pseudocode algorithm performs an insertion sort on the CardData array.
Complete the following pseudocode algorithm.
01
ArraySize ← 10
FOR Pointer ← 2 TO …
02
03
ValueToInsert ← CardData[Pointer]
HolePosition ← …
04
WHILE (HolePosition > 1 AND ( … > … ))
05
CardData[HolePosition] ← CardData[ … ]
06
HolePosition ← …
07
08
ENDWHILE
CardData[HolePosition] ← …
09
10
ENDFOR
[7]
(c) (i)
A binary search algorithm is used to find a specific value in an array.
Explain why an array needs to be sorted before a binary search algorithm can be used.
…
…
…
…
…
…
…
… [2]
(ii)
The current contents of CardData are shown.
11
12
25
33
52
56
57
59
85
91
Explain how a binary search will find the value 25 in CardData.
…
…
…
…
…
…
…
…
Question text
6
An Abstract Data Type (ADT) is used to create an unordered binary tree. The binary tree is created
as an array of nodes. Each node consists of a data value and two pointers.
A record type, Node, is declared using pseudocode.
TYPE Node
DECLARE DataValue : STRING
DECLARE LeftPointer : INTEGER
DECLARE RightPointer : INTEGER
ENDTYPE
The following statement declares an array BinaryTree.
DECLARE BinaryTree : ARRAY[0:14] OF Node
A variable, NextNode, points to the next free node.
The following diagram shows a possible node.
ArrayIndex
DataValue
LeftPointer
RightPointer
0
"Red"
1
2
The commands in the following table create and add nodes to the binary tree.
Command
Comment
CreateTree(NodeData)
Sets NextNode to 0.
Writes NodeData into DataValue at the position NextNode
Updates NextNode using NextNode = NextNode + 1
AttachLeft(NodeData, ParentNode)
Writes NodeData into DataValue of NextNode
Sets the LeftPointer of node ParentNode to NextNode
Updates NextNode using NextNode = NextNode + 1
AttachRight(NodeData, ParentNode)
Writes NodeData into DataValue of NextNode
Sets the RightPointer of node ParentNode to NextNode
Updates NextNode using NextNode = NextNode + 1
(a) The following commands are executed.
CreateTree("Red")
AttachLeft("Blue", 0)
AttachRight("Green", 0)
The following diagram shows the current state of the binary tree.
0
"Red"
1
2
1
"Blue"
2 "Green"
…
…
…
…
…
…
…
…
…
…
…
…
Write on the diagram to show the state of the binary tree after the following commands have
been executed.
AttachRight("Black", 2)
AttachLeft("Brown", 2)
AttachLeft("Peach", 3)
AttachLeft("Yellow", 1)
AttachRight("Purple", 1)
AttachLeft("White", 6)
AttachLeft("Pink", 7)
AttachLeft("Grey", 9)
AttachRight("Orange", 9)
[5]
(b) A new command has been added to initialise the pointers of the binary tree to − 1 to indicate
they are not in use.
A leaf is a node of the binary tree which has no children. In the case of this binary tree, a node
with a LeftPointer of − 1 and a RightPointer of − 1 is a leaf.
Write a recursive function, in program code, to traverse the binary tree and output the value
of DataValue for each leaf node.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…
Question text
4
(a) The array Numbers[0 : Max] stores numbers. An insertion sort can be used to sort these
numbers into ascending order.
Complete the following pseudocode for the insertion sort algorithm.
1 TO (Max - 1)
FOR Pointer
…
ItemToInsert
…
CurrentItem
WHILE (CurrentItem > 0) AND (Numbers[CurrentItem – 1] > ItemToInsert)
Numbers[CurrentItem - 1]
Numbers[ … ]
CurrentItem – 1
CurrentItem
ENDWHILE
…
Numbers[CurrentItem]
ENDFOR
[4]
(b) Identify two features of the array Numbers that would have an impact on the performance of
this insertion sort algorithm.
1 …
2 …
[2]
Question text
5
The following table shows part of the instruction set for a processor. The processor 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.
LDD
<address>
Direct addressing. Load the contents of the location at the given
address to ACC.
LDI
<address>
Indirect addressing. The address to be used is at the given
address. Load the contents of this second address to ACC.
LDX
<address>
Indexed addressing. Form the address from <address> + the
contents 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.
STX
<address>
Indexed addressing. Form the address from <address> + the
contents of the index register. Copy the contents from ACC to this
calculated address.
ADD
<address>
Add the contents of the given address to the 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.
JPE
<address>
Following a compare instruction, jump to <address> if the compare
was True.
JPN
<address>
Following a compare instruction, jump to <address> if the compare
was False.
LSL
#n
Bits in ACC are shifted n places to the left. Zeros are introduced
on the right hand end.
LSR
#n
Bits in ACC are shifted n places to the right. Zeros are introduced
on the left hand end.
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.
(a) Six letters are stored, starting at the location labelled LETTERS. A program is needed to
perform a linear search on LETTERS to find the letter 'x'. The program counts the number of
times 'x' appears in LETTERS.
The following is the pseudocode for the program.
0 TO 5
FOR COUNT
IF LETTERS[COUNT] = LETTERTOFIND
THEN
FOUND + 1
FOUND
ENDIF
ENDFOR
Write this program. Use the op codes from the given instruction set.
Label
Op code
Operand
Comment
START:
LDR
#0
// initialise Index Register
LOOP:
// load LETTERS
// is LETTERS = LETTERTOFIND ?
// if not, go to NOTFOUND
// increment FOUND
NOTFOUND:
// increment COUNT
// is COUNT = 6 ?
// if yes, end
// increment Index Register
// go back to beginning of loop
ENDP:
END
// end program
LETTERTOFIND:
'x'
LETTERS:
'd'
'u'
'p'
'l'
'e'
'x'
COUNT:
0
FOUND:
0
[10]
(b) Six values are stored, starting at the location VALUES. A program is needed to divide each of
the values by 8 and store them back in their original location.
Write this program. Use the op codes from the instruction set on the next page.
Label
Op code
Operand
Comment
START:
// initialise the Index Register
// load the value from VALUES
// divide by 8
// store the new value in VALUES
// increment the Index Register
// increment REPS
// is REPS = 6 ?
// repeat for next value
END
REPS:
0
VALUES:
22
13
5
46
12
33
[10]
Instruction
Explanation
Op code
Operand
LDM
#n
Immediate addressing. Load the number n to ACC.
LDD
<address>
Direct addressing. Load the contents of the location at the given
address to ACC.
LDI
<address>
Indirect addressing. The address to be used is at the given
address. Load the contents of this second address to ACC.
LDX
<address>
Indexed addressing. Form the address from <address> + the
contents 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.
STX
<address>
Indexed addressing. Form the address from <address> + the
contents of the index register. Copy the contents from ACC to this
calculated address.
ADD
<addre
Question text
1
The following table shows part of the instruction set for a processor which has one general purpose
register, the Accumulator (ACC), and an Index Register (IX).
Instruction
Explanation
Op
Operand
code
Immediate addressing. Load the number n to ACC.
LDM
#n
Direct addressing. Load the contents of the location at the given address
LDD
<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 of
LDX
<address>
the index register. Copy the contents of this calculated address to ACC.
Store the contents of ACC at the given address.
STO
<address>
Add 1 to the contents of the register (ACC or IX).
INC
<register>
Subtract 1 from the contents of the register (ACC or IX).
DEC
<register>
Compare the contents of ACC with the contents of <address>.
CMP
<address>
Jump to given address.
JMP
<address>
Following a compare instruction, jump to <address> if the compare was
JPE
<address>
True.
Following a compare instruction, jump to <address> if the compare was
JPN
<address>
False.
Bitwise AND operation of the contents of ACC with the contents of
AND
<address>
<address>.
Bitwise XOR operation of the contents of ACC with the contents of
XOR
<address>
<address>.
Bitwise OR operation of the contents of ACC with the contents of
OR
<address>
<address>.
Key in a character and store its ASCII value in ACC.
IN
Output to the screen the character whose ASCII value is stored in ACC.
OUT
Return control to the operating system.
END
(a) A programmer writes a program that:
•
reads a character from the keyboard (assume it will be a capital letter)
•
outputs the alphabetical sequence of characters from ‘A’ to the character input. For
example, if the character ‘G’ is input, the output is:
ABCDEFG
The programmer has started to write the program in the table on the following page. The
Comment column contains descriptions for the missing instructions, labels and data.
Complete the following program. Use op codes from the given instruction set.
Label
Op code
Operand
Comment
START:
// INPUT character
// store in CHAR
// Initialise ACC (ASCII value for 'A' is 65)
// OUTPUT ACC
// compare ACC with CHAR
// if equal jump to end of FOR loop
// increment ACC
// jump to LOOP
ENDFOR:
END
CHAR:
[8]
(b) The programmer now starts to write a program that:
•
tests whether an 8-bit two’s complement integer stored at address NUMBER is positive or
negative
•
outputs 'P' for a positive integer and 'N' for a negative integer.
Complete the following program. Use op codes from the given instruction set.
Show the required value of MASK in binary.
Label
Op code
Operand
Comment
START:
MASK
// set to zero all bits except sign bit
// compare with 0
// if not equal jump to ELSE
THEN:
// load ACC with 'P' (ASCII value 80)
JMP
ENDIF
ELSE:
// load ACC with 'N' (ASCII value 78)
ENDIF:
END
NUMBER:
B00000101
// integer to be tested
MASK:
// value of mask in binary
[7]
Question text
2
A hash table has these associated operations:
•
create hash table
•
insert record
•
search hash table
A hash table is to be used to store customer records.
Each record consists of a unique customer ID, the record key, and other customer data.
(a) The following pseudocode declares a customer record structure.
TYPE CustomerRecord
CustomerID : INTEGER
Data : STRING
ENDTYPE
The hash table is to be implemented as a 1D array Customer with elements indexed
0 to 199. The procedure to create a hash table will declare and initialise the array by storing
200 records with the CustomerID field in each record set to 0.
Complete the pseudocode.
PROCEDURE CreateHashTable()
…
…
…
…
[4]
ENDPROCEDURE
(b) A hashing function Hash exists, which takes as a parameter the customer ID and returns an
integer in the range 0 to 199 inclusive.
(i)
The procedure, InsertRecord, takes as a parameter the customer record to be
inserted into the hash table.
The procedure makes use of the function Hash. Collisions will be managed using open
hashing. This means a collision is resolved by storing the record in the next available
location. The procedure will generate an error message if the hash table is full.
Complete the pseudocode for the procedure.
PROCEDURE InsertRecord(BYVALUE NewCustomer : CustomerRecord)
FALSE
TableFull
// generate hash value
…
Index
Index
// initialise Pointer variable to hash value
Pointer
// find a free table element
WHILE …
…
Pointer
// wrap back to beginning of table if necessary
IF …
THEN
…
ENDIF
// check if back to original index
IF …
THEN
TRUE
TableFull
ENDIF
ENDWHILE
IF …
THEN
…
ELSE
…
ENDIF
[9]
ENDPROCEDURE
(ii)
The function SearchHashTable will search for a record in the hash table. The function
takes as a parameter the customer ID to be searched for. The function will return the
position in the hash table where the record has been saved. If the hash table does not
contain the record, the function will return the value −1.
You can assume that there is at least one empty record in the hash table.
Complete the pseudocode for the function.
FUNCTION SearchHashTable(BYVALUE SearchID : INTEGER) RETURNS INTEGER
// generate hash value
…
Index
// check each record from index until found or not there
WHILE ( …
Question text
3
NameList is a 1D array that stores a sorted list of names. A programmer declares the array in
pseudocode as follows:
NameList : Array[0 : 100] OF STRING
The programmer wants to search the list using a binary search algorithm.
The programmer decides to write the search algorithm as a recursive function. The function, Find,
takes three parameters:
•
Name, the string to be searched for
•
Start, the index of the first item in the list to be searched
•
Finish, the index of the last item in the list to be searched
The function will return the position of the name in the list, or −1 if the name is not found.
Complete the pseudocode for the recursive function.
FUNCTION Find(BYVALUE Name : STRING, BYVALUE Start : INTEGER,
BYVALUE Finish : INTEGER) RETURNS INTEGER
// base case
IF …
THEN
RETURN −1
ELSE
…
Middle
IF …
THEN
RETURN …
ELSE
// general case
IF SearchItem > …
THEN
…
ELSE
…
ENDIF
ENDIF
ENDIF
[7]
ENDFUNCTION
Question text
4
An ordered linked list Abstract Data Type (ADT) has these associated operations:
•
create list
•
add item to list
•
output list to console
The ADT is to be implemented using object-oriented programming as a linked list of nodes.
Each node consists of data and a pointer.
(a) There are two classes, LinkedList and Node.
(i)
State the term used to describe the relationship between these classes.
… [1]
(ii)
Draw the appropriate diagram to represent this relationship. Do not list the attributes and
methods of the classes.
[2]
(b) The design for the Node class consists of:
•
attributes
Data : STRING
Pointer : INTEGER
•
methods
CreateNode(Data, Pointer)
SetData(Data)
SetPointer(Pointer)
GetData() RETURNS STRING
GetPointer() RETURNS INTEGER
The constructor method sets the attributes to the initial values that are passed as parameters.
Write program code for:
•
the Node class declaration
•
the constructor.
Programming language used …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [5]
(c) The identifier table for the LinkedList class is:
Identifier
Data type
Description
HeadPointer
INTEGER
Pointer to the first node in the ordered list.
FreeListPointer
INTEGER
Pointer to the first node in the free list.
NodeArray
ARRAY[0 : 7] OF Node
1D array stores the nodes that make the
ordered linked list. The unused nodes are
linked together into a free list.
Constructor()
Constructor instantiates
Question text
1
The following table shows part of the instruction set for a processor which 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.
LDD
<address>
Direct addressing. Load the contents of the location at the given address
to ACC.
LDI
<address>
Indirect addressing. The address to be used is at the given address.
Load the contents of this second address to ACC.
LDX
<address>
Indexed addressing. Form the address from <address> + the contents of
the index register. Copy the contents of this calculated address to ACC.
STO
<address>
Store the contents of ACC at the given address.
INC
<register> Add 1 to the contents of the register (ACC or IX).
CMP
<address>
Compare the contents of ACC with the contents of <address>.
JMP
<address>
Jump to the given address.
JPE
<address>
Following a compare instruction, jump to <address> if the compare was
True.
JPN
<address>
Following a compare instruction, jump to <address> if the compare was
False.
AND
<address>
Bitwise AND operation of the contents of ACC with the contents of
<address>.
XOR
<address>
Bitwise XOR operation of the contents of ACC with the contents of
<address>.
OR
<address>
Bitwise OR operation of the contents of ACC with the contents of
<address>.
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.
(a) A programmer writes a program that:
•
reads two characters input from the keyboard (you may assume they will be capital
letters in ascending alphabetical sequence)
•
outputs the alphabetical sequence of characters from the first to the second character.
For example, if the characters ‘B’ and ‘F’ are input, the output is:
BCDEF
The programmer has started to write the program in the following table. The Comment column
contains descriptions for the missing program instructions, labels and data.
Complete the following program. Use op codes from the given instruction set.
Op
Label
Operand
Comment
code
START:
// INPUT character
// store in CHAR1
// INPUT character
// store in CHAR2
// initialise ACC to ASCII value of CHAR1
// output contents of ACC
// compare ACC with CHAR2
// if equal jump to end of FOR loop
// increment ACC
// jump to LOOP
ENDFOR:
END
CHAR1:
CHAR2:
[9]
(b) The programmer now starts to write a program that:
•
converts a positive integer, stored at address NUMBER1, into its negative equivalent in
two’s complement form
•
stores the result at address NUMBER2
Complete the following program. Use op codes from the given instruction set.
Show the value stored in NUMBER2.
Op
Label
Operand
Comment
code
START:
MASK
// convert to one's complement
// convert to two's complement
END
MASK:
// show value of mask in binary here
NUMBER1:
B00000101
// positive integer
NUMBER2:
// negative equivalent
[6]
Question text
2
An ordered binary tree Abstract Data Type (ADT) has these associated operations:
•
create tree
•
add new item to tree
•
traverse tree
The binary tree ADT is to be implemented as a linked list of nodes.
Each node consists of data, a left pointer and a right pointer.
(a) A null pointer is shown as O.
Explain the meaning of the term null pointer.
…
… [1]
(b) The following diagram shows an ordered binary tree after the following data have been
added:
Dublin, London, Berlin, Paris, Madrid, Copenhagen
RootPointer
Dublin
London
Ø
Ø
Berlin
Ø Copenhagen Ø
Paris
Ø
Madrid
Ø
Ø
Another data item to be added is Athens.
Make the required changes to the diagram when this data item is added.
[2]
(c) A tree without any nodes
Unused nodes are linked together into a free list
is represented as:
as shown:
RootPointer
FreePointer
Ø
Ø
Ø
Ø
Ø
Ø
The following diagram shows an array of records that stores the tree shown in part (b).
(i)
Add the relevant pointer values to complete the diagram.
RootPointer
LeftPointer
Tree data
RightPointer
0
[0]
Dublin
[1]
London
[2]
Berlin
[3]
Paris
[4]
Madrid
FreePointer
[5]
Copenhagen
[6]
Athens
[7]
[8]
[9]
[5]
(ii)
Give an appropriate numerical value to represent the null pointer for this design. Justify
your answer.
…
…
…
… [2]
(d) A program is to be written to implement the tree ADT. The variables and procedures to be
used are listed below:
Identifier
Data type
Description
Data structure to store node data and associated
Node
RECORD
pointers.
Stores index of start of left subtree.
LeftPointer
INTEGER
Stores index of start of right subtree.
RightPointer
INTEGER
Data item stored in node.
Data
STRING
Array to store nodes.
Tree
ARRAY
Stores data to be added.
NewDataItem
STRING
Stores index of start of free list.
FreePointer
INTEGER
Stores index of root node.
RootPointer
INTEGER
Stores index of node to be added.
NewNodePointer
INTEGER
Procedure initialises the root pointer and free pointer
CreateTree()
and links all nodes together into the free list.
Procedure to add a new data item in the correct
AddToTree()
position in the binary tree.
Procedure that finds the node where a new node is
to be added.
Procedure takes the parameter NewDataItem and
returns two parameters:
FindInsertionPoint()
•
Index, whose value is the index of the node
where the new node is to be added
•
Direction, whose value is the direction of the
pointer (“Left” or “Right”).
(i)
Complete the pseudocode to create an empty tree.
TYPE Node
…
…
…
ENDTYPE
DECLARE Tree : ARRAY[0 : 9] …
DECLARE FreePointer : INTEGER
DECLARE RootPointer : INTEGER
PROCEDURE CreateTree()
DECLARE Index : INTEGER
…
Question text
3
A programmer is writing a treasure island game to be played on the computer. The island is
a rectangular grid, 30 squares by 10 squares. Each square of the island is represented by an
element in a 2D array. The top left square of the island is represented by the array element [0, 0].
There are 30 squares across and 10 squares down.
The computer will:
•
generate three random locations where treasure will be buried
•
prompt the player for the location of one square where the player chooses to dig
•
display the contents of the array by outputting for each square:
–
'.' for only sand in this square
–
'T' for treasure still hidden in sand
–
'X' for a hole dug where treasure was found
–
'O' for a hole dug where no treasure was found.
Here is an example display after the player has chosen to dig at location [9, 3]:
…
…
…
…
…
… T …
…
…
… T …
...X …
The game is to be implemented using object-oriented programming.
The programmer has designed the class IslandClass. The identifier table for this class is:
Identifier
Data type
Description
2D array to represent the
Grid
ARRAY[0 : 9, 0 : 29] OF CHAR
squares of the island
instantiates an object of class
IslandClass and initialises
Constructor()
all squares to sand
generates a pair of random
numbers used as the grid
HideTreasure()
location of treasure and
marks the square with 'T'
takes as parameters a valid
grid location and marks the
DigHole(Row, Column)
square with 'X' or 'O' as
appropriate
takes as parameter a valid
grid location and returns the
grid value for that square
GetSquare(Row, Column) CHAR
from the IslandClass
object
(a) The programmer designed the pseudocode for the main program as follows:
DECLARE Island : IslandClass.Constructor()
// instantiate object
CALL DisplayGrid()
// output island squares
FOR Treasure ← 1 TO 3
// hide 3 treasures
CALL Island.HideTreasure()
ENDFOR
CALL StartDig()
// user to input location of dig
CALL DisplayGrid()
// output island squares
Write program code to implement this pseudocode.
Programming language used …
Program code …
…
…
…
…
…
…
…
…
…
…
Question text
3
(a) The numerical difference between the ASCII code of an upper case letter and the ASCII code
of its lower case equivalent is 32 denary (32 10 ).
For example, 'F' has ASCII code 70 and 'f' has ASCII code 102.
Bit number
7
6
5
4
3
2
1
0
ASCII code
ASCII code in binary
0
1
0
0
0
1
1
0
70
0
1
1
0
0
1
1
0
102
The bit patterns differ only at bit number 5. This bit is 1 if the letter is lower case and 0 if the
letter is upper case.
(i)
A program needs a mask to ensure that a letter is in upper case.
Write the binary pattern of the mask in the space provided in the table below.
Bit number
7
6
5
4
3
2
1
0
ASCII code
ASCII code in binary
0
1
0
0
0
1
1
0
70
0
1
1
0
0
1
1
0
102
Mask
Give the bit-wise operation that needs to be performed using the mask and the
ASCII code.
… [2]
(ii)
A program needs a mask to ensure that a letter is in lower case.
Write the binary pattern of the mask in the space provided in the table below.
Bit number
7
6
5
4
3
2
1
0
ASCII code
ASCII code in binary
0
1
0
0
0
1
1
0
70
0
1
1
0
0
1
1
0
102
Mask
Give the bit-wise operation that needs to be performed using the mask and the
ASCII code.
… [2]
The following table shows part of the instruction set for a processor which has one general
purpose register, the Accumulator (ACC), and an index register (IX).
Instruction
Explanation
Op
Operand
code
LDM
#n
Immediate addressing. Load the number n to ACC.
Direct addressing. Load the contents of the given address to
LDD
<address>
ACC.
Indexed addressing. Form the address from <address> +
LDX
<address>
the contents of the index register. Copy the contents of this
calculated address to ACC.
LDR
#n
Immediate addressing. Load the number n into IX.
STO
<address>
Store the contents of ACC at the given address.
INC
<register>
Add 1 to the contents of the register (ACC or IX).
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
JPE
<address>
compare was True.
Following a compare instruction, jump to <address> if the
JPN
<address>
compare was False.
Bitwise AND operation of the contents of ACC with the
AND
#n
operand.
Bitwise AND operation of the contents of ACC with the
AND
<address>
contents of <address>.
Bitwise XOR operation of the contents of ACC with the
XOR
#n
operand.
Bitwise XOR operation of the contents of ACC with the
XOR
<address>
contents of <address>.
OR
#n
Bitwise OR operation of the contents of ACC with the operand.
Bitwise OR operation of the contents of ACC with the contents
OR
<address>
of <address>.
Output to the screen the character whose ASCII value is
OUT
stored in ACC.
END
Return control to the operating system.
A programmer is writing a program that will output the first character of a string in upper case and
the remaining characters of the string in lower case.
The program will use locations from address WORD onwards to store the characters in the string.
The location with address LENGTH stores the number of characters that make up the string.
The programmer has started to write the program in the following table. The comment column
contains descriptions for the missing program instructions.
(b) Complete the program using op codes from the given instruction set.
Op
Label
Operand
Comment
code
START:
// initialise index register to zero
// get first character of WORD
// ensure it is in upper case using MASK1
// output character to screen
// increment index register
// load 1 into ACC
// store in COUNT
LOOP:
// load next character from indexed address WORD
// make lower case using MASK2
// output character to screen
// increment COUNT starts here
// is COUNT = LENGTH ?
// if FALSE, jump to LOOP
// end of program
COUNT:
Question text
4
Circle the programming language that you have studied:
Visual Basic (console mode)
Python
Pascal
Delphi (console mode)
(a) (i)
Name the programming environment you have used when typing in program code.
…
…
List three features of the editor that helped you to write program code.
1 …
…
2 …
…
3 …
… [3]
(ii)
Explain when and how your programming environment reports a syntax error.
When …
…
…
How …
…
… [2]
The table shows a module definition for BubbleSort in three programming languages.
(iii)
Study one of the examples. Indicate your choice by circling A, B or C:
A
B
C
A) Python
01
def BubbleSort(SList, Max):
02
NoMoreSwaps = False
03
while NoMoreSwaps == False:
04
NoMoreSwaps = True
05
for i in (Max - 1):
06
if SList[i] > SList[i + 1]:
07
NoMoreSwaps = True
08
Temp = SList[i]
09
SList[i] = SList[i + 1]
10
SList[i + 1] = Temp
B) Pascal/Delphi
01
PROCEDURE BubbleSort(VAR SList : ARRAY OF INTEGER; Max : INTEGER);
02
VAR NoMoreSwaps : BOOLEAN; i, Temp : INTEGER;
03
BEGIN
04
REPEAT
05
NoMoreSwaps := TRUE;
06
FOR i := 1 TO (Max – 1)
07
IF SList[i] > SList[i + 1]
08
THEN
09
BEGIN
10
NoMoreSwaps := TRUE;
11
Temp := SList[i];
12
SList[i] := SList[i + 1];
13
SList[i + 1] := Temp;
14
END;
15
UNTIL NoMoreSwaps;
16
END;
C) Visual Basic
01
Sub BubbleSort(ByRef SList() As Integer, ByVal Max As Integer)
02
Dim NoMoreSwaps As Boolean, i, Temp As Integer
03
Do
04
NoMoreSwaps = True
05
For i : 0 To (Max – 1)
06
If SList(i) > SList(i + 1) Then
07
NoMoreSwaps = True
08
Temp = SList(i)
09
SList(i) = SList(i + 1)
10
SList(i + 1) = Temp
11
End If
12
Next
13
Loop Until (NoMoreSwaps = True)
14
End Sub
The programming environment reported a syntax error in the BubbleSort code.
State the line number …
Write the correct code for this line.
… [2]
(b) (i)
State whether programs written in your programming language are compiled or
interpreted.
Question text
1
A linked list abstract data type (ADT) is to be used to store and organise surnames.
This will be implemented with a 1D array and a start pointer. Elements of the array consist of a
user-defined type. The user-defined type consists of a data value and a link pointer.
Identifier
Data type
Description
LinkedList
RECORD
User-defined type
Surname
STRING
Surname string
Ptr
INTEGER
Link pointers for the linked list
Write pseudocode to declare the type LinkedList.
(a) (i)
…
…
…
… [3]
The 1D array is implemented with an array SurnameList of type LinkedList.
(ii)
Write the pseudocode declaration statement for SurnameList. The lower and upper
bounds of the array are 1 and 5000 respectively.
… [2]
(b) The following surnames are organised as a linked list with a start pointer StartPtr.
StartPtr: 3
1
2
3
4
5
6
5000
Liu
Yang
Chan
Wu
Zhao
Huang
Surname
…
4
5
6
2
0
1
Ptr
…
State the value of the following:
SurnameList[4].Surname … [1]
(i)
SurnameList[StartPtr].Ptr … [1]
(ii)
(c) Pseudocode is to be written to search the linked list for a surname input by the user.
Identifier
Data type
Description
ThisSurname
STRING
The surname to search for
Current
INTEGER
Index to array SurnameList
Index to array SurnameList. Points to the
StartPtr
INTEGER
element at the start of the linked list
(i)
Study the pseudocode in part (c)(ii).
Complete the table above by adding the missing identifier details.
[2]
(ii)
Complete the pseudocode.
01 Current ← …
02 IF Current = 0
03
THEN
04
OUTPUT …
05
ELSE
06
IsFound ← …
07
INPUT ThisSurname
08
REPEAT
09
IF … = ThisSurname
10
THEN
11
IsFound ← TRUE
12
OUTPUT "Surname found at position ", Current
13
ELSE
14
// move to the next list item
15
…
16
ENDIF
17
UNTIL IsFound = TRUE OR …
18
IF IsFound = FALSE
19
THEN
20
OUTPUT "Not Found"
21
ENDIF
22 ENDIF
[6]