Question 2
AQA Computer Science November 2021 Paper 1 (7517/1)A level36 marks
On the specification
- 2.1
- 4.2 Fundamentals of data structures
- 2.2
- 4.3 Fundamentals of algorithms
- 2.3
- 4.3 Fundamentals of algorithms4.2 Fundamentals of data structures
- 2.4
- 4.1 Fundamentals of programming
- 2.5
- 4.1 Fundamentals of programming
- 2.6
- 4.1 Fundamentals of programming
Question text
2 Figure 1 shows a binary tree containing seven nodes. Figure 2 shows how the binary tree in Figure 1 could be represented using three one-dimensional arrays: Data, Dir1 and Dir2. Figure 1 Figure 2 Index Data Dir1 Dir2 [0] C 1 4 [1] I 2 3 [2] E -1 -1 [3] H -1 -1 [4] B 5 6 [5] Y -1 -1 [6] Q -1 -1 2.1 Define the term binary tree. [2 marks] 2.2 The output of a post-order traversal algorithm used to print the data item at each node in the binary tree shown in Figure 1 would be E, H, I, Y, Q, B, C. State the output that would be produced by an in-order traversal algorithm. [2 marks] Figure 3 shows pseudo-code for a subroutine called Traversal that uses the three arrays from Figure 2. Figure 3 SUBROUTINE Traversal(StartNode) Current StartNode Pos 0 Stack[Pos] Current WHILE Pos ≠ -1 Current Stack[Pos] Pos Pos – 1 OUTPUT Data[Current] IF Dir2[Current] ≠ -1 THEN Pos Pos + 1 Stack[Pos] Dir2[Current] ENDIF IF Dir1[Current] ≠ -1 THEN Pos Pos + 1 Stack[Pos] Dir1[Current] ENDIF ENDWHILE ENDSUBROUTINE 2.3 Complete the unshaded cells in Table 2 to show the result of the subroutine call Traversal(0) Table 2 Stack Current Pos [0] [1] [2] [3] Output Copy the contents of the unshaded cells in Table 2 into the table in your Electronic Answer Document. [7 marks] Figure 3 (repeated) SUBROUTINE Traversal(StartNode) Current StartNode Pos 0 Stack[Pos] Current WHILE Pos ≠ -1 Current Stack[Pos] Pos Pos – 1 OUTPUT Data[Current] IF Dir2[Current] ≠ -1 THEN Pos Pos + 1 Stack[Pos] Dir2[Current] ENDIF IF Dir1[Current] ≠ -1 THEN Pos Pos + 1 Stack[Pos] Dir1[Current] ENDIF ENDWHILE ENDSUBROUTINE 2.4 The subroutine shown in Figure 3 could have been written so that it used recursion instead of iteration. Explain what is meant by a recursive subroutine. [1 mark] 2.5 Explain what is meant by a base case for a recursive subroutine. [1 mark] 2.6 If the subroutine shown in Figure 3 had been written using recursion, a stack frame would have been stored each time a recursive subroutine call was made. State two components of a stack frame. [2 marks]