0% found this document useful (0 votes)
7 views

Data Structures

The document contains a series of questions related to data structures, specifically focusing on trees, graphs, and algorithms. It includes tasks such as explaining the functionality of pseudo-code, sketching tree structures, and discussing the properties of binary trees and hash tables. Additionally, it covers traversal methods, adjacency matrices, and the use of stacks and queues.

Uploaded by

User.9463820
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Data Structures

The document contains a series of questions related to data structures, specifically focusing on trees, graphs, and algorithms. It includes tasks such as explaining the functionality of pseudo-code, sketching tree structures, and discussing the properties of binary trees and hash tables. Additionally, it covers traversal methods, adjacency matrices, and the use of stacks and queues.

Uploaded by

User.9463820
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

Q1.

This question is about the CardCollection class.

(a) Figure 1 shows a pseudo-code version of part of the Shuffle subroutine.


Figure 2 shows an alternative, incorrect version of the same part of the Shuffle
subroutine.

Figure 1

TempCard ← Cards[RNo1]
Cards[RNo1] ← Cards[RNo2]
Cards[RNo2] ← TempCard

Figure 2

Cards[RNo1] ← Cards[RNo2]
Cards[RNo2] ← Cards[RNo1]

Explain why the Shuffle subroutine would not work if it used the method shown in
Figure 2 instead of the method shown in Figure 1.

___________________________________________________________________

___________________________________________________________________
(1)

The CardCollection class uses a list to store the cards.

(b) State one reason why a set could not have been used instead of a list.

___________________________________________________________________

___________________________________________________________________
(1)

(c) A hash table could have been used instead of a list.

Describe how a card would be added to a hash table.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(3)

(d) A hash table can be used to implement a dictionary data structure.

Page 1 of 64
Explain why a hash table is a suitable choice.

___________________________________________________________________

___________________________________________________________________
(1)
(Total 6 marks)

Q2.
For the expression 3+x the binary tree stores + at the root, 3 at the left hand node and x at
the right hand node. If the nodes of this tree are printed as the tree is traversed, what will
be printed when the traversal is

(a) pre-order; __________________________________________________________

(b) in-order; ___________________________________________________________

(c) post-order? _________________________________________________________


(Total 3 marks)

Q3.
A binary search tree is used by software to store and then search for user names on a
college network.

The following are the first seven user names to join the tree:

PollardJ, AtkinsP, RogersG, AbbottJ, SearleF, CollinsK, RuddleA

(a) Sketch the tree structure.

(2)

(b) The tree is to be searched for various user names.

(i) The task is to search for the user name CollinsK. List in order the nodes
visited.

______________________________________________________________
(1)

(ii) A second search is done to find the user name RuddleA. How many

Page 2 of 64
comparisons does this require?

______________________________________________________________
(1)
(Total 4 marks)

Q4.
A tree can be used to represent a mathematical expression. This is known as an
expression tree. Figure 1 is an expression tree for the infix expression 4 + 9 * 6.

Figure 1

(a) An expression tree is an example of a rooted tree.

State the contents of the root node:___________________________

List the contents of all of the leaf nodes: _______________________


(2)

(b) The expression tree in Figure 1 could be represented using three one-dimensional
arrays named A, B and C. Figure 2 shows a representation of Figure 1 together
with the array indices.
Figure 2
Arrays

Index A B C

[1] + 2 3

[2] 4 0 0

[3] * 4 5

[4] 9 0 0

[5] 6 0 0

Page 3 of 64
Describe the role of each of the arrays A, B and C.

A:
_________________________________________________________________

B:
_________________________________________________________________

C:
_________________________________________________________________
(3)

(c) What does an entry of 0 in array B indicate?

___________________________________________________________________

___________________________________________________________________
(1)

(d) The procedure in Figure 3 describes a type of tree traversal that can be carried out
on the representation of the tree shown in Figure 2.
Figure 3

Procedure Traverse(Pos:Integer)

If B[Pos] > 0 Then Traverse(B[Pos])

If C[Pos] > 0 Then Traverse(C[Pos])

Output A[Pos]

End Procedure

Using the table below, trace the execution of the procedure when it is called using
Traverse(1). You may not need to use all of the lines provided in the table.

Pos Output

Page 4 of 64
(4)

(e) Which type of tree traversal does the procedure Traverse carry out?

___________________________________________________________________
(1)

(f) What does the output of the procedure represent?

___________________________________________________________________
(1)
(Total 12 marks)

Q5.
A binary tree is a type of data structure.

(a) State two characteristics that make a tree a binary tree.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)

(b) Figure 1 shows a binary tree and its representation using an array of records called
Tree. Each record consists of three fields, Data, Left and Right.

Figure 1

Figure 2 shows a subroutine that implements a binary tree search algorithm using
the array Tree. The subroutine parameter, k, is the data item being searched for.
The subroutine returns a Boolean value indicating if the data item being searched
for is in the binary tree or not.

Parts of the algorithm are missing.

Figure 2
SUBROUTINE BTS(k)
Current ← 1
WHILE Current > 2
IF Tree[Current].Data = k THEN
RETURN 3

Page 5 of 64
ELSEIF Tree[Current].Data < k THEN
4
ELSE
5
ENDIF
ENDWHILE
RETURN 6
ENDSUBROUTINE

Complete each row in the table below, to show what the labels indicating missing
parts of the algorithm in Figure 2 should be replaced by.

6
(4)

(c) There are similarities in how the binary tree search and the binary search algorithms
work.

State the big-O time complexity of the binary search algorithm.

___________________________________________________________________

___________________________________________________________________
(1)

(d) Explain why the binary search algorithm has the time complexity stated in your
answer for part (c).

___________________________________________________________________

___________________________________________________________________
(1)

(e) Explain why searching for an item in a list or tree is a tractable problem.

___________________________________________________________________

___________________________________________________________________
(1)

(f) Heuristics can be used when working with an intractable problem.

Explain what heuristics are.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

Page 6 of 64
___________________________________________________________________
(2)

(g) Explain what is meant by constant time complexity.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)
(Total 13 marks)

Q6.
The table below shows an adjacency matrix representation of a directed graph (digraph).

(a) Complete this unfinished diagram of the directed graph.

(2)

(b) Directed graphs can also be represented by an adjacency list.

Explain under what circumstances an adjacency matrix is the most appropriate


method to use to represent a directed graph, and under what circumstances an
adjacency list is more appropriate.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)

(c) A tree is a particular type of graph.

Page 7 of 64
What properties must a graph have for it to be a tree?

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)

(d) Data may be stored as a binary tree.

Show how the following data may be stored as a binary tree for subsequent
processing in alphabetic order by drawing the tree. Assume that the first item is the
root of the tree and the rest of the data items are inserted into the tree in the order
given.

Data items: Jack, Bramble, Snowy, Butter, Squeak, Bear, Pip

