Question 7

OCR Computer Science June 2024 Algorithms and programming (H446-02)A level13 marks

On the specification

(a)
1.4 Data types, data structures and algorithms
(b)(i)
1.4 Data types, data structures and algorithms
(b)(ii)
1.4 Data types, data structures and algorithms
(b)(iii)
2.3 Algorithms
(b)(iv)
1.4 Data types, data structures and algorithms2.3 Algorithms
Question text

7 A computer game stores tasks that the player has requested. Each task has: • an identification (ID) number e.g. Task A • a real number to be processed e.g. 123456.789 • an integer number to represent the order the tasks should be accessed e.g. 1. The task that needs to be processed the earliest is given the order number 1. Two or more tasks can have the same order number. For example, two tasks can have an order number 1. (a) The data about each task needs to be stored. This will store the ID number, data value and order number for a task. Explain why a record data structure is suitable for this data. [2] (b) The tasks will be stored in a binary search tree before they are processed. They are stored in ascending order by their order number. (i) Give two characteristics of a binary search tree. 1 2 [2] (ii) Give an advantage of storing the tasks in a binary search tree instead of a 1-dimensional array. [1] (iii) Tick (3) one column in each row to identify whether each statement applies to a depth-first (post-order) tree traversal, a breadth-first tree traversal, or neither of these two traversals, when performed on a binary search tree. Neither of Depth-first Breadth- Statement these two (post-order) first traversals All nodes at the current depth are visited before moving to the next depth The algorithm traverses to the end of one branch before moving to another branch The algorithm will make use of backtracking The traversal can be used to output the contents of the tree in ascending order The algorithm will output the root node last [5] (iv) The tasks currently stored in the binary search tree are shown here. When a new task is inserted with the same order number as a pre-existing task, it is classed as having a higher order number. For example, task G has the same order number as task A. Since task G was inserted after task A it is classed as a higher number. Change the diagram to show the contents of the binary search tree after the following tasks are inserted in the order given: • Task X with order number 12 • Task Y with order number 7 • Task Z with order number 11 Task A Order 6 Task B Task D Order 3 Order 9 Task E Task C Task F Task H Order 1 Order 5 Order 7 Order 10 Task I Task G Order 2 Order 6 [3]