0% found this document useful (0 votes)
57 views28 pages

All Path Finding 23

The document discusses using graphs and algorithms like Dijkstra's algorithm and A* search to solve problems related to pathfinding and optimization. It provides examples of applying these algorithms to problems like finding the shortest route between locations on a map, planning character movements in a game, and concurrent processing in searching algorithms.

Uploaded by

sammytest30
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)
57 views28 pages

All Path Finding 23

The document discusses using graphs and algorithms like Dijkstra's algorithm and A* search to solve problems related to pathfinding and optimization. It provides examples of applying these algorithms to problems like finding the shortest route between locations on a map, planning character movements in a game, and concurrent processing in searching algorithms.

Uploaded by

sammytest30
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/ 28

1 Mabel is a software engineer. She is writing a computer game for a client.

In the game the main character has to


avoid their enemies. This becomes more difficult as the levels of the game increase.

The game’s ‘challenging’ level has intelligent enemies that hunt down the character in an attempt to stop the
user from winning. The program plans the enemies’ moves in advance to identify the most efficient way to stop
the user from winning the game.

The possible moves are shown in a graph. Each node represents a different state in the game. The lines
represent the number of moves it will take to get to that state.

Show how Dijkstra’s algorithm would find the shortest path from A to H.

© OCR 2023. You may photocopy this page. 1 of 28 Created in ExamBuilder


[6]

2(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 2023. You may photocopy this page. 2 of 28 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 2023. You may photocopy this page. 3 of 28 Created in ExamBuilder


[9]

© OCR 2023. You may photocopy this page. 4 of 28 Created in ExamBuilder


3(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 2023. You may photocopy this page. 5 of 28 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 2023. You may photocopy this page. 6 of 28 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 2023. You may photocopy this page. 7 of 28 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 2023. You may photocopy this page. 8 of 28 Created in ExamBuilder


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.

[2]

(ii) Perform an A* algorithm on the graph shown in Fig. 1 to find the shortest path from the starting node to the

© OCR 2023. You may photocopy this page. 9 of 28 Created in ExamBuilder


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 2023. You may photocopy this page. 10 of 28 Created in ExamBuilder


Final path:

Distance:

[8]

5(a) A data structure is shown below in Fig. 4.1.

Fig. 4.1

Identify the data structure shown in Fig. 4.1.

[1]

© OCR 2023. You may photocopy this page. 11 of 28 Created in ExamBuilder


(b) The programmer is considering using a depth-first (post-order) traversal, or a breadth-first traversal to find the
path between node A and node X.

(i) Explain the difference between a depth-first (post-order) and breadth-first traversal.

[4]

(ii) Show how a depth-first (post-order) traversal would find the path between node A and node X for the
structure shown in Fig. 4.1.

© OCR 2023. You may photocopy this page. 12 of 28 Created in ExamBuilder


[6]

(iii) Explain how you used backtracking in your answer to part (b)(ii).

[3]

© OCR 2023. You may photocopy this page. 13 of 28 Created in ExamBuilder


6(a) *A programmer is interested in using concurrent processing to perform a searching algorithm.

Explain how concurrent processing could be used in searching algorithms, and evaluate the benefits and trade-
offs from implementing concurrent processing in a searching algorithm.

[9]

© OCR 2023. You may photocopy this page. 14 of 28 Created in ExamBuilder


(b) 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]
(c) 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 2023. You may photocopy this page. 15 of 28 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]

END OF QUESTION PAPER

© OCR 2023. You may photocopy this page. 16 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

