Past-paper question · 2015 May-June · Paper 42 · Q6(b)(ii)

Question 6(b)(ii) 2015 · May-June · Paper 42 · 6 marks

Original past-paper question for 6(B)(II)
Original past-paper question for 6(B)(II)
Original past-paper question for 6(B)(II)
Original past-paper question for 6(B)(II)
Reveal official mark-scheme answer

The answer for this question is in the official mark scheme: open the mark scheme.

Mark scheme 9608_s15_ms_42.pdf →

Show text version of question

Question 6

Part (b)

(ii)

Question 6

A queue Abstract Data Type (ADT) has these associated operations:

  • create queue
  • add item to queue
  • remove item from queue

The queue ADT is to be implemented as a linked list of nodes.

Each node consists of data and a pointer to the next node. Using pseudocode, a record type, Node, is declared as follows:

TYPE Node DECLARE Name : STRING DECLARE Pointer : INTEGER ENDTYPE

The statement

DECLARE Queue : ARRAY[1:10] OF Node

reserves space for 10 nodes in array Queue.

(ii)

The algorithm for adding a name to the queue is written, using pseudocode, as a

procedure with the header:

PROCEDURE AddName(NewName)

where NewName is the new name to be added to the queue.

The procedure uses the variables as shown in the identifier table.

Identifier Data type Description Queue Array[1:10] OF Node Array to store node data NewName STRING Name to be added FreePointer INTEGER Pointer to next free node in array HeadPointer INTEGER Pointer to first node in queue TailPointer INTEGER Pointer to last node in queue CurrentPointer INTEGER Pointer to current node

PROCEDURE AddName(BYVALUE NewName : STRING) // Report error if no free nodes remaining IF FreePointer = 0 THEN Report Error ELSE // new name placed in node at head of free list CurrentPointer ← FreePointer Queue[CurrentPointer].Name ← NewName // adjust free pointer FreePointer ← Queue[CurrentPointer].Pointer // if first name in queue then adjust head pointer IF HeadPointer = 0 THEN HeadPointer ← CurrentPointer ENDIF // current node is new end of queue Queue[CurrentPointer].Pointer ← 0 TailPointer ← CurrentPointer ENDIF ENDPROCEDURE

Question 16

Complete the pseudocode for the procedure RemoveName. Use the variables listed in the identifier table.

PROCEDURE RemoveName() // Report error if Queue is empty ........................................................................................................................... ........................................................................................................................... ........................................................................................................................... ........................................................................................................................... OUTPUT Queue[…………………………………………………………].Name // current node is head of queue ........................................................................................................................... // update head pointer ........................................................................................................................... // if only one element in queue then update tail pointer ........................................................................................................................... ........................................................................................................................... ........................................................................................................................... ........................................................................................................................... // link released node to free list ........................................................................................................................... ........................................................................................................................... ........................................................................................................................... ENDPROCEDURE

[6]

effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after the live examination series.

Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.

Topic relevance

Why this question appears here

91% assigned-topic match · Data types and structures › Introduction to abstract data types

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9608_s15_qp_42.pdf

Keep practising this topic