Question 8

OCR Computer Science June 2025 Algorithms and programming (H446-02)A level28 marks

On the specification

(a)
1.4 Data types, data structures and algorithms
(b)(i)
2.2 Problem solving and programming1.4 Data types, data structures and algorithms
(b)(ii)
2.2 Problem solving and programming
(c)(i)
2.2 Problem solving and programming1.4 Data types, data structures and algorithms
(c)(ii)
2.3 Algorithms1.4 Data types, data structures and algorithms
(d)
2.2 Problem solving and programming2.3 Algorithms
(e)
2.3 Algorithms1.4 Data types, data structures and algorithms
(f)
2.2 Problem solving and programming
Question text

8 A linked list data structure is designed using object-oriented programming. The design includes two classes called node and linkedList. (a) Describe the features of a linked list data structure. [3] (b) The class design for node is shown here. class: node attributes: private value : integer private nextNode : node methods: new() getValue() getNextNode() setValue() setNextNode() new() is the constructor method. The constructor method takes a parameter and assigns this to the value attribute. (i) The method getNextNode() returns the attribute nextNode. Write the method getNextNode() using pseudocode or program code. [2] (ii) 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. [3] (c) The class design for linkedList is shown here. class: linkedList attributes: private headNode : node methods: new() insertNode() outputList() new() is the constructor method. The constructor initialises the attribute headNode to a null value. (i) Write the constructor method using pseudocode or program code. [2] The class design for node and linkedList are shown again here for your reference. class: node class: linkedList attributes: attributes: private value : integer private headNode : node private nextNode : node methods: methods: new() new() insertNode() getValue() outputList() getNextNode() setValue() setNextNode() (ii) 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. function outputList() returnValue = "" start = while start null returnValue = returnValue + start. () + " " start = start. () endwhile return endfunction [5] (d) 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. [5] (e) 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. [5] (f) 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. 1 2 3 [3]