Question 5
OCR Computer Science June 2025 Algorithms and programming (H446-02)A level11 marks
On the specification
- (a)
- 1.4 Data types, data structures and algorithms2.1 Elements of computational thinking
- (b)
- 2.3 Algorithms
- (c)
- 2.3 Algorithms2.2 Problem solving and programming
Question text
5 A program is being written that allows users to travel between different planets in a virtual world. Spaceships are used to travel between planets and there are only set routes that they use. Fig. 5 shows a directed graph. The nodes represent the different planets and the edges represent the routes the spaceships can travel. The arrows on the edges show which way the spaceships can travel. For example, a spaceship can travel from planet B to planet C, but not from planet C to planet B. The value on each edge is the cost in space dollars to travel on that route. Fig. 5 5 H B C 12 3 10 5 D E G A 5 7 20 F (a) Explain why this graph is a visualisation of the problem. [2] (b) A user needs to travel from planet A to planet H. They need to travel the least expensive route. Show how Dijkstra’s algorithm can be used on the directed graph shown in Fig. 5 to find the shortest path from start planet A to the end planet H. You must state the nodes on the final path and the distance of this path. Show your working. You may use the table to give your answer. Node Distance travelled Previous node Final path: Distance: [7] (c) The A* algorithm can also be used to find the shortest path in a graph. Describe how an A* algorithm uses heuristics to be an efficient algorithm. [2]