10.4 ADTs (AS) (MT-L) Topical
10.4 ADTs (AS) (MT-L) Topical
9618/22/M/J/21
1. The following diagram represents an Abstract Data Type (ADT).
............................................................................................................................................. [1]
(b) Give the technical term for the item labelled A in the diagram.
............................................................................................................................................. [1]
(c) Give the technical term for the item labelled B in the diagram.
Term ..........................................................................................................................................
Meaning ....................................................................................................................................
...................................................................................................................................................
.................................................................................................................................................[2]
(d) Complete the diagram to show the ADT after the data has been sorted in alphabetical order.
[2]
9618/22/M/J/21
2. The following diagram represents an Abstract Data Type (ADT) for a linked list.
(a) Explain how a node containing data value B is added to the list in alphabetic sequence.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
(b) Describe how the linked list in part (a) may be implemented using variables and arrays.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
9618/22/M/J/23
3 A program stores data in a text file. When data is read from the file, it is placed in a queue.
(a) The diagram below represents an Abstract Data Type (ADT) implementation of the queue.
Each data item is stored in a separate location in the data structure. During initial design, the
queue is limited to holding a maximum of 10 data items.
The Front of Queue Pointer points to the next data item to be removed.
The End of Queue Pointer points to the last data item added.
The queue is circular so that locations can be reused.
(i) Describe how the data items Orange and Yellow are added to the queue shown in the
diagram.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]
(ii) The following diagram shows the state of the queue after several operations have been
performed. All queue locations have been used at least once.
..................................................................................................................................... [1]
(b) The design of the queue is completed and the number of locations is increased.
A function AddToQueue() has been written. It takes a string as a parameter and adds this to the
queue. The function will return TRUE if the string was added successfully.
A procedure FileToQueue() will add each line from the file to the queue. This procedure will end
when all lines have been added or when the queue is full.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [5]
9618/21/M/J/24
4 The diagram shows an Abstract Data Type (ADT) representation of a linked list after data
items
have been added.
PS is the start pointer.
PF is the free list pointer.
Labels Df, Dc, Db and Dy represent the data items of nodes in the list.
Labels Fg, Fh, Fm and Fw represent the data items of nodes in the free list.
The symbol Ø represents a null pointer.
(a) Describe the linked list immediately after initialisation, before any data items are added.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
(b) A program will be written to include a linked list to store alphanumeric user IDs.
The design uses two variables and two 1D arrays to implement the linked list.
Each array element contains data of a single data type and not a record.
................................................................................................................................................. .
9618/21/O/N/21
5 (a) The diagram below represents a queue Abstract Data Type (ADT) that can hold a
maximum of eight items.
The operation of this queue may be summarised as follows:
The front of queue pointer points to the next item to be removed.
The end of queue pointer points to the last item added.
The queue is circular so that empty storage elements can be reused.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) Describe how the next item in the given queue is removed and stored in the variable
AnimalName.
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(iii) Describe the state of the queue when the front of queue and the end of queue pointers
have the same value.
...........................................................................................................................................
..................................................................................................................................... [1]
(b) Some operations are carried out on the original queue given in part (a).
Complete the diagram to show the state of the queue after the following operations:
Add “Wasp”, “Bee” and “Mouse”, and then remove two data items. [3]
(ii) The state of the queue after other operations are carried out is shown:
Complete the following diagram to show the state of the queue after the following operations:
[2]
(c) The queue is implemented using a 1D array.
Describe the algorithm that should be used to modify the end of queue pointer when adding an
item to the queue.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
9608/41/M/J/15
Q. 6 /- A queue Abstract Data Type (ADT) has these associated operations:
create queue
add item to queue
remove item from queue
CreateQueue
AddName("Ali")
AddName("Jack")
AddName("Ben")
AddName("Ahmed")
RemoveName
AddName("Jatinder")
RemoveName
Add appropriate labels to the diagram to show the final state of the queue. Use the
space on the left as a workspace. Show your final answer in the node shapes on the
right:
TYPE Node
DECLARE Name : STRING
DECLARE Pointer : INTEGER
END TYPE
The statement
(i) The CreateQueue operation links all nodes and initialises the three pointers that
need to be used: HeadPointer, TailPointer and FreePointer.
Complete the diagram to show the value of all pointers after CreateQueue has been
executed.
9608/43/M/J/15
Q7/- A stack Abstract Data Type (ADT) has these associated operations:
create stack
add item to stack (push)
remove item from stack (pop)
(a) There is one pointer: the top of stack pointer, which points to the last item added to
the stack.
Draw a diagram to show the final state of the stack after the following operations are
carried out.
Add appropriate labels to the diagram to show the final state of the stack. Use the space
on the left as a workspace. Show your final answer in the node shapes on the right:
TYPE Node
DECLARE Name: STRING
DECLARE Pointer: INTEGER
END TYPE
The Statement
(i) The CreateStack operation links all the nodes and initializes
TopOfStackPointer and FreePointer.
Complete the diagram to show the value of all Pointers after CreateStack
has been executed.
[4]
9618/21/O/N/22
8 (a) The following diagram shows an Abstract Data Type (ADT) representation of an ordered
linked list. The data item stored in each node is a single character. The data will be accessed in
alphabetical order.
The symbol Ø represents a null pointer.
(i) Nodes with data 'A' and 'K' are added to the linked list. Nodes with data 'J' and 'L' are
deleted.
After the changes, the data items still need to be accessed in alphabetical order.
Complete the diagram to show the new state of the linked list.
[4]
(ii) The original data could have been stored in a 1D array in which each element stores a
character.
For example:
Explain the advantages of making the changes described in part (a)(i) when the data is stored
in the linked list instead of an array.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(iii) Explain the disadvantages of making the changes described in part (a)(i) when the data is
stored in the linked list instead of an array.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
9618/21/O/N/23
The TopOfStack pointer points to the last item added to the stack.
The BottomOfStack pointer points to the first item on the stack.
(a) The stack is implemented using two variables and a 1D array of 8 elements as shown.
The variables are used to reference individual elements of the array, in such a way that:
the array is filled from the lowest indexed element towards the highest
all the elements of the array are available for the stack.
Complete the diagram to represent the state of the stack as shown above.
[3]
9(b) A function Push() will add a value onto the stack by manipulating the array and variables
in part (a).
Before adding a value onto the stack, the algorithm will check that space is available.
If the value is added to the stack, the function will return TRUE, otherwise it will return FALSE.
5. Return .............................. .
[5]
9618/22/M/J/21
ANSWERS
Q1
Question Answer Marks
(a) Linked list [1]
(b) Start pointer [1]
(d)
[2]
9618/21/M/J/21
2(a) One mark per point:
ALTERNATIVE:
Define a record type comprising a data element and a pointer and declare an array (1D) of
this type
An integer variable to hold the start pointer and an integer variable to store the next free
pointer
[2]
9618/22/M/J/23
3(a)(i) One mark per point:
1 Check that the queue is not full
2 EoQ pointer will move to point to location 9
3 Data item Orange will be stored in location referenced by EoQ pointer
4 EoQ pointer will move to point to location 0
5 Data item Yellow will be stored in location referenced by EoQ pointer
[4]
Note: max 4 marks
3(a)(ii) 7 [1]
9618/21/O/N/21
5(a)(i) One mark per point:
EoQ pointer will move to point to location 4 // incremented EoQ (by 1)
Data value "Octopus" will be stored in location pointed to be EoQ / location 4
[2]
5(a)(ii) One mark for each bullet
Value "Frog" // value pointed to by FoQ / location 0 is assigned to variable AnimalName
FoQ pointer will move to point to location 1 / point to "Cat" // incremented FoQ (by 1)
5(b)(i) One mark for data values plus one mark for pointers
[2]
9608/43/M/J/15
Q7/-
Q8 (a)
One mark for each:
1 Data A and K stored in new / existing nodes
2 Start pointer points to Node A
3 Node A points to Node C and Node C points to Node K
4 Node K contains Null Pointer
[4]
8(a)(ii)
One mark per point:
1 Pointers determine the ordering of data // only the pointers need to be changed when data
changed
2 Easier to add / delete data (to maintain correct sequence) in a linked list // description of
moving data to maintain correct sequence when array used [2]
8(a)(iii)
One mark per point:
1 Need to store pointers as well as data
2 More complex (to setup / implement) [2]
9618/21/O/N/23
Q9 (ANSWER)
[3]
9(b)
MP1 If TopOfStack = 8 // (stack) full then return FALSE
MP2 Otherwise, increment TopOfStack
MP3 Use TopOfStack as an index to the Array
MP4 Set the element at this index / location / position to the value / data / item being added
MP5 Return TRUE [5]