Question 2

OCR Computer Science June 2019 Paper 2A level22 marks

On the specification

(a)(i)
1.4 Data types, data structures and algorithms
(a)(ii)
1.4 Data types, data structures and algorithms2.3 Algorithms
(a)(iii)
2.2 Problem solving and programming2.3 Algorithms
(b)(i)
1.4 Data types, data structures and algorithms
(b)(ii)
1.4 Data types, data structures and algorithms2.3 Algorithms
(b)(iii)
1.4 Data types, data structures and algorithms2.3 Algorithms
(b)(iv)
2.3 Algorithms1.4 Data types, data structures and algorithms
Question text

2 A program needs to store the names of plants that are in a garden, so they can be easily found and accessed in alphabetical order. The data is stored in a tree structure. Part of the tree is shown. Lily Daisy Sunflower Begonia Hosta Peony Rose Fig. 2.1 (a) (i) State the type of tree shown in Fig. 2.1. [1] (ii) Show the output of a breadth-first traversal of the tree shown in Fig. 2.1. [3] (iii) Explain how backtracking is used in a depth-first (post-order) traversal. Use the tree in Fig. 2.1 in your explanation. [4] (b) The elements in the tree in Fig. 2.1 are read into a linked list producing an alphabetised list. (i) Complete the following table to show the linked list for the data. Data Data NextPointer item 0 Begonia 1 Daisy 2 Hosta 3 Lily 4 Peony 5 Rose 6 Sunflower [2] (ii) A new plant, Lavender, needs adding to the linked list. The linked list needs to retain its alphabetical order. Complete the table to show the linked list after Lavender is added. Data Data NextPointer item 0 Begonia 1 Daisy 2 Hosta 3 Lily 4 Peony 5 Rose 6 Sunflower [3] (iii) Hosta needs removing from the linked list. Explain how a data item is removed from a linked list. Use the removal of Hosta in your answer. [4] (iv) The linked list is stored as a 2D array with the identifier plantList. The index of the first element of the linked list is stored in the identifier firstElement. All contents of the linked list need to be output in alphabetical order. Write an algorithm to follow the pointers to output the contents of the linked list in alphabetical order. Add comments to explain your code. [5]