Algorithms and programming June 2025, Question 8 40 marks
Also involves Arrays · Linked lists
A linked list data structure is designed using object-oriented programming.
The design includes two classes called node and linkedList.
Describe the features of a linked list data structure.
Reveal mark scheme
The class design for node is shown here.
new() is the constructor method. The constructor method takes a parameter and assigns this to the value attribute.
The method getNextNode() returns the attribute nextNode.
Write the method getNextNode() using pseudocode or program code.
Reveal mark scheme
The method setValue() takes an integer as a parameter and assigns this to the attribute value
Write the method setValue() using pseudocode or program code.
Reveal mark scheme
The class design for linkedList is shown here.
new() is the constructor method. The constructor initialises the attribute headNode to a null value.
Write the constructor method using pseudocode or program code.
Reveal mark scheme
The class design for node and linkedList are shown again here for your reference.
The method getValue() will return the value of a node. The method getNextNode() will return the next node to be accessed in the linked list.
The method outputList() traverses the linked list starting at the node headNode. The method joins the data in each node and returns it.
Complete the method outputList() using pseudocode or program code.
Reveal mark scheme
The method insertNode() will insert a new node into the linked list.
The method accepts an integer as a parameter, creates a new node with that data and inserts it into the linked list, e.g. insertNode(8) creates a node object with the data 8 and adds it to the linked list.
The program needs to store the following data items in the linked list in the order they are given: 10 25 39
The program then needs to output all of the data in the list using the appropriate method.
Write an algorithm using pseudocode or program code to:
• create a new linkedList object with the identifier createList
• insert each of the data items into the linked list (10, 25, 39)
• output the content of the linked list.
Reveal mark scheme
A new method is needed to remove a node from the linked list. The method needs to take the data to remove as a parameter and then find this data in the linked list before removing the node.
Describe the steps that this method will need to follow and the decisions that need to be made in the method to remove the correct node.
Reveal mark scheme
The program developer made use of computational methods when designing the object-oriented programming solution. One computational method is divide-and-conquer.
Identify three other computational methods that the program developer could have used.
Reveal mark scheme
* This program uses classes and objects to create a linked list.
An alternative method is creating a 2-dimensional array. In this design the first index stores the data and the second element stores the index of the next data item. Array elements not currently used are also linked together to form a chain of empty values to identify where the next data item can be inserted.
Compare the two different methods of creating a linked list that have been described.
You should include the following in your answer:
• the features of both methods including the reusability of program components
• benefits and drawbacks of both methods in this program
• a conclusion evaluating the efficiency of both methods when designing a program that needs
a linked list.
Reveal mark scheme