More Graph Algorithms 15 April 2003. 2 Applications of Graphs Graph theory is used in dealing with problems which have a fairly natural graph/network.

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

Decision Maths Networks Kruskals Algorithm Wiltshire Networks A Network is a weighted graph, which just means there is a number associated with each.
Lecture 15. Graph Algorithms
Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
Introduction to Graph Theory Instructor: Dr. Chaudhary Department of Computer Science Millersville University Reading Assignment Chapter 1.
22C:19 Discrete Math Graphs Fall 2014 Sukumar Ghosh.
Great Theoretical Ideas in Computer Science for Some.
1 Discrete Structures & Algorithms Graphs and Trees: III EECE 320.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Lecture 21 Paths and Circuits CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Data Structures Using C++
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Great Theoretical Ideas in Computer Science.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Two Discrete Optimization Problems Problem #2: The Minimum Cost Spanning Tree Problem.
Chapter 11 Graphs and Trees This handout: Terminology of Graphs Eulerian Cycles.
The Shortest Path Problem
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
1 1 Slide © 2000 South-Western College Publishing/ITP Slides Prepared by JOHN LOUCKS.
1 Shortest Path Calculations in Graphs Prof. S. M. Lee Department of Computer Science.
GRAPH Learning Outcomes Students should be able to:
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
An Illustration of Prim's Algorithm
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Analysis of Algorithms
Copyright © Cengage Learning. All rights reserved.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Operations Research Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD4207 University of Palestine.
Introduction to Operations Research
Chapter 2 Graph Algorithms.
Graph Theory Topics to be covered:
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.
Dijkstra’s Algorithm. Announcements Assignment #2 Due Tonight Exams Graded Assignment #3 Posted.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
Minimal Spanning Tree Problems in What is a minimal spanning tree An MST is a tree (set of edges) that connects all nodes in a graph, using.
Most of contents are provided by the website Graph Essentials TJTSD66: Advanced Topics in Social Media.
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
Excursions in Modern Mathematics, 7e: Copyright © 2010 Pearson Education, Inc. 7 The Mathematics of Networks 7.1Trees 7.2Spanning Trees 7.3 Kruskal’s.
Networks and Graphs in Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is.
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.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
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.
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,
1 Data Structures and Algorithms Graphs. 2 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Examples of Graph Algorithms:
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
1 1 Slide © 2005 Thomson/South-Western Chapter 9 Network Models n Shortest-Route Problem n Minimal Spanning Tree Problem n Maximal Flow Problem.
Week 7 - Monday CS 113.
Minimum Spanning Trees
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Graph Algorithm.
Minimum-Cost Spanning Tree
Minimum Spanning Trees
Graphs Chapter 13.
Graphs Chapter 11 Objectives Upon completion you will be able to:
CSE 373: Data Structures and Algorithms
4-4 Graph Theory Trees.
Shortest Paths and 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
CSE 373: Data Structures and Algorithms
CSE 373 Data Structures and Algorithms
CSE 417: Algorithms and Computational Complexity
Minimum-Cost Spanning Tree
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

More Graph Algorithms 15 April 2003

2 Applications of Graphs Graph theory is used in dealing with problems which have a fairly natural graph/network structure, for example: 1.road networks: nodes are towns or road junctions, arcs are the roads 2.communication networks: telephone systems 3.computer systems We are reading this document via the Web. This is a graph, with each document (file) being a node and each hypertext link an arc.

3 Königsberg Bridge Problem Graph theory has a relatively long history in classical mathematics. In 1736 Euler solved the problem of whether, given the map on the next slide of the city of Königsberg in Germany, someone could make a complete tour, crossing over all 7 bridges over the river Pregel, and return to their starting point without crossing any bridge more than once. The town of Königsberg was in northern Germany and is now part of Russia.

4 The Map

5 Eulerian Paths A path that solves the problem is called an Eulerian path. Eulerian paths have interesting mathematical and computational properties. Euler reasoned that for such a journey to be possible that each land mass should have an even number of bridges connected to it, or if the journey would begin at one land mass and end at another, then exactly those two land masses could have an odd number of connecting bridges while all other land masses must have an even number of connecting bridges.

6 A Path Problem lightpath1.html lightpath1.html

7 Shortest Path Problem Given a directed graph in which each edge has a nonnegative weight or cost, find a path of least total weight from a given vertex, called the source, to every other vertex in the graph

8 The Main Idea (Dijkstra’s Algorithm) We keep a set S of vertices whose closest distances to the source, vertex 0, are known and add one vertex to S at each stage. We maintain a table of distances D that gives, for each vertex v, the distance from 0 to v along a path all of whose vertices are in S, except possibly the last one. To determine what vertex to add to S at each step, we apply the greedy criterion of choosing the vertex v with the smallest distance recorded in D, such that v is not already in S.

9 Greedy Criteria “Choose the vertex v with the smallest distance recorded in the table D, such that v is not already in S.”

10 Why Dijkstra’s Algorithm Works Prove that the distance recorded in D really is the length of the shortest path from source to v. Suppose that there were a shorter path from source to v, such as shown on the next slide. This path first leaves S to go to some vertex x, then goes on to v (possibly even reentering S along the way). But if this path is shorter than the marked path to v, then its initial segment from source to x is also shorter, so that the greedy criterion would have chosen x rather than v as the next vertex to add to S, since we would have had distance[source to x] < distance[source to v].