(3)

(e) A binary tree such as the one created in part (d) could be represented using one
array of records or, alternatively, using three one-dimensional arrays.

Describe how the data stored in the array(s) could be structured for one of these
two possible methods of representation.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(3)
(Total 12 marks)

Q7.

Page 8 of 64
Figure 1 is a graph that shows the time it takes to travel between six locations in a
warehouse. The six locations have been labelled with the numbers 1 - 6. When there is no
edge between two nodes in the graph this means that it is not possible to travel directly
between those two locations. When there is an edge between two nodes in the graph the
edge is labelled with the time (in minutes) it takes to travel between the two locations
represented by the nodes.

(a) The graph is represented using an adjacency matrix, with the value 0 being used to
indicate that there is no edge between two nodes in the graph.

A value should be written in every cell.

Complete the unshaded cells in Table 1 so that it shows the adjacency matrix for
Figure 1.

Table 1

1 2 3 4 5 6

4
5

6
(2)

(b) Instead of using an adjacency matrix, an adjacency list could be used to represent
the graph. Explain the circumstances in which it would be more appropriate to use
an adjacency list instead of an adjacency matrix.

___________________________________________________________________

Page 9 of 64
___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)

(c) State one reason why the graph shown in Figure 1 is not a tree.

___________________________________________________________________

___________________________________________________________________
(1)

(d) The graph in Figure 1 is a weighted graph. Explain what is meant by a weighted
graph.

___________________________________________________________________

___________________________________________________________________
(1)

Figure 2 contains pseudo-code for a version of Djikstra’s algorithm used with the graph in
Figure 1.

Q is a priority queue which stores nodes from the graph, maintained in an order based on
the values in array D. The reordering of Q is performed automatically when a value in D is
changed.

AM is the name given to the adjacency matrix for the graph represented in Figure 1.

Figure 2

Q ← empty queue

FOR C1 ← 1 TO 6

D[C1] ← 20

P[C1] ← −1
ADD C1 TO Q
ENDFOR
D[1] ←
0
WHILE Q NOT EMPTY
U ←get next node from Q
remove U from Q
FOR EACH V IN Q WHERE AM[U, V] > 0
A ←D[U] + AM[U, V]
IF A < D[V] THEN
D[V] ← A

P[V] ← U
ENDIF
ENDFOR
ENDWHILE
OUTPUT D[6]

Page 10 of 64
(e) Complete the unshaded cells of Table 2 to show the result of tracing the algorithm
shown in Figure 2. Some of the trace, including the maintenance of Q, has already
been completed for you.

(7)

(f) What does the output from the algorithm in Figure 2 represent?

___________________________________________________________________

___________________________________________________________________
(1)

(g) The contents of the array P were changed by the algorithm. What is the purpose of
the array P?

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)
(Total 16 marks)

Q8.
Figure 1 shows a simpler example of a type of logic puzzle with fewer cells. In this simpler
puzzle only the letters A-D are used.

Page 11 of 64
It is possible to represent this type of puzzle as a graph. To do this a unique number is
given to each cell and a node containing this unique number is added to the graph. An
edge between two nodes denotes a link between those two cells, meaning they cannot
contain the same letter as each other.

Figure 2 shows how unique numbers have been allocated to each cell in the puzzle in
Figure 1 and Figure 3 shows an adjacency matrix that represents this puzzle.

Page 12 of 64
The graph in Figure 3 can be considered to be both a representational abstraction and an
abstraction by generalisation of the puzzle from Figure 1.

Only the top half of the matrix in Figure 3 needed to be used to present the puzzle. For
which type of graph would the bottom half of the matrix also need to be used?

_______________________________________________________________________

_______________________________________________________________________
(Total 1 mark)

Q9.
Figure 1 shows a simpler example of a type of logic puzzle with fewer cells. In this simpler
puzzle only the letters A-D are used.

Page 13 of 64
It is possible to represent this type of puzzle as a graph. To do this a unique number is
given to each cell and a node containing this unique number is added to the graph. An
edge between two nodes denotes a link between those two cells, meaning they cannot
contain the same letter as each other.

Figure 2 shows how unique numbers have been allocated to each cell in the puzzle in
Figure 1 and Figure 3 shows an adjacency matrix that represents this puzzle.

Page 14 of 64
The graph in Figure 3 can be considered to be both a representational abstraction and an
abstraction by generalisation of the puzzle from Figure 1.

A graph can be represented using an adjacency list or as an adjacency matrix.

Explain the circumstances when it would be more appropriate to use an adjacency matrix
instead of an adjacency list.

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________
(Total 2 marks)

Q10.
Explain how the elements in a non-empty queue may be reversed with the aid of a stack.

Page 15 of 64
_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________
(Total 4 marks)

Q11.
Describe how the elements in a non-empty queue are reversed with the aid of a stack.

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________
(Total 4 marks)

Q12.
The list Ports contains the following names:

[Southampton, Barcelona, Athens, Alexandria, Tunis, Lisbon]

The table below shows some functions which take a list as their single argument and
return a result which is either an element of a list or a boolean value.

Head(list) – If the list is non-empty, it returns the element at the head of the list
(e.g. Head (Ports) → Southampton) otherwise it reports an error

Tail(list) – If the list is non-empty it returns a new list containing all but the first
element of the original list, otherwise it reports an error

Empty(list) – if the list is the empty list it returns True otherwise it returns False.
The empty list is donated by [ ]

(a) What result is returned when the following function calls are made?

(i) Tail(Ports) _____________________________________________________

______________________________________________________________
(1)

Page 16 of 64
(ii) Head(Tail(Tail(Ports))) ____________________________________________

______________________________________________________________
(2)

(iii) Empty(Tail(Tail(Tail(Tail(Tail(Tail(Ports))))))) __________________________

______________________________________________________________
(2)

A recursively defined procedure P, which takes a list as its single parameter, is defined
below.
Define Procedure P(list)
If Not Empty(list)
Then
P(Tail(list))
Print Head(list)
EndIf
EndDefine

(b) What is meant by recursively defined?

___________________________________________________________________

___________________________________________________________________
(1)

(c) Explain why a stack is needed to execute procedure P recursively.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)

(d) For the procedure call P(Ports) give the PRINTed output in the order in which it is
produced.

___________________________________________________________________

___________________________________________________________________
(4)

(e) Complete the table to show the list Ports as a linked list so that the ports can be
accessed in alphabetical order.

Page 17 of 64
(2)
(Total 14 marks)

Q13.
A stack is a type of abstract data type (ADT) that is often known as a LIFO data type. A
stack with a single element 27 may be drawn as follows:

(a) What is the meaning of the term LIFO?

___________________________________________________________________
(1)

(b) A stack has two operations, Push and Pop. Push n adds item n to stack. Pop
removes one item from the stack. A number of operations are performed, in
sequence, on the stack drawn above. Using the stack diagrams below show the
effect of this sequence of operations.

