Question 4
AQA Computer Science June 2022 Paper 1 (7517/1)A level15 marks
On the specification
- 4.1
- 4.3 Fundamentals of algorithms4.4 Theory of computation
- 4.2
- 4.1 Fundamentals of programming
- 4.3
- 4.3 Fundamentals of algorithms
- 4.4
- 4.2 Fundamentals of data structures
- 4.5
- 4.3 Fundamentals of algorithms4.1 Fundamentals of programming
Question text
4.1 For each of the statements in Table 2, complete each row to indicate if the statement is true or false for Dijkstra’s algorithm. Table 2 True or False? Calculates the shortest path between a node and other nodes in a graph. Can be used to prove that the Halting Problem cannot be solved. Can be used with both directed and undirected graphs. Can be used with both weighted and unweighted graphs. Copy the contents of the unshaded cells in Table 2 into the table in your Electronic Answer Document. [2 marks] Figure 3 shows a subroutine represented using pseudo-code. The subroutine makes use of an array Visited and an array ConnectedNodes that stores a graph represented as an adjacency list. Figure 3 FUNCTION G(V, P) Visited[V] True FOR EACH N IN ConnectedNodes[V] IF Visited[N] = False THEN IF G(N, V) = True THEN RETURN True ENDIF ELSE IF N ≠ P THEN RETURN True ENDIF ENDFOR RETURN False ENDFUNCTION 4.2 The subroutine G uses recursion. Explain what is meant by a recursive subroutine. [1 mark] Figure 3 (repeated) FUNCTION G(V, P) Visited[V] True FOR EACH N IN ConnectedNodes[V] IF Visited[N] = False THEN IF G(N, V) = True THEN RETURN True ENDIF ELSE IF N ≠ P THEN RETURN True ENDIF ENDFOR RETURN False ENDFUNCTION Figure 4 shows a subroutine represented using pseudo-code. The subroutine makes use of the array Visited. Figure 4 FUNCTION F() FOR Count 0 TO LENGTH(Visited) - 1 IF Visited[Count] = False THEN RETURN False ENDIF ENDFOR RETURN True ENDFUNCTION Figure 5 shows a subroutine represented using pseudo-code. The subroutine makes use of the subroutine G shown in Figure 3, the subroutine F shown in Figure 4 and the array Visited. Figure 5 FUNCTION E() Set all elements of Visited to False IF G(0, -1) = True THEN RETURN False ELSE RETURN F() ENDIF ENDFUNCTION Figure 6 shows a graph consisting of three nodes, the contents of the array ConnectedNodes when it is used to represent this graph, and the contents of the array Visited after the subroutine call G(0, -1). Figure 6 4.3 Complete the unshaded cells in Table 3 to show the result of the subroutine call F() when it is applied using the graph shown in Figure 6. Table 3 Value Count returned Copy the contents of the unshaded cells in Table 3 into the table in your Electronic Answer Document. [2 marks] Figure 7 shows a graph consisting of four nodes and the contents of the array ConnectedNodes when it is used to represent this graph. Figure 7 4.4 Complete the unshaded cells in Table 4 to show how the graph in Figure 7 would be represented as an adjacency matrix. Table 4 1 2 3 0 1 2 3 Copy the contents of the unshaded cells in Table 4 into the table in your Electronic Answer Document. [1 mark] Figure 3 (repeated) FUNCTION G(V, P) Visited[V] True FOR EACH N IN ConnectedNodes[V] IF Visited[N] = False THEN IF G(N, V) = True THEN RETURN True ENDIF ELSE IF N ≠ P THEN RETURN True ENDIF ENDFOR RETURN False ENDFUNCTION 4.5 Complete the unshaded cells in Table 5 to show the result of the subroutine call G(0, -1) on the graph shown in Figure 7. Some parts of the table, including the initial values in the Visited array, have been completed for you. Table 5 Visited Subroutine V P [0] [1] [2] [3] N call False False False False G(0, -1) Final value returned: Copy the contents of the unshaded cells in Table 5 into the table in your Electronic Answer Document. [6 marks] 4.6 What is the purpose of the subroutine G? [1 mark] 4.7 State the type of graph traversal used in subroutine G. [1 mark] 4.8 If the graph represented by ConnectedNodes is undirected, what can you determine about the graph when a value of True is returned by subroutine E? [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.