graphs a ‘graph’ is a diagram that shows how things are connected together. it makes no attempt...

63
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential. If ‘weights’ are attached to the paths (to describe flows, times or distances) then the graph is called a ‘Network’.

Upload: darleen-owen

Post on 18-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Graphs

A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential. If ‘weights’ are attached to the paths (to describe flows, times or distances) then the graph is called a ‘Network’.

Page 2: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Graph Vocabulary

A B

C D

A graph is made up of nodes (dots) and arcs (lines/curves).It can contain multiple arcs and loops.A graph without any loops or multiple arcs is called simple.

In a graph arcs are generally ‘two way’. A graph with at least one directed arc is called a di-graph.

A subgraph is a small part of a graph, a subset of arcs and nodes

A B

C D

A B

D

Page 3: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Since graphs are only used to describe how thing are connected together, the lengths and positions of the arcs are not important. This means that graphs relaying the same information can be drawn in many different ways. We call two graphs that are really the same Isomorphic.

Which of these graphs are isomorphic?

How can you easily tell?

Page 4: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

We can also try and capture the information in the Graph using a matrix. When written in this form it is much easier to spot if two graphs are isomorphic

Clearly it can be difficult to tell if two graphs are isomorphic.

To make life easier we attempt to draw graphs so that none of the arcs cross, this isn’t always possible, but graphs for which it is possible are called planar.

This graph is planar because we can draw it like this with

no arcs crossing

0111

1011

1101

1110 A B C D

A

B

C

D

0112

1011

1101

2110 A B C D

A

B

C

D

A B

C DA B C

D

Page 5: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

1) Look at the diagram for a circuit board opposite.

Draw a graph to show how the six components are ‘directly’ connected to each other.

2) Represent the graphs below with a matrix.

3) Decide which of the graphs below are planar

AB

C

D

E

A

B

C

D

E

AB

CD

AB

D C

What do you notice about the matrices for i), ii) and iv) compared to iii)?

Why is this the case?

i) ii) iii) iv)

i) ii) iii) iv)

Page 6: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

A B

C D

A complete graph is one where every node is directly connected to every other node. This is the graph of K4.

A

B

C

D

F

G

E

A bi-partite graph is a graph where the nodes split into 2 sets so that nodes in each set are not connected to other nodes in the same set.

Types of Graphs and Networks

Page 7: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

A B

C D

A walk/route around a graph/network is a sequence of linked arcs

Eg . A – B – D – B – D – C

A walk/route is closed if it starts and ends at the same node

Eg. A – B – D – B – A

A trail is a walk/route that doesn’t visit an edge more than once

Eg. A – B – D – B (along alternate arc)

A path is a trail that doesn’t visit a node more than once

Eg. A – B – D

A cycle is a path with the extra condition that the start and end nodes are the same

Eg. B – D – B

A Hamiltonian cycle is a cycle that visits every node (ie it will visit every node exactly once apart from the start/end node)

Eg. A – B – C - DA graph/network is connected if every pair of nodes can be linked by a trail. The order/degree/valency of a node is the number of arcs that are incident to it

Eg The order of A is 2, the order of B is 3, the order of C is 4

Page 8: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

1) Is the complete graph with 6 nodes planar?

2) Look at the map opposite.

Use the map opposite to determine the shortest distance between any two towns.

Use this information to draw a graph representing the shortest distance between each of the towns.

3) Which of the graphs below contain a Hamiltonian cycle?

20

3

6

8

39

12

2

8

A

B

C

D

E

F

A

B

C

D

E

F

A

B

C

D

E

F

G

H

A

BC

D

E

F

G

Page 9: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Lesson Objective:

Trees, Spanning Trees and Minimum Spanning Trees

Page 10: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Look at these graphs. They are all ‘trees’.

What do you think makes a graph a tree? Can you draw some ‘trees’ of your own?

Page 11: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

