0% found this document useful (0 votes)
267 views23 pages

A and Dijkstra Combined

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
267 views23 pages

A and Dijkstra Combined

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

1(a) A salesman travels around the country, stopping at specific places, and then returning to the starting place.

Fig 6.1 shows an example map of places that the salesman visits.

The filled in circle represents the start and end point. The letters represent the places to visit. The lines are the
routes available and the numbers are the length of time each route takes to travel.

Explain how abstraction has been applied in the production of Fig 6.1

[2]

© OCR 2024. You may photocopy this page. 1 of 23 Created in ExamBuilder


(b) The travelling salesman aims to find the shortest route between these places to visit.

A programmer is writing an algorithm to solve the travelling salesman problem.

The programmer is using a tree to find the most efficient route. Fig 6.2 shows part of the tree with three levels
completed.

(i) The ‘Start’ nodes on level three are not expanded again as this is a repeat, ‘Start’ has already been
expanded.

Write the place names in the boxes in Fig 6.2, to complete the fourth level of the tree structure for the map
shown in Fig 6.1.

[3]

(ii) Explain why the tree in Fig 6.2 is not a binary tree.

[1]

© OCR 2024. You may photocopy this page. 2 of 23 Created in ExamBuilder


(c) The programmer has decided to use a graph instead of a tree structure.

(i) Describe what is meant by a graph structure.

[2]

(ii) The pseudocode below shows part of an algorithm which uses a queue to traverse the graph breadth-first.
Complete the missing elements of the algorithm.

[4]

© OCR 2024. You may photocopy this page. 3 of 23 Created in ExamBuilder


(d) Fig 6.3 is a graph representation of the places that the travelling salesman visits. Using this graph, show how
Dijkstra's algorithm would find the shortest path from place A to place F.

[6]

© OCR 2024. You may photocopy this page. 4 of 23 Created in ExamBuilder


2(a) Fig. 2.1 shows the flight paths between a country's airports. The value in bold beneath each node is the heuristic
value from E.

State the full name of the data structure shown in Fig. 2.1.

[2]
(b) The structure in Fig. 2.1 is searched using the A* algorithm making use of the heuristic values.

(i) State what the heuristic values could represent in Fig. 2.1.

[1]

(ii) State the purpose of heuristic values in the A* algorithm.

[1]

(iii) Perform an A* algorithm on the data structure in Fig. 2.1 to find the shortest distance between H and E.
Show each step of the process, and the calculations performed for each node visited.

© OCR 2024. You may photocopy this page. 5 of 23 Created in ExamBuilder


[8]

(iv) Give one decision that is made in the A* algorithm, and describe the effect of this decision on the next step(s)
of the algorithm.

Decision _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Effect _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

[3]

© OCR 2024. You may photocopy this page. 6 of 23 Created in ExamBuilder


3(a) A puzzle has multiple ways of reaching the end solution. Fig. 3 shows a graph that represents all possible routes
to the solution. The starting point of the game is represented by A, the solution is represented by J. The other
points in the graph are possible intermediary stages.

Fig. 3

Demonstrate how Dijkstra’s algorithm would find the shortest path to the solution in Fig. 3.

© OCR 2024. You may photocopy this page. 7 of 23 Created in ExamBuilder


[7]
(b) * The creator of the puzzle has been told that the A* algorithm is more efficient at finding the shortest path
because it uses heuristics.

Compare the performance of Dijkstra’s algorithm and the A* search algorithm, making reference to heuristics, to
find the shortest path to the problem.

© OCR 2024. You may photocopy this page. 8 of 23 Created in ExamBuilder


[9]

4 Some of the characters in a game will move and interact independently. Taylor is going to use graphs to plan the
movements that each character can take within the game.

DancerGold is one character. The graph shown in Fig. 1 shows the possible movements that DancerGold can
make.

Fig. 1

DancerGold’s starting state is represented by node A. DancerGold can take any of the paths to reach the end
state represented by node G.

