Question 3
AQA Computer Science June 2025 Paper 1 (7517/1)A level18 marks
On the specification
- 3.1
- 4.3 Fundamentals of algorithms
- 3.2
- 4.2 Fundamentals of data structures
- 3.3
- 4.2 Fundamentals of data structures
- 3.4
- 4.1 Fundamentals of programming
- 3.5
- 4.3 Fundamentals of algorithms4.1 Fundamentals of programming
Question text
3.1 State the purpose of Dijkstra’s algorithm. [1 mark] Figure 1 shows a graph containing seven nodes. Figure 1 3.2 State both the reasons why the graph in Figure 1 is not a tree. [2 marks] 3.3 Complete the unshaded cells in Table 1 to show how the graph in Figure 1 could be represented as an adjacency matrix. Table 1 12 3 4 5 6 7 1 2 3 4 5 6 7 Copy the contents of the unshaded cells in Table 1 into the table in your Electronic Answer Document. [2 marks] Figure 2 shows the graph in Figure 1 represented as an adjacency list, called AL. An adjacency list is a list of lists. Figure 2 Node Index 12 3 12 3 7 21 6 31 6 7 45 54 62 3 71 3 AL[1][3] is equal to 7 as it refers to the 3rd position in the list for node 1 LENGTH(AL[6]) is equal to 2 as there are two items in the list for node 6 Figure 3 contains pseudo-code for an algorithm that finds out if there is a path between two nodes in the graph represented by the adjacency list AL. Both subroutines in the algorithm make use of an array V. Figure 3 SUBROUTINE IsPath(start, end) FOR j = 1 TO LENGTH(AL) V[j] = 0 END FOR FOR j = 1 TO LENGTH(AL) IF V[j] = 0 THEN IF Traverse(start, end) = True THEN RETURN True END IF END IF END FOR RETURN False END SUBROUTINE SUBROUTINE Traverse(start, end) IF start = end THEN RETURN True END IF V[start] = 1 FOR i = 1 TO LENGTH(AL[start]) IF V[AL[start][i]] = 0 THEN IF Traverse(AL[start][i], end) = True THEN RETURN True END IF END IF END FOR RETURN False 3.4 Describe one of the base cases for the recursive subroutine Traverse. [1 mark] Figure 4 shows a trace table for the subroutine call Traverse(1, 6) The subroutine call will return a value of True as there is a path from node 1 to node 6 in the graph shown in Figure 1, on page 3. Figure 4 V Subroutine call to i 1 2 3 4 5 6 7 Traverse 0 0 0 0 0 0 Traverse(1, 6) 1 1 Traverse(2, 6) 1 1 2 Traverse(6, 6) Figures 2 and 3 are repeated here to help you answer Question 03.5. Figure 2 Node Index 12 3 12 3 7 21 6 31 6 7 45 54 62 3 71 3 Figure 3 SUBROUTINE IsPath(start, end) FOR j = 1 TO LENGTH(AL) V[j] = 0 END FOR FOR j = 1 TO LENGTH(AL) IF V[j] = 0 THEN IF Traverse(start, end) = True THEN RETURN True END IF END IF END FOR RETURN False END SUBROUTINE SUBROUTINE Traverse(start, end) IF start = end THEN RETURN True END IF V[start] = 1 FOR i = 1 TO LENGTH(AL[start]) IF V[AL[start][i]] = 0 THEN IF Traverse(AL[start][i], end) = True THEN RETURN True END IF END IF END FOR RETURN False END SUBROUTINE 3.5 Complete the unshaded cells in Table 2 to show the result of tracing the algorithm shown in Figure 3 using the adjacency list AL in Figure 2 for the subroutine call IsPath(3, 7) Table 2 V Subroutine call to j i 1 2 3 4 5 6 7 Traverse Copy the contents of the unshaded cells in Table 2 into the table in your Electronic Answer Document. [6 marks] 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.