Algorithms on graphs In Decision Mathematics, a graph consists of points (called vertices or nodes) which are connected by lines (edges or arcs). Eg in.

Slides:



Advertisements
Similar presentations
Decision Maths Networks Kruskals Algorithm Wiltshire Networks A Network is a weighted graph, which just means there is a number associated with each.
Advertisements

The Chinese Postman Problem Route Planning Map Colouring
Networks Prim’s Algorithm
Introduction to Graph Theory Instructor: Dr. Chaudhary Department of Computer Science Millersville University Reading Assignment Chapter 1.
Minimum Spanning Tree Sarah Brubaker Tuesday 4/22/8.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Section 14.1 Intro to Graph Theory. Beginnings of Graph Theory Euler’s Konigsberg Bridge Problem (18 th c.)  Can one walk through town and cross all.
MINIMAL CONNECTOR PROBLEMS Problem: A cable TV company is installing a system of cables to connect all the towns in a region. The numbers in the network.
Aims: To know the terms: tree, spanning tree, minimum spanning tree. To understand that a minimum spanning tree connects a network using the lowest possible.
Euler Circuits and Paths
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Graphs. Graph A “graph” is a collection of “nodes” that are connected to each other Graph Theory: This novel way of solving problems was invented by a.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
GRAPH Learning Outcomes Students should be able to:
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley.
Excursions in Modern Mathematics, 7e: Copyright © 2010 Pearson Education, Inc. 7 The Mathematics of Networks 7.1Trees 7.2Spanning Trees 7.3 Kruskal’s.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
More Graph Algorithms 15 April Applications of Graphs Graph theory is used in dealing with problems which have a fairly natural graph/network.
Copyright © Cengage Learning. All rights reserved.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Minimum spanning trees Aims: To know the terms: tree, spanning tree, minimum spanning tree. To understand that a minimum spanning tree connects a network.
Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.
1 Excursions in Modern Mathematics Sixth Edition Peter Tannenbaum.
Chapter 2 Graph Algorithms.
Graph Theory Topics to be covered:
Networks.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Which of these can be drawn without taking your pencil off the paper and without going over the same line twice? If we can find a path that goes over all.
Chinese postman problem
Structures 7 Decision Maths: Graph Theory, Networks and Algorithms.
Graphs Edge(arc) Vertices can be even or odd or undirected (two-way) Edges can be directed (one-way) This graph is connected. Degree(order) = 3 Odd vertex.
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.
D1 stuff The tail wags the dog. M1A1 A1 A1 We mark your best effort.
EXCURSIONS IN MODERN MATHEMATICS SIXTH EDITION Peter Tannenbaum 1.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Graphs Upon completion you will be able to:
M Clements Formal Network Theory. Introduction Practical problem – The Seven Bridges of Königsberg Network graphs Nodes & edges Degrees Rules/ axioms.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
I can describe the differences between Hamilton and Euler circuits and find efficient Hamilton circuits in graphs. Hamilton Circuits I can compare and.
DECISION 1. How do you do a Bubble Sort? Bubble Sort:  You compare adjacent items in a list;  If they are in order, leave them.  If they are not in.
Grade 11 AP Mathematics Graph Theory Definition: A graph, G, is a set of vertices v(G) = {v 1, v 2, v 3, …, v n } and edges e(G) = {v i v j where 1 ≤ i,
AS Decision Maths Tips for each Topic. Kruskal and Prim What examiner’s are looking for A table of values in the order that they are added and the total.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
1 Data Structures and Algorithms Graphs. 2 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Examples of Graph Algorithms:
Networks Teacher’s guide. Networks 2 Problem 1 – the Link The EMTV Company needs to install a new cable system that links the six major towns in its.
The graph is neither Eulerian or Semi – Eulerian as it has 4 ODD vertices.
Excursions in Modern Mathematics Sixth Edition
Excursions in Modern Mathematics Sixth Edition
Minimum Spanning Trees
Kruskal’s Algorithm Elaicca Ronna Ordoña. A cable company want to connect five villages to their network which currently extends to the market town of.
Jan 2007.
Discrete Maths 9. Graphs Objective
Graph Algorithm.
Spanning Trees.
Minimum Spanning Trees
Graphs Chapter 13.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Minimum Spanning Trees
Shortest Path.
Graphs.
Example A cable company want to connect five villages to their network which currently extends to the market town of Avonford. What is the minimum.
Minimum spanning trees
Minimum spanning trees
Route Inspection Which of these can be drawn without taking your pencil off the paper and without going over the same line twice? If we introduce a vertex.
Networks Kruskal’s Algorithm
Networks Prim’s Algorithm
Kruskal’s Algorithm AQR.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Section 13.4 Trees.
Presentation transcript:

Algorithms on graphs In Decision Mathematics, a graph consists of points (called vertices or nodes) which are connected by lines (edges or arcs). Eg in the map below, the towns are nodes and the routes between them are arcs This section considers algorithms that find the shortest route that: connects all nodes in a graph gets you from ‘A to B’ travels along every arc in a network Modern journey planner tools use these algorithms to find routes that minimise time, distance or cost as required.

Graph terminology A path exists between 2 nodes if you can get from one to the other without passing through any other node twice C B Eg there is a route from A to E via the paths ABE or ADCE E A D A walk is a path in which you are permitted to pass through nodes more than once A cycle is a ‘closed’ path – one that starts & finishes at the same node Eg there is a walk starting & finishing at A via BECB Eg the cycle BCE

Graph terminology A tree is a connected graph with no cycles C B E A D A graph is connected if there is a path between any two nodes A spanning tree is a tree which includes all nodes in a network Eg the graph above is connected Eg there are many spanning trees of the graph shown: But remove arcs AB and AD and it isn’t

Prim’s algorithm Prim and Kruskal’s algorithms find a Minimum Spanning Tree (MST) Eg The network in the diagram below shows the distances, in metres, between 10 wildlife observation points. The observation points are to be linked by footpaths, to form a network along the arcs indicated, using the least possible total length. Find a minimum spanning tree for the network, showing clearly the order in which you selected the arcs for your tree, using Prim’s algorithm, starting from A. With Prim’s algorithm, consider arcs from the shortest to the longest, adding them to the MST if they do not form a cycle

Order arcs included: AD DE EC EG CF FH HI IJ CB D E G Length of MST = 188 A Add the shortest arc connected to the tree so far, provided it doesn’t form a cycle I C F B J H

Distance matrices Complete the table of distances for this network A B - 20 18 16 - - B 20 - 15 - - 50 C 18 15 - 10 20 30 D 16 - 10 - 23 - E - - 20 23 - 25 F - 50 30 - 25 - Draw a network corresponding to this distance matrix A B C D E - 21 20 23 17 18 41 22

Prim from a table of distances G - 165 195 280 130 200 150 90 155 235 230 170 110 175 190 105 163 82 63 Eg An area manager has to visit branches of his company in 7 towns A, B, C, D, E, F and G. The table shows the distances, in km, between these 7 towns. The manager lives in town A and plans a route starting and finishing at this town. She wishes to visit each town and drive the minimum distance. Starting from A, use Prim’s algorithm to find a minimum connector and draw the minimum spanning tree. State the order in which you selected the arcs. MST: A E G F D Arcs selected: AE, EG, GF, FD, EC, CB C Weight = 130 + 82 + 63 + 105 + 110 + 90 = 580 B

Draw your tree using the vertices given in the diagram below. WB5 The table shows the lengths, in metres, of the paths between seven vertices A, B, C, D, E, F and G in a network N. A B C D E F G — 48 117 92 63 55 28 85 58 132 124 (a) Use Prim's algorithm, starting at A, to solve the minimum connector problem for this table of distances. You must clearly state the order in which you selected the edges of your tree, and the weight of your final tree. Draw your tree using the vertices given in the diagram below. Arcs selected: AB , BG , BF , GC , CD , DE Weight = 337m

A spanning tree of minimum total length WB6(a) Define the terms (i) tree ………………………………………………………………………… (ii) spanning tree ……………………………………………………………… (iii) minimum spanning tree …………………………………………………… A connected graph with no cycles, loops or multiple edges A tree that includes all vertices A spanning tree of minimum total length (b) State one difference between Kruskal’s algorithm and Prim’s algorithm, to find a minimum spanning tree. In Kruskal the shortest arc is added (unless it completes a cycle), in Prim the nearest unattached vertex is added There is no need to check for cycles when using Prim but there is when using Kruskal In Prim the tree always “grows” in a connected fashion Kruskal starts with the shortest edge, Prim with any vertex WB7(a) Explain what is meant by the term ‘path’. A path is a (finite) sequence of edges, such that the end vertex of one edge is the start vertex of the next and in which no vertex appears more than once/no cycles.

Kruskal’s Algorithm WB6(c) Use Kruskal’s algorithm to find the minimum spanning tree for the network shown in Figure 1. State the order in which you included the arcs. Draw the minimum spanning tree in Diagram 1 below and state its length. Figure 1 Order arcs included: BH NF HN HA BE NA EF AF EH CN Length of MST = 48 List arcs in ascending order of size, only including them if they don’t form a cycle

Remove either BE, BH or HN so there are no cycles Figure 2 models a car park. Currently there are two pay-stations, one at E and one at N. These two are linked by a cable as shown. New pay-stations are to be installed at B, H, A, F and C. The number on each arc represents the distance between the pay-stations in metres. All of the pay-stations need to be connected by cables, either directly or indirectly. The current cable between E and N must be included in the final network. The minimum amount of new cable is to be used. (d) Using your answer to part (c), or otherwise, determine the minimum amount of new cable needed. Use Diagram 2 to show where these cables should be installed. State the minimum amount of new cable needed. Remove either BE, BH or HN so there are no cycles Length of MST = 480 Answer to (c) Remove longest BE - 90 New cable needed = 390

Use Prim (starting from A) and then Kruskal’s algorithms to find MSTs for this network Prim from A Kruskal IG EK AE EF EJ FI IG GC CD CB EK KH EF CD EJ GC GD CB FI KH KJ AE FJ FC Length of MST = 172 Length of MST = 172

Use Prim (starting from A) and then Kruskal’s algorithms to find MSTs for this network Prim from A Kruskal

Use Prim (starting from L) and then Kruskal’s algorithms to find MSTs for this network Prim from L Kruskal ST ST LT TM MQ QN NP MQ LT TM QN MN NP QR QR

Use Prim (starting from L) and then Kruskal’s algorithms to find MSTs for this network

The table shows the lengths, in mm, between six nodes A to F in a network. C D E F — 124 52 87 58 97 114 111 115 84 67 103 98 41 117 121 (a) Use Prim's algorithm, starting at A, to solve the minimum connector problem for this table of distances. You must clearly state the order in which you selected the edges of your tree, and the weight of your final tree. Arcs selected: AC , CD , DE , AF , FB MST: Weight = 341m B F A C D E D

The table shows the lengths, in mm, between six nodes A to F in a network. C D E F — 124 52 87 58 97 114 111 115 84 67 103 98 41 117 121 (a) Use Prim's algorithm, starting at A, to solve the minimum connector problem for this table of distances. You must clearly state the order in which you selected the edges of your tree, and the weight of your final tree.

Dijkstra’s Algorithm WB7 The figure below shows a network of cycle tracks. The number on each edge represents the length, in miles, of that track. Mary wishes to cycle from A to I as part of a cycling holiday. She wishes to minimise the distance she travels. Use Dijkstra’s algorithm to find the shortest path from A to I. Show all necessary working in the boxes in the diagram State your shortest path and its length (2) Dijkstra’s algorithm finds the shortest route through a network

Dijkstra’s Algorithm 4 50 2 23 50 23 7 87 88 , 87 5 51 56 , 51 , 59 61 1 9 108 6 72 116 ,108 ,119 83 , 72 3 39 39 8 99 122 , 99 To find the route, trace back from end and include arc XY if Y already on the path and if the difference in final labels equals the length of arc I -21 G -15 F -21 D -28 B -23 A Shortest path ABDFGI Length 108

Mary wants to visit a theme park at E. (d) Find a path of minimal length that goes from A to I via E and state its length. 4 50 2 23 50 23 7 87 97 88 , 87 5 51 61 56 , 51 1 9 108 118 6 72 82 116 ,108 ,119 83 , 72 3 39 39 8 99 122 , 99 Going via E, Mary will reach D 10 later than previously Giving route ABEDFGI, length 118

The 7 bridges of Konigsberg Can you find a walk through the city that would cross each bridge once and only once? The islands can’t be reached by any route other than the bridges, and every bridge must be crossed completely every time. Euler reduced this to a graph, thinking of the districts of the city as nodes and the bridges as paths. Arc Node Each node has an odd number of arcs connected He realised that unless each node had an even number of arcs connected to it, a route could not be found. Hence this particular problem is unsolvable.

Can you find a walk around these networks?

Route inspection 3 3 WB5(c) Solve the Route Inspection problem for N. 117 WB5(c) Solve the Route Inspection problem for N. You must make your method and working clear. State a shortest route and find its length. 48 85 28 4 92 3 55 58 132 63 124 2 2 3 Odd nodes: A B C F Total weight = 802 Shortest routes: AB + CF = 48 + 160 = 208 AC + BF = 117 + 63 = 180 So repeat AC and BF AF + BC = 111 + 140 = 251 Length of route = 802 + 180 = 982 Possible route, eg from A: ABFEDCGBFDACA

WB8 (a) Describe a practical problem that could be modelled using the network in the diagram above and solved using the route inspection algorithm. (b) Use the route inspection algorithm to find which paths need to be traversed twice. (c) State whether your answer to part (b) is unique. Give a reason for your answer. (d) Find the length of the shortest inspection route that traverses each arc at least once and starts and finishes at the same vertex. Odd nodes: A B D F Shortest routes: via E AB + DF = 32 + 9 = 41 AD + BF = 26 + 15 = 41 AF + BD = 18 + 24 = 42 So repeat either AE, EB and DF or AD and BF Total weight = 258 Length of route = 258 + 41 = 299 You may have to consider the shortest of a number of routes

Given that it is permitted to start and finish the inspection at two distinct vertices, (e) find which two vertices should be chosen to minimise the length of the route. Give a reason for your answer. AB + DF = 32 + 9 = 41 AD + BF = 26 + 15 = 41 AF + BD = 18 + 24 = 42 DF is the shortest, so repeat that and start/finish at A/B If you can start/finish at different nodes, then you only need to repeat one arc…