1 1 mark for final solution, max 5 for showing 6 Guidance – 1 mark only for stating the
the stages solution of A-C-D-E-G-H length 10
AO1.2
(1) Examiner’s Comments
• Mark A as the current node initially AO2.2
• Record B = 1, C = 2 (mark A as visited) (3) Exemplar 2
• Record E = 5 (and mark B as visited) AO2.2
• (Record D = 3, F = 5 (and mark B as (2)
visited)
• Change E to 4 (overriding previous
value, and mark D as visited)
• Record G = 6 (and mark E as visited)
• …Do not change G as greater than
current (mark F as visited)
• (G as visited) H = 10 (Mark G as
visited)
• Solution: A-C-D-E-G-H path length 10

Node Visited From A Previous


Node
A ✓ 0 - 1 Mark
B ✓ 1 A 1 Mark
C ✓ 2 A
D ✓ 3 C 1 Mark
F ✓ 5 C Dijkstra's shortest path algorithm has
E ✓ 54 BD 2 Marks appeared in previous sessions and
Initial candidates generally had a good grasp of
visit, the principles of the algorithm. Verbose
plus text often made some responses difficult to
override follow. The clearest responses (as
values exemplified) tabulated the steps in the
G ✓ 6 E 1 Mark algorithm.
H 10 G 1 Mark

Total 6

© OCR 2023. You may photocopy this page. 17 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

2 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 2023. You may photocopy this page. 18 of 28 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 2023. You may photocopy this page. 19 of 28 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

© OCR 2023. You may photocopy this page. 20 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

3 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 2023. You may photocopy this page. 21 of 28 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 2023. You may photocopy this page. 22 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

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 2023. You may photocopy this page. 23 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

5 a Tree // Graph (undirected) 1 Do not accept binary tree


AO1.2
(1)

b i 1 mark per bullet to max 4 4


AO1.2
(4)
Depth-first goes to left child node when
it can…

If there is no left child it goes to the


right child

when there are no child nodes the


algorithm 'visits' it' and backtracks to
the parent node.

Breadth-first visits all nodes connected


directly to start node…

Then visits all nodes directly connected


to each of those nodes (and then all
nodes directly connected to those
nodes and so on…)

Depth-first uses a stack

Breadth-first uses a queue

ii 1 mark per node in correct order 6


D→K→L→H→B→G (X) AO2.1
(6)

© OCR 2023. You may photocopy this page. 24 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

iii Max 3 e.g. 3


AO1.2
(2)
When a node does not have any node AO2.1
to visit e.g. D (1)

The algorithm goes back to the


previous visited node e.g. B

To check for further nodes to visit


e.g. H

This repeats until a new node can be


visited, or all nodes have been visited

Examiner’s Comment:
A number of candidates incorrectly
identified the data structure as a binary
tree which indicated that this was the only
type of tree that they were familiar with.
Descriptions of depth and breadth first
traversals were often very vague, and
precision in terms of the algorithmic steps
involved would have produced stronger
answers. A pleasing number of candidates
produced the correct traversal of the tree,
but of those, a number did not appreciate
that the node was only output when it was
popped from the stack, and hence missed
location G before X was actually output.

Total 14

© OCR 2023. You may photocopy this page. 25 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

6 a Mark Band 3 – High level (7-9 marks) 9 AO1: knowledge and understanding
The candidate demonstrates a thorough Indicative content
knowledge and understanding of
concurrent processing; the material is
generally accurate and detailed. Carrying out more than one task at a
The candidate is able to apply their time
knowledge and understanding directly and Multiple processors
consistently to the context provided Each processor performs
(searching algorithms). simultaneously
Evidence/examples will be explicitly Each processor performs tasks
relevant to the explanation. independently
The candidate provides a thorough
discussion which is well balanced. and/or
Evaluative comments are consistenly
relevant and well considered.
A program has multiple threads
There is a well-developed line of reasoning Each thread starts and ends at
which is clear and logically structured. The different times
information presented is relevant and Each thread overlaps
substantiated. Each thread runs independently

Mark Band 2 – Mid level (4-6 marks) AO2: Application


The candidate demonstrates reasonable
knowledge and understanding of
concurrent processing; the material is Each processor/thread performs a
generally accurate but at times search in a different direction
underdeveloped. Rather than going down one path, go
The candidate is able to apply their down 2+
knowledge and understanding directly to E.g. apply different searches
the context provided although one or two simultaneously - perform breadth- first
opportunities are missed. (searching and depth-first simultaneously
algorithms) Evidence/examples are for the E.g. A* take the two shortest routes at
most part implicitly relevant to the each decision point, update same table
explanation. Linear search can have multiple
The candidate provides a reasonable processors searching different areas at
discussion, the majority of which is the same time.
focused. Evaluative comments are, for the Binary search doesn't benefit from an
most part appropriate, although one or two increase in speed with additional
opportunities for development are missed. processors.
There is a line of reasoning presented with
some structure. The information presented AO3: Evaluation
is in the most part relevant and supported Candidates will need to evaluate the
by some evidence benefits and drawbacks of concurrent
processing in searching e.g.
Mark Band 1 – Low Level (1-3 marks)
The candidate demonstrates a basic
knowledge of concurrent processing with Possibly find solution faster
limited understanding shown; the material Takes up more memory
is basic and contains some inaccuracies. Increase program throughput

© OCR 2023. You may photocopy this page. 26 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

The candidates makes a limited attempt to May waste time investigating inefficient
apply acquired knowledge and solutions
understanding to the context provided More difficult to program especially to
(searching algorithms). cooperate
The candidate provides a limited More memory intensive
discussion which is narrow in focus. Linear search scales very with
Judgements if made are weak and additional processors
unsubstantiated. Binary search can perform better on
The information is basic and comunicated large data sets with one processor than
in an unstructured way. The information is linear search with many processors
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.

b 1 mark per bullet 2

Weighted/Undirected
Graph

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


distance from final node

ii Used to speed up process of finding 1


solution

© OCR 2023. You may photocopy this page. 27 of 28 Created in ExamBuilder


Mark Scheme

Question Answer/Indicative content Marks Guidance

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.

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 24

© OCR 2023. You may photocopy this page. 28 of 28 Created in ExamBuilder

Powered by TCPDF (www.tcpdf.org)

You might also like