(i) Push 5

(1)

(ii) Push 9

Page 18 of 64
(1)

(iii) Pop

(1)

(iv) Push 6

(1)

(c) Give one example of the use of a stack.

___________________________________________________________________
(1)
(Total 6 marks)

Q14.

(a) In the context of data structures what is meant by the terms:

(i) FIFO; _________________________________________________________

(ii) LIFO? ________________________________________________________


(2)

(b) Queue and stack are examples of data structures. Tick in the following table to
indicate whether they are FIFO or LIFO data structures.

FIFO LIFO

Queue

Stack
(2)

Page 19 of 64
(c) Describe one example of the use of a stack.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)

(d) Describe one example of the use of a Binary Search Tree.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)
(Total 8 marks)

Q15.
Reverse Polish Notation is an alternative to standard infix notation for writing arithmetic
expressions.

(a) Convert the following Reverse Polish Notation expressions to their equivalent infix
expressions.

Reverse Polish Notation Equivalent Infix Expression

45 6 +

12 19 + 8 *
(2)

(b) State one advantage of Reverse Polish Notation over infix notation.

___________________________________________________________________

___________________________________________________________________
(1)

(c) The pseudo-code algorithm below can be used to calculate the result of evaluating a
Reverse Polish Notation expression that is stored in a string. The algorithm is
designed to work only with the single digit denary numbers 0 to 9. It uses
procedures and functions listed in the table below, two of which operate on a stack
data structure.

StringPos ← 0
Repeat
StringPos ← StringPos + 1
Token ← GetCharFromString(InputString, StringPos)
If Token = ‘+’ Or Token = ‘-’ Or Token = ‘/’ Or Token = ‘*’
Then
Op2 ←Pop()
Op1 ← Pop()
Case Token Of
‘+’: Result ← Op1 + Op2
‘-’: Result ← Op1 - Op2

Page 20 of 64
‘/’: Result ← Op1 / Op2
‘*’: Result ←Op1 * Op2
EndCase
Push(Result)
Else
IntegerVal ←ConvertToInteger(Token)
Push(IntegerVal)
EndIf
Until StringPos = Length(InputString)
Output Result

Procedure/Function Purpose Example(s)


GetCharFromString
Returns the character GetCharFromString
(InputString:String
at position StringPos ("Computing", 1)
,
StringPos:Integer): within the string would return the
Char InputString. character 'C'.
Note that the leftmost GetCharFromString
("Computing", 3)
letter is position 1, not
position 0. would return the
character 'm'.
ConvertToInteger Returns the integer ConvertToInteger('4'
(ACharacter: Char): equivalent of the
Integer ) would return the
character in
ACharacter. integer value 4.

Length (AString: Returns a count of the Length("AQA") would


String): Integer number of characters in return the integer value
the string AString. 3.

Push (ANumber: Puts the number in Push(6) would put the


Integer) ANumber onto the stack. number 6 on top of the
stack.

Pop (): Integer Removes the number


from the top of the stack
X ←Pop() would
and returns it. remove the value from
the top of the stack and
put it in X.

(d) Complete the table below to trace the execution of the algorithm when InputString
is the string: 64+32+*

In the Stack column, show the contents of the stack once for each iteration of the
Repeat..Until loop, as it would be at the end of the iteration.

The first row and the leftmost column of the table have been completed for you.

StringPos Token IntegerVal Op1 Op2 Result Stack

0 - - - - -

Page 21 of 64
1

(5)

Final output of algorithm: ______________________________________________


(1)

(e) A programmer is going to implement the algorithm above in a programming


language that does not provide built-in support for a stack data structure.

The programmer intends to simulate a stack by using a fixed length array of 20


integers named StackArray with indices running from 1 to 20 and an integer
variable TopOfStackPointer which will be initialised to 0.

Write a pseudo-code algorithm for the Push operation to push a value stored in the

Page 22 of 64
variable ANumber onto the stack.

Your algorithm should cope appropriately with any potential errors that might occur.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(4)
(Total 13 marks)

Q16.

(a) State the principle of operation of a set of data values which behave as a stack.

___________________________________________________________________

___________________________________________________________________
(1)

(b) Memory locations 600 to 605 are to be used as a stack area to store character data,
and the first value added to the stack is to be stored at address 600.

Figure 1 shows the initial empty state of the stack.

Figure 1
600

601

602

603

604

605

(i) Show on Figure 2 the state of the stack after the characters ‘A’, ‘V’, ‘E’, ‘R’
and ‘Y’ join the stack.

Figure 2
600

Page 23 of 64
601

602

603

604

605
(1)

(ii) Two items are removed from the stack. Show on Figure 3 the state of the
stack.

Figure 3
600

601

602

603

604

605
(1)

(iii) Two new characters ‘S’ and ‘P’ join the stack. Show on Figure 4 the final state
of the stack.

Figure 4
600

601

602

603

604

605
(1)

(c) The original items in this stack are to be reversed. This can be done using a second
data structure which uses locations 700 to 705 respectively. The first item added to
the stack was character ‘A’.

Figure 5

Page 24 of 64
600 ‘A’ 700 600

601 ‘V’ 701 601

602 ‘E’ 702 602

603 ‘R’ 703 603

604 ‘Y’ 704 604

605 705 605

Stack Stack
(before the operation) (i) ____________ (after the operation)

(i) Name the second data structure. Label Figure 5.

______________________________________________________________
(1)

(ii) Describe Step 1 in Figure 5.

______________________________________________________________

______________________________________________________________
(1)

(iii) Describe Step 2 in Figure 5.

______________________________________________________________

______________________________________________________________
(1)

(iv) Show on Figure 5 the final contents of all the memory locations.
(2)
(Total 9 marks)

Q17.
A queue data structure can be implemented as a static data structure using an array.

(a) Describe the method that would need to be followed to attempt to remove an item
from a circular queue implemented as a static data structure using an array.

Your method should deal appropriately with any issues which could arise.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

Page 25 of 64
___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(4)

(b) Describe three differences between dynamic and static data structures.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(3)

The figure below shows data that has been stored in a stack implemented using an array
S.

[7]

[6]

[5]

[4]

[3]
[2] Jib Top = 2
[1] Skye

[0] Harry

(c) What value will be returned by applying the peek operation to S?

___________________________________________________________________

___________________________________________________________________
(1)

(d) What value will be returned by applying the pop operation to S?

___________________________________________________________________

___________________________________________________________________
(1)

Page 26 of 64
(e) Explain how a single stack can be used to reverse the order of the items in a queue.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)
(Total 11 marks)

Q18.
Describe the process that should be followed to add an item to a circular queue
implemented as a static data structure using an array.

Your method should deal appropriately with any issues which could arise.

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________
(Total 5 marks)

