Date | November 2021 | Marks available | 4 | Reference code | 21N.1.HL.TZ0.12 |
Level | HL | Paper | 1 | Time zone | no time zone |
Command term | Describe | Question number | 12 | Adapted from | N/A |
Question
Consider the following circular linked list:
where head is an external pointer that points to the first node in the circular linked list.
Three operations are performed on this circular linked list in the following order:
Arrays and linked lists are used to store linear data.
Sketch a diagram showing the resulting circular linked list.
Outline how the last node of the circular linked list is identified.
Describe the steps required to calculate the sum of all numbers held in this circular linked list.
Compare the use of arrays and linked lists.
A linked list can be used to implement a data structure queue.
Identify two applications of a queue data structure.
Markscheme
Award [3 max].
Award [1] for the node containing number 20 is pointed to by the pointer 'head';
Award [1] for the diagram showing only two nodes and all the correct links;
Award [1] for the last node containing number 5;
Award [2 max].
The last node is identified by its next/link pointer;
which contains the address of the node at the beginning of the list / is equal to the pointer “head “;
Award [4 max].
Initialize (a temporary pointer with the head and) a variable sum with 0 (zero);
Loop from the beginning to the end of the circular linked list / until all the nodes get traversed);
Add the value (of the data field) (of the current node) to the sum;
Change the temporary pointer so it points the next node of circular linked list;
Note: Answers written in pseudocode are acceptable.
For example,
sum = 0
curr = head
loop
sum = sum + curr.data
curr = curr.next
until curr == head
Award [4 max].
In an array, memory is assigned during compile time(predetermined) whilst in a linked list it is allocated during execution/runtime;
Arrays are of fixed size whilst linked lists are flexible and can expand and contract its size;
Array requires less memory (due to actual data being stored within the index in the array) whilst there is a need for more memory in linked list (due to storage of additional next and previous pointers/references);
Elements are stored consecutively in array whereas elements are stored randomly in linked lists;
Memory utilization is inefficient in the array whilst memory utilization is efficient in the linked list;
Accessing an element in an array is direct (fast) while accessing an element in linked list is sequential/linear (slower) /to get into the nth element only the array name with index within the square bracket should be written whilst a linked list (to get the nth element) should be traversed starting from the beginning of the list, and traversing through the list until found/ ;
Operations like insertion and deletion in arrays consume a lot of time whilst the performance of these operations in linked lists is fast;
Award [2 max].
Print queues (a number of print jobs on a queue instead of waiting for each one to finish before specifying the next one);
Queue is used for synchronization when data is transferred asynchronously between two processes (for example IO Buffers, file IO);
Queues are used in CPU scheduling algorithms;
Handling of interrupts in real-time systems (the interrupts are handled in the same order as they arrive, first come first served);
Computer modelling of physical queues (supermarket checkouts) (call centre phone systems use queues to hold people calling them in an order, until a service representative is free);
Examiners report
Most candidates were able to sketch a diagram showing the resulting circular linked list.
A mixed set of responses was seen for this question. Most candidates knew that the last node in a circular linked list contains a pointer to the first node of the list. A few candidates incorrectly wrote that the next of the last node point to the null.
Candidates were required to write the main steps involved in an algorithm to calculate the sum of all numbers held in the circular linked list. Many candidates were well prepared, some candidates even wrote their answers in algorithmic form and they generally achieved better results than those who simply described the steps. The full range of marks, from zero to four were achieved for this question.
Was reasonably well answered with many gaining at least two of the marking points. Some candidates described two data structures individually without performing any comparison and thus losing marks.
Was well answered.