Data types, arrays and files – A Level Computer Science (old syllabus, to 2021) (9608)
118 questions · page 7 of 8
Question text
5
A sports club maintains a record of the email address of each of its members. The details are
stored in a text file, EmailDetails.txt. The format of each line of the text file is as follows:
<MembershipNumber><EmailAddress>
•
MembershipNumber is a four-character string of numerals.
•
EmailAddress is a variable-length string.
Membership of the club has increased and a four-character membership number is no longer
adequate.
A procedure, MakeNewFile, is required to perform the following actions:
1.
Create a new file, NewEmailDetails.txt
2.
Read a line from file EmailDetails.txt
3.
Extend MembershipNumber by adding two leading zero digits (for example, "1234"
becomes "001234")
4.
Write the new line to file NewEmailDetails.txt
5.
Repeat steps 2 to 4 for all lines in the original file.
(a) Write pseudocode for the procedure MakeNewFile.
For the built-in functions list, refer to the Appendix on page 14.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [8]
(b) A function, IsEmailValid, is to be written to test for a valid email address format.
An email address has a valid format if it obeys the following three rules:
1.
It contains a single ‘@’ symbol.
2.
The ‘@’ symbol must be preceded by at least one character.
3.
The ‘@’ symbol must be followed by at least three characters.
Choose three different invalid strings to test distinct aspects of the rules.
Explain your choice in each case.
1 …
Explanation …
Question text
1
(a) (i)
Procedural high-level languages usually support different data types.
Give an appropriate data type for each data value in the following table:
Data value
Data type
FALSE
03/03/2013
35
"INTEGER"
3.5
"35"
[6]
(ii)
The following is a declaration in a high-level language:
DEFINE MyGrade[1 to 100]
State the data structure of variable MyGrade.
… [1]
(iii)
An experienced programmer is presented with program code in an unfamiliar high-level
language.
State two features of the code that the programmer should be able to recognise.
1 …
…
2 …
…
[2]
(b) (i)
In the ASCII character set ‘A’ is represented by the value 65. The values representing the
other characters of the alphabet follow in sequence, so ‘B’ is represented by 66, ‘C’ by 67
and so on.
The following table represents consecutive memory locations. Each memory location
stores one byte.
Complete the table to show how the string "CAGE" may be stored in memory using the
ASCII set.
Address
Data
100
101
102
103
104
105
[2]
(ii)
In a high-level language, a LENGTH function is used to return the number of characters in
a string.
Explain what is stored in addition to the string characters to allow this function to
determine this number.
…
…
…
… [2]
(c) Functions and procedures are subroutines.
Explain why parameters are used with subroutines.
…
…
…
…
…
… [3]
(d) The following pseudocode is an example of a CASE structure.
CASE OF MyMark
"Distinction"
75 to 100: MyGrade
"Pass"
35 to 74: MyGrade
"Fail"
0 to 34: MyGrade
OTHERWISE: OUTPUT "Invalid value entered"
ENDCASE
(i)
Describe what will happen if the pseudocode is tested when MyMark has the following
values:
27 …
…
Question text
2
A 1D array, ClassName, of type STRING contains 100 elements.
The following pseudocode represents a simple algorithm to process the array.
DECLARE SearchValue : STRING
DECLARE FoundFlag : BOOLEAN
DECLARE Index : INTEGER
INPUT SearchValue
FALSE
FoundFlag
1
Index
WHILE Index < 101 AND FoundFlag = False
IF ClassName[Index] = SearchValue
THEN
OUTPUT Index
TRUE
FoundFlag
ENDIF
Index + 1
Index
ENDWHILE
IF FoundFlag = FALSE
THEN
OUTPUT "Not found"
ENDIF
(a) Describe the purpose of the algorithm.
…
…
…
…
…
… [2]
(b) Draw a program flowchart to represent this algorithm.
Note that variable declarations are not required in program flowcharts.
[9]
Question text
3
A 1D array, Product, of type STRING is used to store information about a range of products in a
shop. There are 100 elements in the array. Each element stores one data item.
The format of each data item is as follows:
<ProductID><ProductName>
ProductID is a four-character string of numerals
•
ProductName is a variable-length string
•
The following pseudocode is an initial attempt at defining a procedure, ArraySort, which will
perform a bubble sort on Product. The array is to be sorted in ascending order of ProductID.
Line numbers have been added for identification purposes only.
01
PROCEDURE SortArray
02
DECLARE Temp : CHAR
03
DECLARE FirstID, SecondID : INTEGER
1 TO 100
04
FOR I
2 TO 99
05
FOR J
MODULUS(LEFT(Product[J], 6))
06
FirstID
MODULUS(LEFT(Product[J + 1], 6))
07
SecondID
08
IF FirstID > SecondID
09
THEN
Product[I]
10
Temp
Product[J + 1]
11
Product[I]
Temp
12
Product[J + 1]
13
ENDFOR
14
ENDIF
15
ENDFOR
16
ENDPROCEDURE
The pseudocode on page 8 contains a number of errors. Complete the following table to show:
the line number of the error
•
the error itself
•
the correction that is required.
•
Note:
If the same error occurs on more than one line, you should only refer to it ONCE.
•
Lack of optimisation should not be regarded as an error.
•
Line
Error
Correction
number
01
Wrong procedure name – “SortArray”
PROCEDURE ArraySort
[8]
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
2
One of the security features of a multi-user computer system is a user login process. The user
must complete this successfully before they can access the resources of the system.
As part of the login process the user enters their user ID followed by a password. The system then
compares the password entered with the password held in a file.
(a) The steps involved in the login process are described as follows:
•
User enters their ID and password.
•
Validation checks:
Compare user ID with data from the file.
Indicate whether or not the user ID was found.
If user ID found, check whether passwords match.
The description above is not detailed enough to allow a program to be written. The validation
checks must be expressed as a more detailed algorithm.
Give the name of the process of increasing the level of detail of the algorithm.
… [1]
(b) An identifier table is created as the algorithm is developed. A section of the table is shown.
Complete the table.
Identifier
Data Type
Description
…
Stores the user ID entered
UserIDInput
…
…
PasswordInput
…
…
…
UserIDFound
…
…
…
PasswordValid
…
[5]
(c) The validation checks described in part (a) are to be used as the basis for program code.
Use structured English to write a more detailed algorithm.
You should:
•
use the identifiers given in the previous table
•
assume that the password file, password.txt, is organised as a simple text file. The
user ID and password are stored together, one entry per line.
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
5
A multi-user computer system records user login information in a text file, LoginFile.txt. Each
time a user successfully logs into the system, the following information is recorded:
Item
Information
Example data
1
A five character user ID
"JimAA"
2
A four character port ID
"3456"
3
A fourteen character time and date
"08:30Jun012015"
The data items are concatenated to form a single string. Each string is saved as a separate line in
the text file.
The example data in the preceding table would result in the following text line in the file:
"JimAA345608:30Jun012015"
The computer system can produce a list of the successful login attempts by a given user.
The file LoginFile.txt is searched for a given user ID and the corresponding data are copied
into a 2D array, LoginEvents.
LoginEvents has been declared in pseudocode as:
DECLARE LoginEvents[1 : 1000, 1 : 2] OF STRING
A procedure, SearchFile, is needed to search the file and copy selected data to the array.
The main steps of the procedure are as follows:
•
Input a user ID.
•
Search LoginFile.txt for entries with matching user ID.
•
For matching entries, copy items 2 and 3 above into the LoginEvents array.
You can assume that:
•
the system initialises all elements of LoginEvents to an empty string " ", before it calls
SearchFile
•
there will be no more than 1000 successful logins for a single user.
Write program code for the procedure SearchFile.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
5
A multi-user computer system records user login data. Each time a user successfully logs into the
system, it records the following data.
Data item
Example data
User ID
"Jim27"
Port ID
"3456"
Time and date
"08:30 Jun 01 2015"
The data items are concatenated (joined) using a separator character to form a single string. Each
string represents one log entry.
(a) (i)
Suggest a suitable separator character. Give the reason for your choice.
Character …
Reason …
…
[2]
(ii)
The concatenated strings are stored in an array, LogArray, which may contain up to 20
log entries.
Use pseudocode to declare LogArray.
… [2]
(b) A procedure, LogEvents, is required to add the log entry data from LogArray to the existing
text file, LoginFile.txt.
Unused array elements are assigned the value "****". These can occur anywhere in the
array and should not be written to the file.
Write program code for the procedure LogEvents.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
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
…