Q19.
Priority queues and linear queues are examples of data structures.

Describe the steps involved in adding an item to a linear queue that has been
implemented as a static data structure using an array. Your answer should include a
description of how any pointers are used and changed.

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

Page 27 of 64
_______________________________________________________________________
(Total 3 marks)

Q20.
A computer program is being developed to play a card game on a smartphone. The game
uses a standard deck of 52 playing cards, placed in a pile on top of each other.

The cards will be dealt (ie given out) to players from the top of the deck.

When a player gives up a card it is returned to the bottom of the deck.

(a) Explain why a queue is a suitable data structure to represent the deck of cards in
this game.

___________________________________________________________________

___________________________________________________________________
(1)

(b) The queue representing the deck of cards will be implemented as a circular queue
in a fixed-size array named DeckQueue. The array DeckQueue has indices running
from 1 to 52.

The figure below shows the contents of the DeckQueue array and its associated
pointers at the start of a game. The variable QueueSize indicates how many cards
are currently represented in the queue.

(i) Twelve cards are dealt from the top of the deck.

What values are now stored in the FrontPointer and RearPointer pointers
and the QueueSize variable?

FrontPointer = ___________ RearPointer = ___________

QueueSize = ___________
(1)

(ii) Next, a player gives up three cards and these are returned to the deck.

What values are now stored in the FrontPointer and RearPointer pointers

Page 28 of 64
and the QueueSize variable?

FrontPointer = ___________ RearPointer = ___________

QueueSize = ___________
(1)

(c) Write a pseudo-code algorithm to deal a card from the deck.

Your algorithm should output the value of the card that is to be dealt and make any
required modifications to the pointers and to the QueueSize variable.

It should also cope appropriately with any situation that might arise in the
DeckQueue array whilst a game is being played.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(6)
(Total 9 marks)

Q21.
Describe how a single stack could be used to evaluate an RPN expression.

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

Page 29 of 64
_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________
(Total 4 marks)

Q22.
A graph can be drawn to represent a maze. In such a graph, each graph vertex
represents one of the following:

• the entrance to or exit from the maze

• a place where more than one path can be taken

• a dead end.

Edges connect the vertices according to the paths in the maze.

Diagram 1 shows a maze and Diagram 2 shows one possible representation of this
maze.
Position 1 in Diagram 1 corresponds to vertex 1 in Diagram 2 and is the entrance to the
maze. Position 7 in Diagram 1 is the exit to the maze and corresponds to vertex 7.
Dead ends have been represented by the symbol in Diagram 2.

Diagram 3 shows a simplified undirected graph of this maze with dead ends omitted.

Diagram 2 Diagram 3

Page 30 of 64
Representation of maze Graph representing maze
including dead ends with dead ends omitted

(a) The graph in Diagram 3 is a tree.

State one property of the graph in Diagram 3 that makes it a tree.

___________________________________________________________________

___________________________________________________________________
(1)

(b) The graphs of some mazes are not trees.

Describe a feature of a maze that would result in its graph not being a tree.

___________________________________________________________________

___________________________________________________________________
(1)

(c) Complete the table below to show how the graph in Diagram 3 would be stored
using an adjacency matrix.

Page 31 of 64
(2)

(d) (i) What is a recursive routine?

______________________________________________________________

______________________________________________________________
(1)

(ii) To enable the use of recursion a programming language must provide a stack.

Explain what this stack will be used for and why a stack is appropriate.

______________________________________________________________

______________________________________________________________

______________________________________________________________

______________________________________________________________
(2)

Diagram 3 is repeated here so that you can answer Question (e) without having to turn
pages.

Page 32 of 64
(e) A recursive routine can be used to perform a depth-first search of the graph that
represents the maze to test if there is a route from the entrance (vertex 1) to the exit
(vertex 7).

The recursive routine in the diagram below is to be used to explore the graph in
Diagram 3. It has two parameters, V (the current vertex) and EndV (the exit vertex).

Procedure DFS(V, EndV)


Discovered[V] ← True

If V = EndV Then Found ←


True
For each vertex U which is connected to V Do
If Discovered [U] = False Then DFS(U, EndV)
EndFor
CompletelyExplored[V] ← True
EndProcedure

Complete the trace table below to show how the Discovered and
CompletelyExplored flag arrays and the variable Found are updated by the
algorithm when it is called using DFS(1,7).

The details of each call and the values of the variables V, U and EndV have already
been entered into the table for you. The letter F has been used as an abbreviation
for False. You should use T as an abbreviation for True.

Page 33 of 64
(5)
(Total 12 marks)

Q23.
Describe the steps involved in adding a record to a hash table.

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

Page 34 of 64
(Total 5 marks)

Q24.
A dictionary is an abstract data type that allows pairs of values to be associated with each
other. For example, an English-French dictionary might associate English words with their
translations into French. In such a dictionary, "Apple" would be associated with "Pomme"
because "Pomme" is the French word for "Apple".

At a lower level of abstraction, a dictionary could be implemented as a data structure


using a number of different methods. Two possible implementation methods are:

• Implementation One: As an unordered list in an array.


• Implementation Two: Using hashing, with the English word being passed through a
hash function to calculate the position of the correct French translation in an array.

In each implementation, a record containing the English word and the equivalent French
word are stored at each index in the array that is in use.

The figure below shows how an English-French dictionary containing five words could be
implemented using these two methods.

Implementation One – Unordered List Implementation Two – Hashing


Index English Word French Word Index English Word French Word

[1] Apple Pomme [1] Pear Poire

[2] Lemon Citron [2] Lemon Citron

[3] Strawberry Fraise [3]

[4] Grapefruit Pamplemousse [4]

[5] Pear Poire [5]

[6] [6]

[7] [7] Apple Pomme

[8] [8] Strawberry Fraise

[9] [9]

[10] [10] Grapefruit Pamplemousse


New words are inserted into the array in the The position to store a word is calculated
first available slot. The next word would be from the English word using a hashing
stored at position 6. function.

(a) Explain why, when the French translation of an English word needs to be looked up,
Implementation Two is more time efficient than Implementation One.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

Page 35 of 64
___________________________________________________________________
(2)

(b) In Implementation Two, it is possible that the hash function could compute the
same value for two different English words.

Explain what the effect of this would be, and how it could be dealt with.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)

(c) In Implementation Two, both the English and French words are stored at each
index in the Array. In this implementation, explain why it would not be possible to
perform reliable English to French translation if only the French words were stored.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(1)
(Total 5 marks)

Q25.
The graph below shows two vectors a and b and the angle between them, c.

Page 36 of 64
a = [4, 3]

b = [4, 0]

The magnitude of a vector, represented as an arrow, is the length of the arrow. The
magnitude of vector a is 5 because

(a) What is the magnitude of vector b?

___________________________________________________________________

___________________________________________________________________
(1)