A tree with is a connected graph that contains only trivial cycles.

Draw 2 ‘different trees’ with 4 nodes

Draw 2 ‘different trees’ with 5 nodes

Draw 2 ‘different trees’ with 6 nodes

What can you say about the number of arcs in a tree with ‘n’ nodes. Why?

How many ‘different’ trees are there with 3 nodes?

How many ‘different’ trees are there with 4 nodes? 5 nodes? Etc.

Page 12: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

When you find a tree for a network it is often called a spanning tree because it is a way of linking the nodes of the network together using the smallest number of arcs.

Find two ‘different’ spanning trees for the network below?

Add up the weights of the arcs in your spanning trees are they the same?

How many different spanning trees can you find?

Which has the smallest total weight?

The spanning tree with the smallest total weight for a particular network is called the minimum spanning tree.

10

7

6

8

5

5

3

A

B

C

D

E

F

G

9

4

6

Page 13: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Imagine the dots on this page represent underground stations.

The stations need to be joined up using the smallest amount of track possible, but only by joining stations directly to other stations.

The distances between each of the dots represents the ‘weight ‘ of the arc.

What is the best solution?

Page 14: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Imagine the dots on this page represent underground stations.

The stations need to be joined up using the smallest amount of track possible, but only by joining stations directly to other stations.

The distances between each of the dots represents the ‘weight ‘ of the arc.

What is the best solution?

Page 15: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Kruskal’s Algorithm

(To find a minimum spanning tree)

Step 1: Sort the edges in ascending order of weight

Step 2: Select the edge of least weight

Step 3: Select, from the edges not previously selected,

the edge of least weight that does not form a

cycle together with edges already included

Step 4: Repeat step 3 until all the vertices are connected.

Page 16: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

We model the situation as a network, then the problem is to find the minimum connector for the network

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 17: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

A F

B C

D

E

2

7

45

8 6 4

5

3

8

List the edges in order of size:

ED 2AB 3AE 4CD 4BC 5EF 5CF 6AF 7BF 8CF 8

Kruskal’s Algorithm

Page 18: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Select the shortestedge in the network

ED 2

Kruskal’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 19: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Select the next shortestedge which does notcreate a cycle

ED 2AB 3

Kruskal’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 20: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Select the next shortestedge which does notcreate a cycle

ED 2AB 3CD 4 (or AE 4)

Kruskal’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 21: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Select the next shortestedge which does notcreate a cycle

ED 2AB 3CD 4 AE 4

Kruskal’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 22: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Select the next shortestedge which does notcreate a cycle

ED 2AB 3CD 4 AE 4BC 5 – forms a cycleEF 5

Kruskal’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 23: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

All vertices have beenconnected.

The solution is

ED 2AB 3CD 4 AE 4EF 5

Total weight of tree: 18

Kruskal’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 24: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Prim’s Algorithm

(To find a minimum spanning tree)

Step 1: Choose a starting vertex

Step 2: Choose the vertex ‘nearest’ to the starting

vertex and the associated edge to the tree

Step 3: Connect to the tree the vertex that is ‘nearest’ to

any vertex in the connected set

Step 4: Repeat step 3 until all the vertices are connected.

Page 25: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Select any vertex

A

Select the shortest edge connected to that vertex

AB 3

Prim’s Algorithm

Page 26: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Select the shortestedge connected to any vertex already connected.

AE 4

Prim’s Algorithm

Page 27: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Select the shortestedge connected to any vertex already connected.

ED 2

Prim’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 28: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Select the shortestedge connected to any vertex already connected.

DC 4

Prim’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 29: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Select the shortestedge connected to any vertex already connected.

CB 5 – forms a cycle

EF 5

Prim’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 30: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Prim’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

All vertices have beenconnected.

The solution is

ED 2AB 3CD 4 AE 4EF 5

Total weight of tree: 18

