1 / 34

More Graph Algorithms

Explore the applications of graph theory in various domains, from road networks and communication networks to computer systems. Learn about important graph algorithms such as Dijkstra's Algorithm and minimal spanning trees.

Download Presentation

More Graph Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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: • road networks: nodes are towns or road junctions, arcs are the roads • communication networks: telephone systems • 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 • http://www.planemath.com/activities/flightpath/flightpath1.html

  7. 0 2 5 6 3 1 4 6 10 2 1 4 3 2 2 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 Marked path Hypothetical shortest path x S 0 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. 0 2 5 d = 5 d = 2 3 1 4 0 2 5 6 3 1 4 3 2 6 10 d = 3 d =  2 1 4 S = {0} 3 2 2 Dijkstra’s Algorithm

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

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

  16. Dijkstra’s Algorithm Demo http://www-b2.is.tokushima-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(n2). It will be reduced to O(a log n) if a heap is used to keep {v  V-Si | 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. 2 6 3 7 3 1 3 5 8 10 2 4 4 5 5 is Shore, 1, 2, 3, 4 are Wells

  19. 3 3 3 3 4 4 4 4 0 0 3 3 3 3 3 3 3 3 1 5 1 5 2 2 2 1 2 1 2 4 2 4 2 2 Weight Sum of Tree = 15 Weight Sum of Tree = 12 Two Spanning Trees

  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: • the total cost of the edges used is a minimum; and • 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 1-2-3-4-5-1 formed above).

  23. Kruskal’s Algorithm • Points to note : • for an n-node graph the solution involves (n-1) edges • 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

  26. Example For the graph shown earlier, applying the Kruskal algorithm and starting with the shortest (least cost) edge, we have: Edge Cost Decision 1-5 2 add to tree 1-2 3 add to tree 1-4 3 add to tree 4-5 4 reject as forms cycle 1-5-4-1 2-5 5 reject as forms cycle 1-5-2-1 2-3 6 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. 2 6 3 3 1 3 2 4 5 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 http://www-b2.is.tokushima-u.ac.jp/~ikeda/suuri/kruskal/Kruskal.shtml

  29. Prim’s Algorithm Demo http://www-b2.is.tokushima-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 • solve the MST problem • calculate how much oil is carried in each pipeline • adjust pipeline costs accordingly and reiterate

  32. Extensions Other difficulties include: • mixing oil of different grades • gases given off • use of compressors • geographic/political problems in getting the pipeline to go where we want • network very vulnerable to a failure in an edge or at a node • 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.

More Related