(b) Calculate the dot product of vectors a and b. You should show your working.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)

The angle between two vectors cannot be larger than 180 o. If the angle is measured as
being greater than 180o then this angle is subtracted from 360o to find the actual angle
between the two vectors.

Example: if an angle between two vectors represented as arrows is measured as being


240o then the angle between the two vectors is 360 o – 240o = 120o

(c) Describe what will happen to the angle c and the magnitude of vector a when vector
a is multiplied by the scalar 2

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)

(d) Describe what will happen to the angle c and the magnitude of vector a when vector
a is multiplied by the scalar -1

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)
(Total 7 marks)

Page 37 of 64
Mark schemes

Q1.
(a) Mark is for AO2 (analyse)

There will end up being two copies of the second card (A. a card);
The first card (A. a card) will be overwritten;

Max 1
1

(b) Mark is for AO2 (apply)

Because sets are unordered // because the cards have an order;


R. because sets only allow one instance of a value to be stored
1

(c) One mark for AO2 (apply)

Hash algorithm / function applied to CardNumber (NE. primary key);

Two marks for AO1 (understanding)

Result indicates location that card should be stored in;

If there is already a card in that location a method is needed to deal with


collisions;
A. description of any suitable method for dealing with collisions
3

(d) Mark is for AO1 (understanding)

Allows direct (A. faster) access to the value being looked-up


//
No need to search through the list to find a value (assuming a good choice of
hash function);
1
[6]

Q2.

(a) +3x;
1

(b) 3+x;
1

(c) 3x+;
1
[3]

Q3.

(a)

Page 38 of 64
Correct root + left subtree;
Correct root + right subtree;

I. identification of PollardJ as the root


A a complete ‘left-right’ mirrored image.
2

(b) (i) PollardJ, AtkinsP, CollinsK


from a correctly drawn left sub-tree;
1

(ii) 4 from a correctly drawn right sub-tree;


1
[4]

Q4.

(a) +;
4, 9, 6; (in any order)
2

(b) A Store the data / value (in the vertices / nodes);


A: holds the expression
B: Left pointer // points to the left child / left sub tree;
C: Right pointer // points to the right child / right sub tree;
A “indicates”, "index" or other synonym for “points” / “pointer”
R Stores left / right subtree
3

(c) The node has no left child / sub tree;


A there is nothing to the left
A this is a null pointer
1

(d) One mark for each area outlined with a dark rectangle. Lines that are not
outlined can be missed out.

Alternative 1Alternative 2

Page 39 of 64
Mark against whichever alternative gives the highest mark.

Stop marking as soon as incorrect output is given.


4

(e) Post-order;
A Depth-first
A Depth-first search as BOD
TO Depth-first pre / in-order
1

(f) ( 4 + 9 * 6 in) Reverse Polish (Notation) // Postfix (Notation) // RPN;


1
[12]

Q5.
(a) All marks for AO1 (understanding)

A root (A. start) node; A. there is a parent-child relationship between nodes

Each node has no more than two child nodes; R. has two child nodes
2

(b) All marks are for AO2 (apply)

1 0

2 −1

3 True

4 Current ← Tree[Current].Right

5 Current ← Tree[Current].Left

6 False

Page 40 of 64
Note for examiners: answers are in pseudo-code so accept any reasonable
representation (including use of string or integer values for rows 3 and 6).

Mark as follows:

1 mark: row one correct


1 mark: row two correct
1 mark: rows three and six correct
1 mark: rows four and five correct
4

(c) Mark is for AO1 (knowledge)

O(log2n);

I. missing brackets
I. missing O
I. missing 2
1

(d) Mark is for AO1 (understanding)

Every comparison halves the size of the binary tree to look at; (A. every
comparison halves the size of the tree)
1

(e) Mark is for AO1 (understanding)

It does not have exponential (or worse) time complexity;


It has a polynomial (or better) time complexity solution;
A. It can be solved in a reasonable amount of time regardless of the
problem/input size;
NE. can be solved in a reasonable amount of time

Max 1
1

(f) All marks AO1 (understanding)

Rules/knowledge (about the problem domain);

Can be used to find a good/approximate but (probably) not optimal solution to


a problem;

Can reduce the size of the search/problem space // changing some


constraints in the problem;

Max 2
2

(g) All marks AO1 (knowledge)

As the size of the input/problem increases; the amount of time taken remains
the same;
2
[13]

Q6.

Page 41 of 64
(a)

1 mark for all 5 lines correctly drawn


1 mark for all 5 arrowheads pointing in correct directions
Max 1 if more than 5 lines drawn by candidate (note that dotted arrow is given
in question)

A arrowheads at any position on line


2

(b) Adjacency matrix appropriate when there are many edges between vertices //
when edges may be frequently changed // when presence/absence of specific
edges needs to be tested (frequently)
Adjacency list appropriate when there are few edges between vertices // when
graph is sparse // when edges rarely changed //when presence/absence of
specific edges does not need to be tested (frequently)
A alternative words which describe edge e.g. connection, line
2

(c) Connected // There is a path between each pair of vertices;


Undirected // No direction is associated with each edge;
Has no cycles // No (simple) circuits // No closed chains // No closed paths in
which all the edges are different and all the intermediate vertices are different
// No route from a vertex back to itself that doesn’t use an edge more than
once or visit an intermediate vertex more than once;
Alternative definitions:
Graph with no cycles, and a simple cycle is formed if any edge is added to it;;
Graph which is connected, and it is not connected anymore if any edge is
removed from it;;
Graph in which any two vertices can be connected by a unique simple path;;
(Note: not just adjacent vertices)
Graph which is connected and has n - 1 edges where n is no of vertices;;
Graph which has no simple cycles and has n - 1 edges where n is no of
vertices;;
Max 2

(d)

Page 42 of 64
1 mark for Jack as root
1 mark for Bramble and Snowy as children of Jack
1 mark for four correct children of Bramble and Snowy

DPT if arrows drawn instead of lines


DPT if any node has more than 2 child nodes
A “mirror image” answers which are consistent.
3

(e) For solution with 3 arrays:


One array stores data items;
One array for left child pointers;
One array for right child pointers;
Pointers stored at same location in arrays as corresponding data item;
For solution with 1 array of records:
Record created to store data item and pointers;
One pointer to left child;
One pointer to right child;
For either of the above solutions:
Rogue value (allow example) used to indicate no child;
Variable indicates position in array(s) of root node // Root node stored at first
location/start of array(s);
If answered as diagram:
Column for data with at least three correct data items in it;
Use of rogue value for a node that does not have child;
Correct value for a start pointer variable indicating position of root node in the
array (not drawn as an arrow, array indices must be labelled);
Column for left child pointers*;
Column for right child pointers*;
* = To get these marks, there must be a sufficient number of pointers to
demonstrate that the data structure is a representation of a binary tree, but it is
not necessary for every item to be shown. Also the array indices must be
shown.
Max 3
[12]