Page 31: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Apply both Prim’s and Kruskal’s algorithms to the networks below to find a minimum spanning tree. What is the weight of the minimum spanning tree in each case?

1) The algorithms will always find a minimum spanning tree, but do they always find the same minimum spanning tree?

2) Try and think of an advantage/disadvantage of each algorithm.

Page 32: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Apply both Prim’s and Kruskal’s algorithms to the networks below to find a minimum spanning tree. What is the weight of the minimum spanning tree in each case?

1) The algorithms will always find a minimum spanning tree, but do they always find the same minimum spanning tree?

2) Try and think of an advantage/disadvantage for each algorithm.

A solution – there are others. Weight 22. A solution – there are others. Weight 28.

Page 33: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

•Both algorithms will always give solutions with the same length.

•They will usually select edges in a different order – you must show this in your workings.

•Occasionally they will use different edges – this may happen when you have to choose between edges with the same length. In this case there is more than one minimum connector for the network.

Some points to note

Page 34: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

The advantage of Prim’s algorithm is that you don’t have to check for cycles. This means that you can apply the algorithm easily without ‘seeing’ the network, just by having the matrix. This makes it ideal to program into a computer.

Apply Prim’s algorithm to the network below, then write down a matrix for the network

Page 35: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential
Page 36: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

PRIM’S ALGORITHM FOR A MATRIXStep 1: Start anywhere, say A. Cross out the row for this vertex and

put an arrow over the corresponding column.

Step 2: Look down all arrowed columns and find the smallest value that is not crossed out. Cross out the remainder of this row and put an arrow over the column corresponding to the row vertex.

Step 3: Repeat step 2 until all columns have arrows

Page 37: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Write down a matrix for the network and use it to find a minimum spanning tree using the algorithm on the matrix.

A B C

D EF G

12 32

41 11 20 11 14

32 9 7

Page 38: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Network Matrix

A B C D E F G A - 12 - - - 41 - B 12 - 32 11 20 - - C - 32 - - 11 - 14 D - 11 - - 32 7 - E - 20 11 32 - - 9 F 41 - - 7 - - - G - - 14 - 9 - -

Page 39: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Prim’s algorithm in matrix form

Step 1: Start anywhere, say A.Cross out the row for this vertex and put an arrow over the corresponding column.

Step 2: Look down all arrowed columns and find the smallest value that is not crossed out. Cross out the remainder of this row and put an arrow over the column corresponding to the row vertex.

Step 3: Repeat step 2 until all columns have arrows

Page 40: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

A B C D E F GA - 12 - - - 41 -B 12 - 32 11 20 - -C - 32 - - 11 - 14D - 11 - - 32 7 -E - 20 11 32 - - 9F 41 - - 7 - - -G - - 14 - 9 - -

1 2 3 45 67

Page 41: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Apply Prim’s algorithm to these matrices:

Page 42: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Apply Prim’s algorithm to these matrices:

Page 43: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Lesson Objective:

Finding the shortest route between two nodes in a Network

4

3

7

1

4

2 4

7

25

3 2

A

C

D

BF

E

G

Look at the network below. If the weights represents the distances between the nodes, what is the shortest route from A to G?

Page 44: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Djikstra’s algorithm is an algorithm used to solve this kind of problem.

It works by scanning the network from A to G labelling them one at a time in the search for an optimal path. It only permanently labels (or ‘boxes’) a node when it can guarantee that there is no shorter route to that node from the start position.

Page 45: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithmfinds the shortest path from the start vertex to every other vertex in

the network. We will find the shortest path from A to G

4

3

7

1

4

2 4

7

25

3 2

A

C

D

BF

E

G

Page 46: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

1. Label the start vertex with permanent label 0 and order label 1

2 Assign temporary labels to all the vertices that can be reached directly from the start

3 Select the vertex with the smallest temporary label and make its label permanent. Add the correct order label.