The number on each path represents the number of seconds each movement takes.

The number in bold below each node is the heuristic value from A.

(i) Define the term heuristic in relation to the A* algorithm.

© OCR 2024. You may photocopy this page. 9 of 23 Created in ExamBuilder


[2]

(ii) Perform an A* algorithm on the graph shown in Fig. 1 to find the shortest path from the starting node to the
end node. Show your working, the nodes visited and the distance. You may choose to use the table below to
give your answer.

Node Distance Heuristic Distance travelled + Previous node


travelled Heuristic

© OCR 2024. You may photocopy this page. 10 of 23 Created in ExamBuilder


Final path:

Distance:

[8]

© OCR 2024. You may photocopy this page. 11 of 23 Created in ExamBuilder


5(a) Fig. 5 shows a graph data structure representing a small section of a parcel delivery network. Each node
represents an address where deliveries need to be made. The edges show the possible routes and distances
between these deliveries.

Fig. 5

Give one reason why the graph is a visualisation of the problem.

[1]

© OCR 2024. You may photocopy this page. 12 of 23 Created in ExamBuilder


(b)

(i) Show how Dijkstra’s algorithm can be used on the graph shown in Fig. 5 to find the shortest path from the
start node A and the end node H.

You should state the nodes on the final path and the overall distance. Show your working.

You may choose to use the table below to give your answer.

Node Distance travelled Previous node

© OCR 2024. You may photocopy this page. 13 of 23 Created in ExamBuilder


Final path: ............................................................................

Distance: .............................................................................. [6]

(ii) Give a similarity and difference between the performance of Dijkstra’s algorithm and the performance of A*
algorithm.

Similarity

Difference

[2]

END OF QUESTION PAPER

© OCR 2024. You may photocopy this page. 14 of 23 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

1 a 1 mark per bullet to max 2 2


e.g.

Places have been replaced with


variables … (1)
… e.g. a place has been replaced with
A (1)
Irrelevant information has been
removed … (1)
… e.g. only the routes and places are
shown (1)
Time is given as a numeric value (1) …
… e.g. 1 rather than 1 hour, or 1
minute (1)
Relative geographic location may not
be accurate (1)
… e.g. positions of the towns may not
be proportional to actual distance (1)

b i 1 mark for completing A, E, F below C 3


1 mark for completing A, F below B
1 mark for completed D, C below E

ii In a binary tree a node can only have two 1


children

c i 1 mark per bullet to max 2 2

Collection of data nodes / vertices (1)


Connections / edges are set between
nodes / vertices (1)
Graph (edges) can be directional or bi-
directional (1)
Graphs (edges) can be directed or
undirected (1)

© OCR 2024. You may photocopy this page. 15 of 23 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

ii 1 mark each 4

d Max 6. 6
1 mark for final solution, max 5 for showing
the stages

Mark A as the current node (1)


Record B is 5, C is 3, D is 3 (1)
Mark A as visited (1)
C is shortest distance from A (1)
(C as current) Record E as 6, F as 6
(1)
Mark C as visited (1)
(D as current) Record E as 5 (1)
Mark D as visited (1)
(B as current) Record F as 7, do not
update table as longer (1)
Mark B as visited (1)
(E as current) Record D as 8, do not
update table as longer and E as visited
(1)
A-C-F found as shortest (1)

Total 18

© OCR 2024. You may photocopy this page. 16 of 23 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

2 a 1 mark per bullet 2

Weighted/Undirected
Graph

b i E.g. Weighting/cost based on estimated 1


distance from final node

ii Used to speed up process of finding 1


solution

iii 1 mark per bullet, max 7 for 8


calculations/explanation, max 1 for correct
final path

Visiting H with correct heuristic