Q7.
(a) All marks AO2 (analyse)

1 2 3 4 5 6

1 0 2 5 3 0 8

2 2 0 1 0 0 0

Page 43 of 64
3 5 1 0 0 0 4

4 3 0 0 0 1 0

5 0 0 0 1 0 5

6 8 0 4 0 5 0

Alternative answer

1 2 3 4 5 6

1 0 2 5 3 0 8

2 0 1 0 0 0

3 0 0 0 4

4 0 1 0

5 0 5

6 0

Alternative answer

1 2 3 4 5 6

1 0

2 2 0

3 5 1 0

4 3 0 0 0

5 0 0 0 1 0

6 8 0 4 0 5 0

Mark as follows:

1 mark 0s in correct places

1 mark all other values correct

I. non-zero symbols used to denote no edge but only for showing no edge
going from a node to itself
2

(b) All marks for AO1 (understanding)

Adjacency list appropriate when there are few edges between vertices // when
graph/matrix is sparse; NE. few edges

Adjacency list appropriate when edges rarely changed;

Adjacency list appropriate when presence/absence of specific edges does not


need to be tested (frequently);

Page 44 of 64
A. Alternative words which describe edge, eg connection, line, arc

Max 2
2

(c) Mark is for AO2 (apply)

It contains a cycle / cycles;


1

(d) Mark for AO1 (knowledge)

A graph where each edge has a weight/value associated with it;


1

(e) All marks AO2 (apply)

Mark as follows:

I. output column
1 mark first value of A is 2
1 mark second value of A is 5 and third value is 3
1 mark fourth and subsequent values of A are 8, 3, 7, 4, 9 with no more values
after this
1 mark D[2] is set to 2 and then does not change

Page 45 of 64
1 mark D[3] is set to 5 and then changes to 3 and does not change again
1 mark correct final values for each position of array P

Page 46 of 64
1 mark correct final values for D[1], D[4], D[5], D[6]

Page 47 of 64
Max 6 marks if any errors
7

(f) Mark is for AO2 (analyse)

The shortest distance / time between locations/nodes 1 and 6;

NE distance / time between locations/nodes 1 and 6

R. shortest route / path


1

(g) All marks AO2 (analyse)

Used to store the previous node/location in the path (to this node);

Allows the path (from node/location 1 to any other node/location) to be


recreated // stores the path (from node/location 1 to any other node/location);

Max 1 if not clear that the values represent the shortest path

Page 48 of 64
Alternative answer

Used to store the nodes that should be traversed;

And the order that they should be traversed;

Max 1 if not clear that the values represent the shortest path
2
[16]

Q8.
Mark is for AO1 (understanding)

Directed (graph) // digraph;


[1]

Q9.
All marks for AO1 (understanding)

Adjacency matrix appropriate when there are many edges between vertices // when
graph/matrix is not sparse; when edges frequently changed; when presence/absence of
specific edges needs to be tested frequently;

Max 2 marks

A. Alternative words which describe edge, eg connection, line


[2]

Q10.
Repeat
S→Q
Until Q empty
Queue emptied to a stack
Elements taken from front of queue and placed / pushed on stack

2 marks

Repeat
Q→S
Until S empty
Stack emptied to a queue
Elements popped/taken from top of stack placed in queue

2 marks

Or suitable diagram

1 mark
[4]

Q11.
Queue is FIFO ; (1)
Stack is LIFO; (1)
Given that:

Page 49 of 64
Process of taking elements from queue to stack(1)
Process of popping stack(1)
[4]

Q12.

(a) Tail(Ports) - [Barcelona, Athens, Alexandria, Tunis, Lisbon]

square brackets needed


1

Head(Tail(Tail(Ports))) – Athens (2)

[Athens] (1)
2

Empty(T(T(T(T(T(T(Ports))))))) – True (2)

True [ ] (1)

[True] (0)
2

(b) Recursively defined


A definition which is defined in terms of itself/contains within its body a
reference to itself/calls itself ;
A re-entrant; (In specimen papers 2001/2, but refers specifically to a
procedure)
1

(c) Stack necessary


The state of the machine/contents of appropriate registers/ return address //
saved each time the procedure is called (1) and retrieved in reverse order from
the stack as control is progressively returned (1)
OR
Different value of parameters /local variables (1) must be available each time
procedure is called (1)
OR
P must be re-entrant (In specimen papers 2001/2 )(2)
2

(d) Lisbon first (1)


Southampton last(1)
All 6 in order (1)
No punctuation (1)

i.e. Lisbon Tunis Alexandria Athens Barcelona Southampton;


4

(e)

Page 50 of 64
2
[14]

Q13.

(a) Last In First Out;


1

(b) (i)

(ii)

(iii)

(iv)

Page 51 of 64
(c) To reverse elements/ pass parameters/ store volatile environment;
A store return address
1
[6]

Q14.

(a) (i) First In First Out;


or by description

(ii) Last In First Out;


or by description
2

(b)
FIFO LIFO

Queue

Stack
2

(c) Reverse the contents of a queue/list;


Push all contents of queue/list onto stack then pop them off into a new
queue/list;
Procedure/function calls;
Local variables;
Parameters;
Return Address;
Volatile environment; A register contents State 1 Describe 1
2

(d) List of elements inserted into tree;


To allow rapid/fast searching of the data;
To output sorted/ordered data;
2
[8]

Q15.

(a)
Reverse Polish Notation Equivalent Infix Expression

45 6 + 45 + 6
R 6 + 45

12 19 + 8 * (12 + 19) * 8
R 12+19*8, (19+12)*8
A x for *
2

(b) Simpler for a machine / computer to evaluate // simpler to code algorithm


A easier R to understand
Do not need brackets (to show correct order of evaluation/calculation);

Page 52 of 64
Operators appear in the order required for computation;
No need for order of precedence of operators;
No need to backtrack when evaluating;
A RPN expressions cannot be ambiguous as BOD
1

(c)

Output : 50

1 mark for each of rows 1–3


1 mark for rows 4 and 5 together
1 mark for rows 6 and 7 together
1 mark for correct final output
Values of Op1 and Op2 MUST be assigned in rows 3, 6 and 7 to award the
marks for these rows. They cannot be inferred from incorrectly entered
previous values.

I values in empty cells, even if they are incorrect.


6
(d) If StackArray is full
Then Stack Full Error
Else
Increment TopOfStackPointer
StackArray [TopOfStackPointer]
ANumber
EndIf

1 mark for appropriate If structure including condition (does not need both

Page 53 of 64
Then and Else) – Do not award this mark if ANumber is put into StackArray
outside the If.
1 mark for reporting error in correct place
1 mark* for incrementing TopOfStackPointer
1 mark* for storing value in ANumber into correct position in array
* = if the store instruction is given before the increment instruction OR
the If structure then award Max 1 of these two marks UNLESS the item is
inserted at position TopOfStackPointer+1 so the code would work.