4 Put temporary labels on each vertex that can be reached directly from the vertex you have just made permanent. The temporary label must be equal to the sum of the permanent label and the direct distance from it. If there is an existing temporary label at a vertex, it should be replaced only if the new sum is smaller.

5 Select the vertex with the smallest temporary label and make its label permanent. Add the correct order label.

6 Repeat until the finishing vertex has a permanent label.

7 To find the shortest paths(s), trace back from the end vertex to the start vertex. Write the route forwards and state the length.

Page 47: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

Order in which vertices are labelled.

Distance from A to vertex

Working

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

1 0

Label vertex A 1 as it is the first vertex labelled

Page 48: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

4

3

7

We update each vertex adjacent to A with a ‘working value’ for its distance from A.

1 0

Page 49: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

4

3

7

2 3

Vertex C is closest to A so we give it a permanent label 3. C is the 2nd vertex to be permanently labelled.

1 0

Page 50: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

We update each vertex adjacent to C with a ‘working value’ for its total distance from A, by adding its distance from C to C’s permanent label of 3.

6

8

1 0

4

7

2 33

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

6 < 7 so replace the t-label here

Page 51: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

6

8

1 0

4

7

2 33

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

The vertex with the smallest temporary label is B, so make this label permanent. B is the 3rd vertex to be permanently labelled.

3 4

Page 52: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

6

8

1 0

4

7

2 33

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

3 4

We update each vertex adjacent to B with a ‘working value’ for its total distance from A, by adding its distance from B to B’s permanent label of 4.

5

85 < 6 so replace the t-label here

Page 53: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

6

8

1 0

4

7

2 33

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

3 4

5

8

The vertex with the smallest temporary label is D, so make this label permanent. D is the 4th vertex to be permanently labelled.

4 5

Page 54: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

6

8

1 0

4

7

2 33

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

3 4

5

8

4 5

We update each vertex adjacent to D with a ‘working value’ for its total distance from A, by adding its distance from D to D’s permanent label of 5.

7 < 8 so replace the t-label here

12

7

7 < 8 so replace the t-label here

7

Page 55: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

6

8

1 0

4

7

2 33

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

3 4

5

8

4 5

12

7

7

The vertices with the smallest temporary labels are E and F, so choose one and make the label permanent. E is chosen - the 5th vertex to be permanently labelled.

5 7

Page 56: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

6

8

1 0

4

7

2 33

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

3 4

5

8

4 5

12

7

7

5 7

We update each vertex adjacent to E with a ‘working value’ for its total distance from A, by adding its distance from E to E’s permanent label of 7.

9 < 12 so replace the t-label here

9

Page 57: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

6

8

1 0

4

7

2 33

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

3 4

5

8

4 5

12

7

7

5 7

The vertex with the smallest temporary label is F, so make this label permanent.F is the 6th vertex to be permanently labelled.

9

6 7

Page 58: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

6

8

1 0

4

7

2 33

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

3 4

5

8

4 5

12

7

7

5 79

6 7

We update each vertex adjacent to F with a ‘working value’ for its total distance from A, by adding its distance from F to F’s permanent label of 7.

11 > 9 so do not replace the t-label here

Page 59: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

6

8

1 0

4

7

2 33

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

3 4

5

8

4 5

12

7

7

5 79

6 7

G is the final vertex to be permanently labelled.

7 9

Page 60: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Dijkstra’s Algorithm

6

8

1 0

4

7

2 33

A

C

D

BF

E

G

4

3

7

1

4

2 4

7

25

3 2

3 4

5

8

4 5

12

7

7

5 79

6 7

7 9

To find the shortest path from A to G, start from G and work backwards, choosing arcs for which the difference between the permanent labels is equal to the arc length.

The shortest path is ABDEG, with length 9.

Page 61: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential
Page 62: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

First of all draw boxes as shown next to each of the nodes.

Page 63: Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential

Text book page 12,13 and 11 in that order page 94-97 Ex 11E