Visiting G and N from H
Calculating correct
distance+heuristic for G and N
Identifying G as the smallest value
Visiting L and M from G
Calculating distance+heuristic for L
and M
Identifying L as the smallest value
Visiting E
Calculating distance+heuristic for E
Final path: H-G-L-E

e.g.

© OCR 2024. You may photocopy this page. 17 of 23 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

iv 1 mark for decision, 2 marks for effect 3


e.g.
Decision:

Choosing which node to take next


The shortest distance+heuristic is
taken

Effect:

All adjoining nodes from this new node


are taken
Other nodes are compared again in
future checks
Assumed that this node is a shorter
distance
Adjoining nodes may not be shortest
path …
….may need to backtrack to previous
nodes

Total 15

© OCR 2024. You may photocopy this page. 18 of 23 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

3 a 1 mark per bullet 7


AO1.2
Mark A as the initial node and then visit (3)
B (5) AO2.1 Examiner’s Comments
Node E (8) is then visited (chosen from (2)
C (13), D (14), E (8)) AO2.2 Whilst many candidates were familiar with
Node I (12) is then visited after E (2) the calculations involved in Dijkstra’s
Node J (14) is then visited after I algorithm, most confined their calculations
to the shortest path ABEIJ and length 14. It
Visiting G (15) from C – was far less common for candidates to
overriding the previous value of 18 recognise that Dijkstra’s algorithm does not
stop until all nodes have been visited and
solution A-B-E-I-J path length 14 that some nodes are over-ridden with lower
values. Some candidates simply stated the
shortest route without any explanation or
calculation and this was not creditworthy.
Candidates should be encouraged to
produce clear answers in tabular format.

© OCR 2024. You may photocopy this page. 19 of 23 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

b Mark Band 3 – High level 9 AO1: Knowledge and Understanding


(7-9 marks) AO1.1 Indicative content
The candidate demonstrates a thorough (2)
knowledge and understanding of Dijkstra’s AO1.2 Heuristic helps produce a solution in a
and A*; the material is generally accurate (2) faster time
and detailed. AO2.1 A* uses estimated distance from final
The candidate is able to apply their (2) node
knowledge and understanding directly and AO3.3 Dijkstra uses a weight/distance
consistently to the context provided. (3) A* chooses which path to take next
Evidence/examples will be explicitly based on lowest current distance
relevant to the explanation. travelled
There is a well-developed line of reasoning
which is clear and logically structured. The AO2: Application
information presented is relevant and
substantiated. Description of how A* will differ from
Dijkstra, e.g. taking the shorter route A-
Mark Band 2 – Mid level B-E-I before exploring nodes from D
(4-6 marks) and E
The candidate demonstrates reasonable Description of the different number of
knowledge and understanding of Dijkstra’s comparisons that would be needed in
and A*; the material is generally accurate this problem
but at times underdeveloped. A* doesn’t need to find all possible
The candidate is able to apply their solutions (saves time)
knowledge and understanding directly to
the context provided although one or two AO3: Evaluation
opportunities are missed. Candidates will need to evaluate the
Evidence/examples are for the most part benefits and drawbacks of each algorithm
implicitly relevant to the explanation.
The candidate provides a reasonable Small-scale problem
discussion, the majority of which is Quick to find a solution using either
focused. Evaluative comments are, for the method
most part appropriate, although one or two Difference in programming complexity
opportunities for development are missed. is minimal
There is a line of reasoning presented with Don’t know if this problem needs to
some structure. The information presented scale
is in the most part relevant and supported Most efficient route needed
by some evidence.

Mark Band 1 – Low Level


(1-3 marks) Examiner’s Comments
The candidate demonstrates a basic
knowledge of Dijkstra’s and A* with limited Candidates were well prepared and had
understanding shown; the material is basic obviously used both Dijkstra’s algorithm
and contains some inaccuracies. The and the A* algorithm, and could explain
candidates makes a limited attempt to differences between them and give
apply acquired knowledge and examples of possible heuristics. Very few
understanding to the context provided. candidates could evaluate and discuss
The candidate provides a limited how the scaling of the algorithms was
discussion which is narrow in focus. relevant to access the top level mark band.