I initialisation of TopOfStackPointer to 0
A TopOfStackPointer=20/>=20 for Stack is full
A Logic of if structure reversed i.e. If stack is not full /
TopOfStackPointer<20 / <>20/!=20 and Then, Else swapped
A Any type of brackets or reasonable notation for the array index
DPT If candidate has used a different name any variable then do not award
first mark but award subsequent marks as if correct name used.
Refer answers where candidate has used a loop to find position to insert item
into stack to team leaders.
4
[13]

Q16.

(a) Last (item) in, is the first (item) out / first (item) in is the last (item) out ;
R LIFO / FILO
1

(b) (i)
600 ‘A’

601 ‘V’

602 ‘E’

603 ‘R’

604 ‘Y’ ;

605

All items in the correct locations


1

(ii)
599

600 ‘A’

601 ‘V’

602 ‘E’ ;

603

604

Page 54 of 64
605

Correct three items // ft from an incorrect (i) including 605 as the first
location used ;
A ‘R’ and ‘Y’ entries indicated in some way as ‘deleted’
1

(iii)
600 ‘A’

601 ‘V’

602 ‘E’

603 ‘S’

604 ‘P’ ;

605

Correct list of five items // ft from an incorrect (i) + a correct ft (ii)


including 605 as the first location used ;
1

(c) (i) Queue ;


A First In – First Out FIFO / LILO
1

(ii) Items are removed/popped from the stack (one at a time) (and items are
then added to the queue);
1

(iii) Items leave the queue on a ‘first in-first out’ basis ; A from the front of
the queue
1

(iv) ‘Y’, ‘R’, ‘E’, ‘V’, ‘A’ on the queue ;


Y’, ‘R’, ‘E’, ‘V’, ‘A’ on the final stack ;
A using 701 for the first queue location
2
[9]

Q17.
(a) All marks for AO1 (understanding)

1. Check the queue is (not already) empty;


2. Compare the value of the front pointer with the maximum size of the
array;
3. If equal then front pointer becomes one; A. index of the first position in
the array instead of one
4. Otherwise, add one to the front pointer;

Alternative answer 1

1. Check the queue is (not already) empty;


2. Compare the value of the front pointer with the maximum size of the

Page 55 of 64
array minus one;
3. If equal then front pointer becomes zero; A. index of the first position in
the array instead of zero
4. Otherwise, add one to the front pointer;

Alternative answer 2

1. Check the queue is (not already) empty;


2. Add one to the front pointer;
3. Compare the value of the front pointer with the maximum size of the
array;
4. If equal then front pointer becomes zero; A. index of the first position in
the array instead of zero

Alternative answer 3

1. Check the queue is (not already) empty;


2. Add one to the front pointer;
3. Compare the value of the front pointer with the maximum size of the
array plus one;
4. If equal then front pointer becomes zero; A. index of the first position in
the array instead of one

Alternative answer 4

1. Check the queue is (not already) empty;


2. Add one to the front pointer;
3. Use modulus/modulo operator/function with new value of front pointer;
4. Use modulus/modulo operator/function with maximum size of array;

Max 3 if any errors


4

(b) All marks for AO1 (understanding)

Static data structures have storage size determined at compile-time / before


program is run / when program code is translated / before the data structure is
first used
//
dynamic data structures can grow / shrink during execution / at run-time
//
static data structures have fixed (maximum) size // size of dynamic data
structures can change;

Static data structures can waste storage space / memory if the number of data
items stored is small relative to the size of the structure
//
dynamic data structures only take up the amount of storage space required for
the actual data;

Dynamic data structures require (memory to store) pointers to the next item(s)
// static data structures (typically) do not need (memory to store) pointers;

Static data structures (typically) store data in consecutive memory locations //


dynamic data structures (typically) do not store data in consecutive memory
locations;

Max 3
3

Page 56 of 64
(c) Mark is for AO2 (apply)

Jib;
1

(d) Mark is for AO2 (apply)

Jib;
1

(e) All marks for AO1 (understanding)

(Until the queue is empty) repeatedly remove / delete (the front item) from the
queue and push it on to the stack;

(Until the stack is empty) repeatedly pop items from the stack and add them to
the (rear of the) queue;
2
[11]

Q18.
All marks AO1 (understanding)

1. Check the queue is not already full;


2. Compare the value of the (rear) pointer with the maximum size of the array;
3. If equal then (rear) pointer becomes zero; A. index of the first position in the array
instead of zero
4. Otherwise, add one to the (rear) pointer;
5. Insert new item in position indicated by (rear) pointer;

Alternative answer 1

1. Check the queue is not already full;


2. Compare the value of the (rear) pointer with the maximum size of the array minus
one;
3. If equal then (rear) pointer becomes one; A. index of the first position in the array
instead of one
4. Otherwise, add one to the (rear) pointer;
5. Insert new item in position indicated by (rear) pointer;

Alternative answer 2

1. Check the queue is not already full;


2. Add one to the (rear) pointer;
3. Compare the value of the (rear) pointer with the maximum size of the array;
4. If equal then (rear) pointer becomes zero; A. index of the first position in the array
instead of zero
5. Insert new item in position indicated by (rear) pointer;

Alternative answer 3

1. Check the queue is not already full;


2. Add one to the (rear) pointer;
3. Compare the value of the (rear) pointer with the maximum size of the array plus
one;
4. If equal then (rear) pointer becomes one; A. index of the first position in the array
instead of one
5. Insert new item in position indicated by (rear) pointer;

Page 57 of 64
Alternative answer 4

1. Check the queue is not already full;


2. Add one to the (rear) pointer;
3. Use modulus/modulo operator/function with new value of (rear) pointer;
4. Use modulus/modulo operator/function with maximum size of array;
5. Insert new item in position indicated by (rear) pointer;

Max 4 if any errors


[5]

Q19.
All marks for AO1 (understanding)

Check that the queue is not already full;

(if it isn’t) then add 1 to the value of the rear pointer;

then add the new item to the position indicated by the rear pointer;

Alternative answer
Check that the queue is not already full;

(if it isn’t) then add the new item to the position indicated by the rear pointer;

then add 1 to the value of the rear pointer;

Max 2 if any errors


Max 1 if circular queue has been described
[3]

Q20.
(a) Values/cards need to be taken out of the data structure from the opposite end
that they are put in // cards removed from top/front and added at
end/bottom/rear;
Values/cards need to be removed in the same order that they are added;
A. It is First In First Out // It is FIFO;
A. It is Last In Last Out // It is LILO;
Max 1

(b) (i) FrontPointer = 13


RearPointer = 52
QueueSize = 40
1 mark for all three values correct
1

(ii) FrontPointer = 13
RearPointer = 3
QueueSize = 43

