Question 6

AQA Computer Science June 2024 Paper 1 (7517/1)A level23 marks

On the specification

6.1
4.2 Fundamentals of data structures
6.2
4.3 Fundamentals of algorithms4.2 Fundamentals of data structures
6.3
4.2 Fundamentals of data structures4.3 Fundamentals of algorithms
6.4
4.2 Fundamentals of data structures
6.5
4.3 Fundamentals of algorithms
Question text

6 Figure 3 shows a graph containing five nodes. Figure 4 shows how the graph in Figure 3 could be represented using three one-dimensional arrays: Data, Dir1 and Dir2. Figure 3 Figure 4 Index Data Dir1 Dir2 [0] U 1 4 [1] K 2 3 [2] Y –1 –1 [3] H –1 –1 [4] M –1 –1 6.1 The graph in Figure 3 is a binary tree. A binary tree is a rooted tree where each node has at most two child nodes. There are three properties that a graph needs to have for it to be a tree. One of those properties is that it contains no cycles. State the other two properties of this graph that make it a tree. [2 marks] Figure 5 contains pseudo-code for an algorithm that uses the arrays in Figure 4. Figure 5 Done  False Pos  –1 Current  0 WHILE Done = False WHILE Current ≠ –1 Pos  Pos + 1 Temp[Pos]  Current Current  Dir1[Current] ENDWHILE IF Pos = –1 THEN Done  True ELSE OUTPUT Data[Temp[Pos]] Current  Dir2[Temp[Pos]] Pos  Pos – 1 ENDIF ENDWHILE 6.2 Complete the unshaded cells in Table 1 to show the result of tracing the algorithm shown in Figure 5 using the arrays in Figure 4. Table 1 Temp Done Pos [0] [1] [2] Current OUTPUT Copy the contents of the unshaded cells in Table 1 into the table in your Electronic Answer Document. [7 marks] 6.3 The array Temp needs to be able to store three values when used with the binary tree shown in Figure 3, on page 6. For some binary trees with only five nodes, the array Temp would need to be able to store five values. Describe the structure of a five-node binary tree that would require Temp to be able to store five values. [2 marks] 6.4 State the type of data structure the algorithm shown in Figure 5 implements using the array Temp. [1 mark] 6.5 Describe the changes that need to be made to the algorithm shown in Figure 5 so that the order that the data values are output in is reversed. In your answer, you should only describe changes to the existing lines of code in the algorithm; you must not suggest the addition of extra lines of code. [1 mark] You are advised to spend no more than 20 minutes on this section. Enter your answers to Section B in your Electronic Answer Document. You must save this document at regular intervals. The question in this section asks you to write program code starting from a new program/project/file. You are advised to save your program at regular intervals.