© OCR 2024. You may photocopy this page. 20 of 23 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

Judgements if made are weak and


unsubstantiated.
The information is basic and comunicated
in an unstructured way. The information is
supported by limited evidence and the
relationship to the evidence may not be
clear.

0 marks
No attempt to answer the question or
response is not worthy of credit.

Total 16

4 i 1 mark per bullet to max 2 2 AO1.1


e.g: (1) AO1.2
(1)
A rule of thumb / estimate / guess
That estimates the distance / cost from
each node to the destination node
To speed up the process of finding a
solution
…by identify which paths to follow first

ii Node Distance Heuristi Distance Previou MARKIN 8 AO1.2


travelled c travelled s node G GUID
+ ANCE (3) AO2.1
Heuristic (3) AO2.2
A (✓) 0 90 90 1 MARK (2)
B (✓) ∞ 21 80 101 A 1 MARK

C (✓) ∞ 42 65 107 A 1 MARK

D (✓) ∞ 50 104 C 1 MARK


42+12=5
4

E ∞ 50 111 B 1 MARK
21+40=6
1

F (✓) ∞ 42+12+ 30 107 D 1 MARK


23=77

G ∞ 42+12+ 0 110 F 1 MARK


23+33=1
10

Final path = A,C,D,F,G and Distance = 110


(1 Mark)

Total 10

© OCR 2024. You may photocopy this page. 21 of 23 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

5 a 1 mark e.g. 1 Allow other suitable answers that are in


context of the problem
Symbols are used to represent the
address Examiner’s Comments
The edges represent possible
connections between addresses not Very few candidates were able to give
the actual physical routes suitable answers within the context of the
problem. The question was asking why the
graph in Fig 5 was a visualisation. Few
candidates identified that it was because
the letters at the nodes represented
delivery addresses, while the weights on
the edges represented the road distances
between the addresses. Most candidates
gave descriptions of visualisation in
general rather than answering in context.

b i Node Distance Previous Marking 6 Order of previous nodes visited must be


travelled node Guidance clear
A 0/- N/A / - 1 Mark
Note that nodes in the table do not have to
B 3 A 1 Mark be given in alphabetical order by
C 13 E candidates
D 10 B 1 Mark
Examiner’s Comments
E 6 B
F 9 E 1 Mark Most candidates gave the final path and
G 16 F the total distance correctly by inspection if
nothing else. All nodes are initially set to
H 21 19 DG 1 Mark infinity, so A is updated to 0 and has a
distance 0 from A as the start node and
Final Path = A,B,E,F,G,H, Distance = 19 (1 many candidates missed this. Those who
Mark) gave an answer by inspection wrote
ABEFGH without knowing Dijkstra’s
algorithm but gained some marks by giving
the distances to BEFGH along the way, but
distances to nodes C and D were omitted.
Few candidates clearly showed that the
initial calculation for the path distance to H
(from D, distance 21) was later updated
and overwritten with the more optimal path
length from G with distance 19.

© OCR 2024. You may photocopy this page. 22 of 23 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

ii 1 mark per bullet 2 Must contain a similarity and a difference


Similarity: for both marks.

Both always find the shortest route Examiner’s Comments


Both are pathfinding algorithms
Those candidates who scored well in c(i)
Differences: frequently gained full marks for describing
the similarities and differences between
A* is (usually) more efficient // dijkstra’s Dijkstra’s algorithm and the A* algorithm.
is (usually) slower The most common responses were that
A* uses heuristics to find a solution both give the shortest path and that A*
faster // Dijkstra’s does not use uses heuristics.
heuristics

Total 9

© OCR 2024. You may photocopy this page. 23 of 23 Created in ExamBuilder

Powered by TCPDF (www.tcpdf.org)

You might also like