1 mark for all three values correct


A. Incorrect value for FrontPointer if it matches the value given in part
(i) and incorrect value for QueueSize if it is equal to the value given for
QueueSize in part (i) incremented by three (follow through of errors
previously made). However, RearPointer must be 3.
1

Page 58 of 64
(c) If DeckQueue is empty THEN
Report error
ELSE
Output DeckQueue[FrontPointer]
Decrement QueueSize
Increment FrontPointer
IF FrontPointer > 52 THEN
FrontPointer ← 1
ENDIF
ENDIF

1 mark for IF statement to check if queue is empty – alternative for test is


QueueSize = 0.
1 mark for reporting an error message if the queue is empty // dealing with the
error in another sensible way – this mark can still be awarded if there is an
error in the logic of the IF statement, as long as there is an IF statement with
a clear purpose.
1 mark for only completing the rest of the algorithm if the queue is not empty –
this mark can still be awarded if there is an error in the logic of the IF
statement, as long as there is an IF statement with a clear purpose.
1 mark for outputting the card at the correct position
1 mark for incrementing FrontPointer and decrementing QueueSize
1 mark for IF statement testing if the end of the queue has been reached
1 mark for setting FrontPointer back to 1 if this is the case – this mark can
still be awarded if minor error in logic of IF statement, eg >= instead of =
A. FrontPointer = (FrontPointer MOD 52) + 1 for 3 marks or
FrontPointer = (FrontPointer MOD 52) for 2 marks, both as alternatives
to incrementing and using and the second IF statement – deduct 1 mark from
either of the above if QueueSize has not been decremented
A. Any type of brackets for array indexing
I. Additional reasonable ENDIF Statements
MAX 5 unless all of the steps listed above are carried out and algorithm fully
working
6
[9]

Q21.
All marks AO1 (understanding)

(Starting at LHS of expression) push values/operands on to stack; R. if operators are also


pushed onto stack, unless they are immediately popped off the stack

Each time operator reached pop top two values off stack (and apply operator to them) //
Each time operator reached pop required number of values off stack (and apply operator
to them);

Push result (of applying operator) to stack;

When end of expression is reached the top item of the stack is the result // when end of
expression is reached pop one value off the stack;

Max 3 if any errors

Max 3 if more than one stack used

Note for examiners: Award 0 marks if description is not about a stack / LIFO structure
even if the word “stack” has been used.

Page 59 of 64
[4]

Q22.

(a) Connected // There is a path between each pair of vertices;


Undirected // No direction is associated with each edge;
Has no cycles // No (simple) circuits // No closed chains // No closed paths in
which all the edges are different and all the intermediate vertices are different
// No route from a vertex back to itself that doesn’t use an edge more than
once or visit an intermediate vertex more than once;
A no loops
Alternative definitions:
A simple cycle is formed if any edge is added to graph;
Any two vertices can be connected by a unique simple path;
Max 1

(b) No route from entrance to exit / through maze;


Maze contains a loop/circuit ;
A more than one route through maze;
Part of the maze is inaccessible / enclosed;
R Responses that clearly relate to a graph rather than the maze
Max 1

(c)

(allow some symbol in the central diagonal to indicate unused)

or

(with the shaded portion in either half – some indication must be made that
half of the matrix is not being used. This could just be leaving it blank, unless
the candidate has also represented absence of an edge by leaving cells blank)

1 mark for drawing a 7x7 matrix, labelled with indices on both axis and filled
only with 0s and 1s, or some other symbol to indicate presence/absence of
edge. e.g. T/F. Absence can be represented by an empty cell.
1 mark for correct values entered into matrix, as shown above;
2
(d) (i) Routine defined in terms of itself // Routine that calls itself;

Page 60 of 64
A alternative names for routine e.g. procedure, algorithm
NE repeats itself
1

(ii) Stores return addresses;


Stores parameters;
Stores local variables; NE temporary variables
Stores contents of registers;
A To keep track of calls to subroutines/methods etc.

Max 1

Procedures / invocations / calls must be returned to in reverse order (of


being called);
As it is a LIFO structure;
A FILO
As more than one / many return addresses / sets of values may need to
be stored (at same time) // As the routine calls itself and for each
call/invocation a new return address / new values must be stored;

Max 1
2

(e)

Page 61 of 64
1 mark for having the correct values changes in each region highlighted by a
rectangle and no incorrect changes in the region. Ignore the contents of any
cells that are not changed.

A alternative indicators that clearly mean True and False.


A it is not necessary to repeat values that are already set (shown lighter in
table)
5
[12]

Q23.
All marks AO1 (understanding)

Hash algorithm applied;


to key value; NE. to data/item
result is location in table where the record should be stored;
if location is not empty;
then use next free location; A. description of any feasible collision resolution method
[5]

Page 62 of 64
Q24.
(a) Implementation One would need to use a linear search //
would need to look at every word in the array (before the one
that is being searched for) // lookup time is proportional to
number of words in list // lookup is O(N); N.E. “search”
without further clarification that this would be linear
Implementation Two would use the hash function/hashing
to directly calculate where the word would be stored // could
jump directly to the correct position/location/index for the
word in the array // lookup time is constant regardless of how
many words in list // lookup is O(1); A. No need to go
through words in list
2

(b) The (record for) each word/both words would be stored at


the same position/index/location in the array;
A. The second word would be stored over/replace the first;
N.E. A collision has occurred

Store record/word in the next available position in the array //


store a pointer (in each array position) that points to a list of
records that have all collided at the position // rehash the
word;
A. Idea that each array position could store more than one
record e.g. five records per location, if explained.
A. Example of what “next available” might be.
R. The use of a different hashing function at all times ie not
just rehashing.
2

(c) The hash function could compute the same value/location for
more than one/two English word(s), so need to verify if the
English word stored at the location is the one that is being
looked up;
To avoid returning a French translation that is for a different
English word, which is stored at the same location as the
word that is being looked up // if a collision occurred (when
storing the words) it will not be possible to tell if the
translation is correct;

A. More than one word could be stored in each location


R. So that French to English translation can be done
MAX 1
1
[5]

Q25.
(a) Mark is for AO2 (apply)

4
//

(b) All marks AO2 (apply)

2 marks: 16

Page 63 of 64
If final answer is incorrect then award a maximum of 1 mark for working:

1 mark: for either multiplying 4 by 4 or multiplying 3 by 0


1 mark: for adding together the sum of two (incorrect) products
2

(c) All marks AO2 (analyse)

The angle will still be the same; A. the direction will not change

The magnitude will be doubled // the magnitude will now be 10;


2

(d) All marks AO2 (analyse)

The angle will be 180 – c // the angle will be 360 – 180 – c // the angle will be
143.13;

A. the direction of a will be the opposite of its current direction

The magnitude will still be the same;


2
[7]

Page 64 of 64

You might also like