11 Proof v 0 x Hypothetical shortest path Marked path S Source

12 Why Dijkstra’s Algorithm Works-2 When we add v to S, we think of v as now marked and also mark the shortest path from source to v. Next, we update the entries of D by checking, for each vertex w not in S, whether a path through v and then directly to w is shorter than the previously recorded distance to w.

13 Dijkstra’s Algorithm d = 2 d =  d = 5 d = 3 S = {0} 5

14 Dijkstra’s Algorithm d = 2 d = 6 d = 5 d = 3 S = {0,4} d = 2 d = 6 d = 4 d = 3 S = {0,4,2} 1

15 Dijkstra’s Algorithm d = 2 d = 5 d = 4 d = 3 S = {0,4,2,1,3} d = 2 d = 5 d = 4 d = 3 S = {0,4,2,1} 1

16 Dijkstra’s Algorithm Demo u.ac.jp/~ikeda/suuri/dijkstra/Dijkstra.shtml For graphs with n vertices and a arcs, the time required by Dijkstra's algorithm is O(n 2 ). It will be reduced to O(a log n) if a heap is used to keep {v  V-S i | d(source, v) < infinity}.

17 Spanning Trees Consider the following problem. In the diagram shown below we have four wells in an offshore oilfield (nodes 1 to 4 below) and an on-shore terminal (node 5 below). The four wells in this field must be connected together via a pipeline network to the on-shore terminal.

18 5 is Shore, 1, 2, 3, 4 are Wells

19 Two Spanning Trees Weight Sum of Tree = Weight Sum of Tree = 15

20 Minimal Spanning Tree This particular problem is a specific example of a more general problem - namely given a graph (such as that shown on previous slide) which edges would we use so that: 1.the total cost of the edges used is a minimum; and 2.all the points are connected together. This problem is called the minimal spanning tree (MST) problem.

21 Formal Definition A minimal spanning tree of a connected network is a spanning tree such that the sum of the weights of its edges is as small as possible.

22 Oil Rigs For example, in the given graph, one possible structure connecting all the points together would consist of the edges 1-2, 2-3, 3-4, 4-5 and 5-1, but there are other structures where the total cost of the edges used is smaller than in this structure (e.g. drop any edge in the cycle formed above).

23 Kruskal’s Algorithm Points to note : 1.for an n-node graph the solution involves (n-1) edges 2.the solution can be easily arrived at by using an algorithm due to Kruskal (developed in the mid 1950’s) The final structure is called the minimal spanning tree (MST) of the graph.

24 Kruskal Algorithm The algorithm is: For a graph with n nodes keep adding the shortest (least cost) edge while avoiding the creation of cycles until (n-1) edges have been added Note that the Kruskal algorithm only applies to graphs in which all the edges are undirected.

25 Edge Table {uv}w

26 Example For the graph shown earlier, applying the Kruskal algorithm and starting with the shortest (least cost) edge, we have: Edge Cost Decision add to tree add to tree add to tree reject as forms cycle reject as forms cycle add to tree Stop since 4 edges have been added and these are all we need for the MST of a graph with 5 nodes.

27 MST The MST of the oil rig graph consists of the edges 1-5, 1-2, 1-4 and 2-3 (total cost 14)

28 Kruskal Demo u.ac.jp/~ikeda/suuri/kruskal/Kruskal.shtml

29 Prim’s Algorithm Demo u.ac.jp/~ikeda/suuri/dijkstra/Prim.html

30 Limitations The principal limitation of the pipeline network shown is (in practical terms) that we have ignored the fact that some pipelines carry more oil than others and this means that they must therefore be of larger diameter and hence more expensive (per unit length). We have the situation that the cost of a pipeline depends upon the amount of oil it must carry–but we do not know how much oil any particular pipeline is carrying until we have decided the entire pipeline network.

31 Extensions Iterative application of MST calculations provides one way of solving such practical pipeline design problems. Typically we first set a cost for each pipeline, then 1.solve the MST problem 2.calculate how much oil is carried in each pipeline 3.adjust pipeline costs accordingly and reiterate

32 Extensions Other difficulties include: 1.mixing oil of different grades 2.gases given off 3.use of compressors 4.geographic/political problems in getting the pipeline to go where we want 5.network very vulnerable to a failure in an edge or at a node 6.time periods: the flow from each well will vary over the years.

33 Bottom Line A pioneering application of MST models to pipeline network design occurred in the early 1960’s in the design of a gas pipeline network in the Gulf of Mexico. Savings resulted of the order of tens of millions of dollars. This illustrates how nice and neat theoretical problems (like the MST) can be used as building blocks to solve complex practical problems.

34 Network Design The oil rig problem can be considered as a network design problem. Such problems typically involve a number of distinct points (nodes) and connections between pairs of nodes (edges) and the problem is to design a suitable network to connect together a number of the nodes at minimum cost and which satisfies a number of criteria. For example we may want a minimum cost network which still functions after a failure in any one of the edges. Such problems are increasingly important–in particular in the telecommunications industry. In the simplest case the nodes are given, each possible edge has a cost associated with its use and the problem is which edges should be used so as to minimize total cost while ensuring that the network is connected. This problem is exactly the MST problem dealt with here.