Data types, arrays and files – A Level Computer Science (old syllabus, to 2021) (9608)
48 questions · page 2 of 4 · Clear filters
Question text
2
A business is developing a program that stores each customer’s username and password in a
hash table.
The hash table will be implemented as a 1D array, CustomerLogIn, of the custom data type
CustomerRecord.
The declaration for CustomerRecord is:
TYPE CustomerRecord
DECLARE Username : STRING
DECLARE Password : STRING
ENDTYPE
The hash table will store a maximum of 3000 records. The key field will be Username.
(a) The program declares the hash table and initialises the username and password of all the
records to an empty string.
Write pseudocode to declare and initialise the hash table.
…
…
…
…
…
…
…
… [4]
(b) (i)
A function, SearchHashTable() will search for a customer’s record in the hash table.
The function Hash():
•
takes a Username as a parameter
•
performs the hashing algorithm
•
returns the calculated index of the username within the hash table.
The function SearchHashTable():
•
takes the username to search for as a parameter
•
uses Hash() to calculate the first index of this username within the hash table
•
returns either the index of the username if found, or –1 if not found.
Complete the pseudocode for the function SearchHashTable().
FUNCTION SearchHashTable(BYVALUE SearchUser : STRING) RETURNS …
DECLARE Index : INTEGER
DECLARE Count : INTEGER
… (SearchUser)
Index
Count
0
WHILE (CustomerLogIn[Index] … <> … )
AND(CustomerLogIn[Index].Username <> "")
AND(Count < 2999)
Index
Index + 1
Count
Count + 1
IF Index > …
THEN
Index
0
ENDIF
ENDWHILE
IF CustomerLogIn[Index].Username = …
THEN
RETURN Index
ELSE
RETURN …
ENDIF
ENDFUNCTION
[7]
(ii)
Explain the purpose of the variable Count in the function SearchHashTable().
…
…
…
… [2]
Question text
3
Recursive algorithms can be used when creating programs.
(a) Describe what is meant by a recursive algorithm.
…
…
…
…
…
… [3]
(b) A string that is a palindrome, reads the same forwards as it does backwards. For example,
the name Anna is a palindrome.
The function Substring(Variable, StartingCharacter, NumberOfCharacters)
returns one or more characters from a string. The first character is at position 0.
For example, the string "Happy" is stored in the variable Word.
•
Substring(Word, 1, 1) would return the character "a".
•
Substring(Word, 2, 3) would return the characters "ppy".
The function Length() returns the length of the string as an integer. For example,
Length(Word) returns 5.
The following is a recursive function to find out whether a string is a palindrome. The function
returns True if the parameter is a palindrome, and returns False if it is not a palindrome.
Complete the pseudocode for the recursive algorithm to indicate whether a string is a
palindrome.
FUNCTION IsPalindrome(CheckWord : STRING) RETURNS BOOLEAN
IF … <= 1
THEN
RETURN …
ENDIF
IF Substring(CheckWord, 0, 1) <>
Substring(CheckWord, … (CheckWord)-1, 1)
THEN
RETURN …
ELSE
RETURN … ( Substring(CheckWord, 1,
Length(CheckWord)-2))
ENDIF
ENDFUNCTION
[5]
(c) The function FindPower() is a recursive function that calculates the result of a base number
to the power of the exponent. For example, the result of 2 4 = 16, as 2*2*2*2 = 16. In this
example, 2 is the base number and 4 is the exponent.
The base number and the exponent are passed as parameters.
Write pseudocode for the recursive function FindPower(). Assume both the base and the
exponent are positive integers.
…
…
…
…
…
…
…
…
…
Question text
8
Files can be structured in serial, sequential or random format.
Tick (3) one box in each row to show whether the statement applies to Serial, Sequential or
Random format.
Statement
Serial
Sequential
Random
Uses a hashing algorithm
No key field is used when storing data, for example,
it is stored in chronological order
Collisions can occur
Least efficient for a very large number of records
Most efficient for a very large number of records
[3]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
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.
…
…
…
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]
Question text
1
(a) A stack contains the values 'red', 'blue', 'green' and 'yellow'.
Top of stack
yellow
green
blue
red
(i)
Show the contents of the stack in part(a) after the following operations.
POP()
PUSH('purple')
PUSH('orange')
[1]
(ii)
Show the contents of the stack from part(a)(i) after these further operations.
POP()
POP()
PUSH('brown')
POP()
PUSH('black')
[1]
(b) A queue is an alternative Abstract Data Type (ADT).
Describe a queue.
…
…
…
…
…
… [3]
Question text
2
A computer games club wants to run a competition. The club needs a system to store the scores
achieved in the competition.
A selection of score data is as follows:
99, 125, 121, 97, 109, 95, 135, 149
(a) A linked list of nodes will be used to store the data. Each node consists of the data, a left
pointer and a right pointer. The linked list will be organised as a binary tree.
(i)
Complete the binary tree to show how the score data above will be organised.
RootPointer
The symbol ∅ represents a null pointer.
LeftPointer
RightPointer
99
97
125
∅
121
[5]
(ii)
The following diagram shows a 2D array that stores the nodes of the binary tree’s linked
list.
Add the correct pointer values to complete the diagram, using your answer from
part (a)(i).
RootPointer
Index LeftPointer
Data
RightPointer
0
99
0
1
125
2
121
3
97
FreePointer
4
109
5
95
6
135
7
149
8
[6]
(b) The club also considers storing the data in the order in which it receives the scores as a
linked list in a 1D array of records.
The following pseudocode algorithm searches for an element in the linked list.
Complete the six missing sections in the algorithm.
FUNCTION FindElement(Item : INTEGER) RETURNS …
… ← RootPointer
WHILE CurrentPointer … NullPointer
IF List[CurrentPointer].Data <> …
THEN
CurrentPointer ← List[ … ].Pointer
ELSE
RETURN CurrentPointer
ENDIF
ENDWHILE
CurrentPointer ← NullPointer
… CurrentPointer
ENDFUNCTION
[6]
(c) The games club is looking at two programming paradigms: imperative and object-oriented
programming paradigms.
Describe what is meant by the imperative programming paradigm and the object-oriented
programming paradigm.
(i)
Imperative …
…
…
…
…
… [3]
(ii)
Object-oriented …
…
…
…
…
… [3]
(d) Players complete one game to place them into a category for the competition. The games club
wants to implement a program to place players into the correct category. The programmer
has decided to use object-oriented programming (OOP).
The highest score that can be achieved in the game is 150. Any score less than 50 will not
qualify for the competition. Players will be placed in a category based on their score.
The following diagram shows the design for the class Player. This includes the properties
and methods.
Player
Sco
Question text
1
A company wants an online marking system for an examination.
(a) The following is a selection of data showing final marks.
36, 45, 21, 65, 66, 13, 54, 53, 34
A linked list of nodes will be used to store the data. Each node consists of the data, a left
pointer and a right pointer. The linked list will be organised as a binary tree.
(i)
Complete the binary tree to show how the data above will be organised.
RootPointer
The symbol Ø represents a
null pointer
LeftPointer
RightPointer
36
45
21
Ø
65
66
Ø
Ø
[5]
(ii)
The following diagram shows a 2D array that stores the nodes of the binary tree’s linked
list.
Add the correct pointer values to complete the diagram, using your answer from
part (a)(i).
RootPointer
Index
LeftPointer
Data
RightPointer
0
0
36
1
45
FreePointer
2
21
3
65
4
66
5
13
6
54
7
53
8
34
9
[6]
(b) The company wants to implement a program for the marking system. It will do this with
object-oriented programming (OOP).
Many candidates take the examination. Each examination paper is given a PaperID that is
made up of the centre (school) number followed by the candidate number.
Each examination paper is awarded a grade.
The following diagram shows the design for the ExaminationPaper class. This includes
the attributes and methods.
ExaminationPaper
FinalMark : INTEGER // maximum 2 digits, initialised to 0
Grade
: STRING // "Pass", "Merit", "Distinction"
// or "Fail", initialised to "Fail"
PaperID
: STRING // centre number followed by the
// candidate number, for example
// "ZZ00991001"
Create()
//
creates and initialises a new instance
//
of the ExaminationPaper class using
//
language-appropriate constructor
SetFinalMark()
//
checks that the mark parameter has a
//
valid value, if so, assigns it to
//
FinalMark
SetGrade()
//
sets Grade based on FinalMark
GetFinalMark()
//
returns FinalMark
GetGrade()
//
returns Grade
GetPaperID()
//
returns PaperID
(i)
The constructor receives the centre number and candidate number as parameter values
to create PaperID. Other properties are initialised as instructed in the class diagram.
Write program code for the Create() constructor method.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
… [5]
(ii)
Get and set methods are used to support the security and integrity of data in
object-oriented programming.
Explain how get and set methods are used to support security and integrity.
…
Question text
2
A stack is an Abstract Data Type (ADT).
(a) Tick (3) one box to show the statement that describes a stack data structure.
Statement
Tick (3)
Last in first out
First in first out
Last in last out
[1]
(b) A stack contains the values 20, 35, 43, 55.
55
Top of stack
43
35
20
(i)
Show the contents of the stack in part (b) after the following operations.
POP()
POP()
PUSH(10)
[1]
(ii)
Show the contents of the stack from part (b)(i) after these further operations:
POP()
PUSH(50)
PUSH(55)
POP()
PUSH(65)
[1]
(iii)
The stack is implemented as a 1D array, with eight elements, and given the identifier
ArrayStack.
The global variable Top contains the index of the last element in the stack, or −1 if the
stack is empty.
The function Push():
•
takes as a parameter an INTEGER value to place on the stack
•
adds the value to the top of the stack and returns TRUE to show that the operation
was successful
•
returns FALSE if the stack is full.
Write an algorithm in pseudocode for the function Push().
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [7]
Question text
4
(a) A program has sorted some data in the array, List, in ascending order.
The following binary search algorithm is used to search for a value in the array.
FALSE
01
ValueFound
LengthOfList - 1
02
UpperBound
0
03
LowerBound
FALSE
04
NotInList
05
06
WHILE ValueFound = FALSE AND NotInList = FALSE
ROUND((LowerBound + UpperBound) / 2)
07
MidPoint
08
09
IF List[LowerBound] = SearchValue
10
THEN
TRUE
11
ValueFound
12
ELSE
13
IF List[MidPoint] < SearchValue
14
THEN
MidPoint + 1
15
UpperBound
16
ELSE
MidPoint – 1
17
UpperBound
18
ENDIF
19
IF LowerBound > MidPoint
20
THEN
TRUE
21
NotInList
22
ENDIF
23
ENDIF
24
ENDWHILE
25
26
IF ValueFound = FALSE
27
THEN
28
OUTPUT "The value is in the list"
29
ELSE
30
OUTPUT "The value is not found in the list"
31
ENDIF
Note:
The pseudocode function
ROUND(Reall : REAL) RETURNS INTEGER
rounds a number to the nearest integer value.
For example: ROUND(4.5) returns 5 and ROUND(4.4) returns 4
(i)
There are four errors in the algorithm.
Write the line of code where an error is present and write the correction in pseudocode.
Error 1 …
Correction …
Error 2 …
Correction …
Error 3 …
Correction …
Error 4 …
Correction …
[4]
(ii)
A binary search is one algorithm that can be used to search an array.
Identify another searching algorithm.
… [1]
(b) The following is an example of a sorting algorithm. It sorts the data in the array ArrayData.
""
01
TempValue
02
REPEAT
TRUE
03
Sorted
0 TO 4
04
FOR Count
05
IF ArrayData[Count] > ArrayData[Count + 1]
06
THEN
ArrayData[Count + 1]
07
TempValue
ArrayData[Count]
08
ArrayData[Count + 1]
TempValue
09
ArrayData[Count]
FALSE
10
Sorted
11
ENDIF
12
ENDFOR
13
UNTIL Sorted = TRUE
(i)
Complete the trace table for the algorithm given in part (b), for the ArrayData values
given in the table.
ArrayData
Count
TempValue
Sorted
0
1
2
3
4
5
5
20
12
25
32
29
[4]
(ii)
Rewrite lines 4 to 12 of the algorithm in part (b) using a WHILE loop instead of a FOR
loop.
…
…
…
…
…
…
…
Question text
2
Kendra collects books. She is writing a program to store and analyse information about her books.
Her program stores information about each book as a record. The following table shows the
information that will be stored about each book.
Field name
Description
The title of the book
Title
The first listed author of the book
Author
A 13-digit code that uniquely identifies the book,
for example:
ISBN
"0081107546738"
If the book is fiction (TRUE) or non-fiction (FALSE)
Fiction
The date when Kendra last read the book
LastRead
(a) Write pseudocode to declare an Abstract Data Type (ADT) named Book, to store the
information in the table.
…
…
…
…
…
…
…
…
… [4]
(b) The records are stored in a random access file.
The function, Hash(), takes as a parameter the ISBN and returns the hash value.
The disk address of the record in the hash table is calculated as: ISBN modulus 2000 plus 1.
Write program code for the function Hash().
Programming language …
Program code …
…
…
…
…
…
…
… [4]
(c) The random access file, MyBooks.dat, stores the data about the books in the format:
<Title>
<Author>
<ISBN>
<Fiction>
<LastRead>
A procedure, FindBook():
prompts the user to input the ISBN of a book until the ISBN contains 13 numeric digits
•
uses the function Hash() to calculate the disk address of the record
•
reads the record for that book from MyBooks.dat into a variable of type Book
•
outputs all the data
Question text
3
Joseph is taking a toy apart. Each time he removes an item from the toy, he writes the name of
the item at the bottom of a paper list. When he rebuilds the toy, he puts the items back together
working from the bottom of the list.
Joseph writes a computer program to create the list using a stack, Parts.
(a) Describe a stack structure.
…
… [1]
(b) The stack is represented as an array in the program, the first element in the array is [0].
The current contents of the stack, Parts, and its pointer, StackPointer are shown.
StackPointer
StackContents
5
0
"Screw 1"
1
"Screw 2"
2
"Back case"
3
"Screw 3"
4
"Engine outer"
5
6
7
(i)
Describe the purpose of the variable StackPointer.
…
… [1]
(ii)
The procedure POP() removes an item from the stack. The procedure
PUSH(<identifier>) adds an item to the stack.
The current contents of the stack, Parts, and its pointer, StackPointer are shown.
StackPointer
StackContents
5
0
"Screw 1"
1
"Screw 2"
2
"Back case"
3
"Screw 3"
4
"Engine outer"
5
6
7
Use the table below to show the contents of the stack, Parts, and its pointer after the
following code is run.
POP()
POP()
PUSH("Light 1")
PUSH("Light 2")
PUSH("Wheel 1")
POP()
POP()
StackPointer
StackContents
0
1
2
3
4
5
6
7
[2]
(c) A 1D array, Parts, is used to implement the stack. Parts is declared as:
DECLARE Parts : ARRAY[0 : 19] OF STRING
(i)
The procedure POP outputs the last element that has been pushed onto the stack and
replaces it with a '*'.
Complete the pseudocode for the procedure POP.
PROCEDURE POP
IF … . = … .
THEN
OUTPUT "The stack is empty"
ELSE
…
StackPointer
OUTPUT … . … .
… .
Parts[StackPointer]
ENDIF
ENDPROCEDURE
[5]
(ii)
The procedure PUSH() puts the parameter onto the stack.
Complete the pseudocode for the procedure PUSH().
PROCEDURE PUSH(BYVALUE Value : String)
IF StackPointer > … .…
THEN
OUTPUT "Stack full"
ELSE
… . … .…..
… . … .. …
… .…. … .
StackPointer
ENDIF
ENDPROCEDURE
[4]
Question text
4
The recursive algorithm for the Calculate() function is defined as follows:
01 FUNCTION Calculate(BYVALUE Number : INTEGER) RETURNS INTEGER
02
IF Number = 0
03
THEN
−10
04
Calculate
05
ELSE
Number * Calculate(Number − 1)
06
Calculate
07
ENDIF
08 ENDFUNCTION
(a) (i)
State what is meant by a recursive algorithm.
…
… [1]
(ii)
State the line number in Calculate() where the recursive call takes place.
… [1]
Question 4(b) begins on the next page.
(b) The function is called with Calculate(3).
Dry run the function and complete the trace table below. State the final value returned. Show
your working.
01 FUNCTION Calculate(BYVALUE Number : INTEGER) RETURNS INTEGER
02
IF Number = 0
03
THEN
−10
04
Calculate
05
ELSE
Number * Calculate(Number − 1)
06
Calculate
07
ENDIF
08 ENDFUNCTION
Working …
…
…
…
Trace table:
Number = 0 ?
Call number
Function call
Return value
Final return value …
[6]
(c) A recursive algorithm within a subroutine can be replaced with an iterative algorithm.
(i)
Describe one problem that can occur when running a subroutine that has a recursive
algorithm.
…
…
…
… [2]
(ii)
Rewrite the Calculate() function in pseudocode, using an iterative algorithm.
…
…
…
…
…
…
…
…
…
Question text
3
A bubble sort algorithm is used to sort an integer array, List. This algorithm can process arrays
of different lengths.
(a) Write pseudocode to complete the bubble sort algorithm shown.
… TO 0 STEP - 1
01 FOR Outer
0 TO ( … )
02
FOR Inner
IF …
…
03
>
04
THEN
…
05
Temp
…
06
List[Inner]
…
07
List[Inner + 1]
08
ENDIF
09
ENDFOR
10 ENDFOR
[7]
(b) (i)
State the order of the sorted array.
… [1]
(ii)
State which line of the algorithm you would change to sort the array into the opposite
order.
State the change you would make.
Line …
Change …
…
[1]
(c) Use pseudocode to write an alternative version of this bubble sort algorithm that will exit the
algorithm when the list is fully sorted.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
6
A linked list abstract data type (ADT) is created. This is implemented as an array of records. The
records are of type ListElement.
An example of a record of ListElement is shown in the following table.
Data Item
Value
Country
"Scotland"
Pointer
1
(a) (i)
Use pseudocode to write a definition for the record type, ListElement.
…
…
…
…
… [3]
(ii)
Use pseudocode to write an array declaration to reserve space for only 15 nodes of
type ListElement in an array, CountryList. The lower bound element is 1.
… [2]
(b) The program stores the position of the last node in the linked list in LastNode. The last node
always has a Pointer value of -1. The position of the node at the head of the list is stored in
ListHead.
After some processing, the array and variables are in the following state.
CountryList
ListHead
Country
Pointer
1
1
"Wales"
2
LastNode
2
"Scotland"
4
3
3
-1
4
"England"
5
5
"Brazil"
6
6
"Canada"
7
7
"Mexico"
8
8
"Peru"
9
9
"China"
10
10
11
11
12
12
13
13
14
14
15
15
3
A recursive algorithm searches the list for a value, deletes that value, and updates the
required pointers. When a node value is deleted, it is set to empty "" and the node is added
to the end of the list.
A node value is deleted using the pseudocode statement
CALL DeleteNode("England", 1, 0)
Complete the following pseudocode to implement the DeleteNode procedure.
PROCEDURE DeleteNode(NodeValue: STRING, ThisPointer : INTEGER,
PreviousPointer : INTEGER)
IF CountryList[ThisPointer].Value = NodeValue
THEN
""
CountryList[ThisPointer].Value
IF ListHead = …
THEN
ListHead
…
ELSE
CountryList[PreviousPointer].Pointer
CountryList[ThisPointer].Pointer
ENDIF
CountryList[LastNode].Pointer
…
LastNode
ThisPointer
…
ELSE
IF CountryList[ThisPointer].Pointer <> -1
THEN
CALL DeleteNode(NodeValue, … ,
ThisPointer)
ELSE
OUTPUT "DOES NOT EXIST"
ENDIF
ENDIF
ENDPROCEDURE
[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