More Graph Algorithms - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

More Graph Algorithms

Description:

... to it, or if the journey would begin at one land mass and end at another, then ... Prove that the distance recorded in D really is the length of the ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 35
Provided by: norman54
Category:
Tags: algorithms | another | city | distance | from | graph | map | more | one | to

less

Transcript and Presenter's Notes

Title: More Graph Algorithms


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/fli
    ghtpath1.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 (Dijkstras 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 Dijkstras 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 distancesource to x lt distancesource
    to v.

11
Proof
v
Marked path
Hypothetical shortest path
x
S
0
Source
12
Why Dijkstras 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
Dijkstras Algorithm
14
Dijkstras Algorithm
15
Dijkstras Algorithm
16
Dijkstras Algorithm Demo
  • http//www-b2.is.tokushima-u.ac.jp/ikeda/suuri/di
    jkstra/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) lt 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
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
Kruskals 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
    1950s)
  • 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
u v w
1 5 2
1 2 3
1 4 3
4 5 4
2 5 5
2 3 6
1 3 7
2 4 8
3 4 10
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
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/kr
    uskal/Kruskal.shtml

29
Prims Algorithm Demo
  • http//www-b2.is.tokushima-u.ac.jp/ikeda/suuri/di
    jkstra/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 carrybut
    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
    1960s 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 importantin
    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.
Write a Comment
User Comments (0)
About PowerShow.com