P4) Topical 4.1 Computational Thinking & Problem Solving
P4) Topical 4.1 Computational Thinking & Problem Solving
P4) Topical 4.1 Computational Thinking & Problem Solving
9608/41/M/J/15
Q. 1 /- 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
ENDTYPE
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.
(ii) The algorithm for adding a name to the queue is written, using pseudocode, as a
procedure with the header:
PROCEDURE AddName(NewName)
Complete the pseudocode for the procedure RemoveName. Use the variables listed in
the identifier table.
9608/43/M/J/15
Q2/- 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:
(ii) The algorithm for adding a name to the stack is written, using pseudocode, as a
procedure with the header
9608/41/M/J/16
Q.3/- A linked list abstract data type (ADT) is to be used to store and organise
surnames.
This will be implemented with a 1D array and a start pointer. Elements of the array
consist of a user-defined type. The user-defined type consists of a data value and a link
pointer.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
The lower and upper bounds of the array are 1 and 5000 respectively.
.......................................................................................................................................[2]
9608/42/M/J/17
Q4/- An ordered binary tree Abstract Data Type (ADT) has these associated operations:
create tree
add new item to tree
traverse tree
............................................................................................................................................
........................................................................................................................................[1]
(b) The following diagram shows an ordered binary tree after the following data have
been added: Dublin, London, Berlin, Paris, Madrid, Copenhagen
(ii) Give an appropriate numerical value to represent the null pointer for this design.
Justify your answer.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[2]
(d) A program is to be written to implement the tree ADT. The variables and procedures
to be used are listed below:
TYPE Node
.................................................................................................................................
................................................................................................................................
.................................................................................................................................
ENDTYPE
PROCEDURE CreateTree()
.................................................................................................................................
.................................................................................................................................
..............................................................................................................................
..............................................................................................................................
ENDFOR
.....................................................................................................................................
ENDPROCEDURE [7]
IF FreePointer .................................................................................................
THEN
OUTPUT("No free space left")
ELSE // add new data item to first node in the free list
NewNodePointer ← FreePointer
.................................................................................................................................
// adjust free pointer
FreePointer ← .................................................................................................
....................................................................................................................
Index ← RootPointer
IF Direction = "Left"
THEN // add new node on left
.......................................................................................................
9608/41/M/J/1
Answers:
Q1/-
9608/43/M/J/15
Q2/-
9608/41/M/J/16
Q.3/-
9608/42/M/J/17
Q4/- Answers